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_launch_info.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "extensions/browser/api/storage/storage_frontend.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 "extensions/common/manifest_handlers/app_isolation_info.h"
22 #include "net/url_request/url_request_context_getter.h"
25 using content::BrowserContext
;
26 using content::BrowserThread
;
27 using content::StoragePartition
;
29 namespace extensions
{
33 // Helper function that deletes data of a given |storage_origin| in a given
35 void DeleteOrigin(Profile
* profile
,
36 StoragePartition
* partition
,
38 const base::Closure
& callback
) {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
43 if (origin
.SchemeIs(kExtensionScheme
)) {
44 // TODO(ajwong): Cookies are not properly isolated for
45 // chrome-extension:// scheme. (http://crbug.com/158386).
47 // However, no isolated apps actually can write to kExtensionScheme
48 // origins. Thus, it is benign to delete from the
49 // RequestContextForExtensions because there's nothing stored there. We
50 // preserve this code path without checking for isolation because it's
51 // simpler than special casing. This code should go away once we merge
52 // the various URLRequestContexts (http://crbug.com/159193).
53 partition
->ClearDataForOrigin(
54 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
,
55 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
,
57 profile
->GetRequestContextForExtensions(),
60 // We don't need to worry about the media request context because that
61 // shares the same cookie store as the main request context.
62 partition
->ClearDataForOrigin(
63 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
,
64 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
,
66 partition
->GetURLRequestContext(),
71 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr
<ExtensionService
> es
,
72 const base::Closure
& callback
) {
74 ExtensionPrefs::Get(es
->profile())->SetNeedsStorageGarbageCollection(true);
81 void DataDeleter::StartDeleting(Profile
* profile
,
82 const Extension
* extension
,
83 const base::Closure
& callback
) {
87 if (AppIsolationInfo::HasIsolatedStorage(extension
)) {
88 BrowserContext::AsyncObliterateStoragePartition(
90 util::GetSiteForExtensionId(extension
->id(), profile
),
92 &OnNeedsToGarbageCollectIsolatedStorage
,
93 ExtensionSystem::Get(profile
)->extension_service()->AsWeakPtr(),
96 GURL
launch_web_url_origin(
97 AppLaunchInfo::GetLaunchWebURL(extension
).GetOrigin());
99 StoragePartition
* partition
= BrowserContext::GetStoragePartitionForSite(
101 Extension::GetBaseURLFromExtensionId(extension
->id()));
103 ExtensionSpecialStoragePolicy
* storage_policy
=
104 profile
->GetExtensionSpecialStoragePolicy();
105 if (storage_policy
->NeedsProtection(extension
) &&
106 !storage_policy
->IsStorageProtected(launch_web_url_origin
)) {
107 DeleteOrigin(profile
,
109 launch_web_url_origin
,
110 base::Bind(&base::DoNothing
));
112 DeleteOrigin(profile
, partition
, extension
->url(), callback
);
115 // Begin removal of the settings for the current extension.
116 // StorageFrontend may not exist in unit tests.
117 StorageFrontend
* frontend
= StorageFrontend::Get(profile
);
119 frontend
->DeleteStorageSoon(extension
->id());
122 } // namespace extensions