This source file includes following definitions.
- DeleteOrigin
- OnNeedsToGarbageCollectIsolatedStorage
- StartDeleting
#include "chrome/browser/extensions/data_deleter.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "net/url_request/url_request_context_getter.h"
#if defined(ENABLE_EXTENSIONS)
#include "extensions/browser/api/storage/storage_frontend.h"
#endif
using base::WeakPtr;
using content::BrowserContext;
using content::BrowserThread;
using content::StoragePartition;
namespace extensions {
namespace {
void DeleteOrigin(Profile* profile,
StoragePartition* partition,
const GURL& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(profile);
DCHECK(partition);
if (origin.SchemeIs(kExtensionScheme)) {
partition->ClearDataForOrigin(
StoragePartition::REMOVE_DATA_MASK_ALL &
(~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
origin,
profile->GetRequestContextForExtensions());
} else {
partition->ClearDataForOrigin(
StoragePartition::REMOVE_DATA_MASK_ALL &
(~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
origin,
partition->GetURLRequestContext());
}
}
void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
if (!es)
return;
ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
}
}
void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) {
DCHECK(profile);
DCHECK(extension);
if (AppIsolationInfo::HasIsolatedStorage(extension)) {
BrowserContext::AsyncObliterateStoragePartition(
profile,
util::GetSiteForExtensionId(extension->id(), profile),
base::Bind(
&OnNeedsToGarbageCollectIsolatedStorage,
ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr()));
} else {
GURL launch_web_url_origin(
AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
profile,
Extension::GetBaseURLFromExtensionId(extension->id()));
if (extension->is_hosted_app() &&
!profile->GetExtensionSpecialStoragePolicy()->
IsStorageProtected(launch_web_url_origin)) {
DeleteOrigin(profile, partition, launch_web_url_origin);
}
DeleteOrigin(profile, partition, extension->url());
}
#if defined(ENABLE_EXTENSIONS)
StorageFrontend* frontend = StorageFrontend::Get(profile);
if (frontend)
frontend->DeleteStorageSoon(extension->id());
#endif
}
}