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/api/storage/settings_frontend.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_special_storage_policy.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/common/constants.h"
18 #include "extensions/common/extension.h"
19 #include "net/url_request/url_request_context_getter.h"
22 using content::BrowserContext
;
23 using content::BrowserThread
;
24 using content::StoragePartition
;
28 // Helper function that deletes data of a given |storage_origin| in a given
30 void DeleteOrigin(Profile
* profile
,
31 StoragePartition
* partition
,
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
37 if (origin
.SchemeIs(extensions::kExtensionScheme
)) {
38 // TODO(ajwong): Cookies are not properly isolated for
39 // chrome-extension:// scheme. (http://crbug.com/158386).
41 // However, no isolated apps actually can write to kExtensionScheme
42 // origins. Thus, it is benign to delete from the
43 // RequestContextForExtensions because there's nothing stored there. We
44 // preserve this code path without checking for isolation because it's
45 // simpler than special casing. This code should go away once we merge
46 // the various URLRequestContexts (http://crbug.com/159193).
47 partition
->ClearDataForOrigin(
48 StoragePartition::REMOVE_DATA_MASK_ALL
&
49 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
),
50 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
,
52 profile
->GetRequestContextForExtensions());
54 // We don't need to worry about the media request context because that
55 // shares the same cookie store as the main request context.
56 partition
->ClearDataForOrigin(
57 StoragePartition::REMOVE_DATA_MASK_ALL
&
58 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE
),
59 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
,
61 partition
->GetURLRequestContext());
65 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr
<ExtensionService
> es
) {
68 es
->extension_prefs()->SetNeedsStorageGarbageCollection(true);
73 namespace extensions
{
76 void DataDeleter::StartDeleting(Profile
* profile
, const Extension
* extension
) {
80 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension
)) {
81 BrowserContext::AsyncObliterateStoragePartition(
83 profile
->GetExtensionService()->GetSiteForExtensionId(extension
->id()),
84 base::Bind(&OnNeedsToGarbageCollectIsolatedStorage
,
85 profile
->GetExtensionService()->AsWeakPtr()));
87 GURL
launch_web_url_origin(
88 extensions::AppLaunchInfo::GetLaunchWebURL(extension
).GetOrigin());
90 StoragePartition
* partition
= BrowserContext::GetStoragePartitionForSite(
92 Extension::GetBaseURLFromExtensionId(extension
->id()));
94 if (extension
->is_hosted_app() &&
95 !profile
->GetExtensionSpecialStoragePolicy()->
96 IsStorageProtected(launch_web_url_origin
)) {
97 DeleteOrigin(profile
, partition
, launch_web_url_origin
);
99 DeleteOrigin(profile
, partition
, extension
->url());
102 // Begin removal of the settings for the current extension.
103 profile
->GetExtensionService()->settings_frontend()->
104 DeleteStorageSoon(extension
->id());
107 } // namespace extensions