1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/data_deleter.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_special_storage_policy.h"
9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
12 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/site_instance.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/constants.h"
20 #include "extensions/common/extension.h"
21 #include "net/url_request/url_request_context_getter.h"
23 #if defined(ENABLE_EXTENSIONS)
24 #include "extensions/browser/api/storage/storage_frontend.h"
28 using content::BrowserContext;
29 using content::BrowserThread;
30 using content::StoragePartition;
32 namespace extensions {
36 // Helper function that deletes data of a given |storage_origin| in a given
38 void DeleteOrigin(Profile* profile,
39 StoragePartition* partition,
41 DCHECK_CURRENTLY_ON(BrowserThread::UI);
45 if (origin.SchemeIs(kExtensionScheme)) {
46 // TODO(ajwong): Cookies are not properly isolated for
47 // chrome-extension:// scheme. (http://crbug.com/158386).
49 // However, no isolated apps actually can write to kExtensionScheme
50 // origins. Thus, it is benign to delete from the
51 // RequestContextForExtensions because there's nothing stored there. We
52 // preserve this code path without checking for isolation because it's
53 // simpler than special casing. This code should go away once we merge
54 // the various URLRequestContexts (http://crbug.com/159193).
55 partition->ClearDataForOrigin(
56 StoragePartition::REMOVE_DATA_MASK_ALL &
57 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
58 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
60 profile->GetRequestContextForExtensions());
62 // We don't need to worry about the media request context because that
63 // shares the same cookie store as the main request context.
64 partition->ClearDataForOrigin(
65 StoragePartition::REMOVE_DATA_MASK_ALL &
66 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
67 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
69 partition->GetURLRequestContext());
73 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
76 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
82 void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) {
86 if (AppIsolationInfo::HasIsolatedStorage(extension)) {
87 BrowserContext::AsyncObliterateStoragePartition(
89 util::GetSiteForExtensionId(extension->id(), profile),
91 &OnNeedsToGarbageCollectIsolatedStorage,
92 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr()));
94 GURL launch_web_url_origin(
95 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
97 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
99 Extension::GetBaseURLFromExtensionId(extension->id()));
101 if (extension->is_hosted_app() &&
102 !profile->GetExtensionSpecialStoragePolicy()->
103 IsStorageProtected(launch_web_url_origin)) {
104 DeleteOrigin(profile, partition, launch_web_url_origin);
106 DeleteOrigin(profile, partition, extension->url());
109 #if defined(ENABLE_EXTENSIONS)
110 // Begin removal of the settings for the current extension.
111 // StorageFrontend may not exist in unit tests.
112 StorageFrontend* frontend = StorageFrontend::Get(profile);
114 frontend->DeleteStorageSoon(extension->id());
115 #endif // defined(ENABLE_EXTENSIONS)
118 } // namespace extensions