Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/extensions/data_deleter.cc

Issue 123733003: Get ride of chrome.storage.* data when removing an application. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/data_deleter.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/data_deleter.h" 5 #include "chrome/browser/extensions/data_deleter.h"
6 6
7 #include "chrome/browser/extensions/api/storage/settings_frontend.h" 7 #include "chrome/browser/extensions/api/storage/settings_frontend.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_special_storage_policy.h"
9 #include "chrome/browser/profiles/profile.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"
10 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/site_instance.h"
12 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
13 #include "extensions/common/constants.h" 17 #include "extensions/common/constants.h"
14 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
15 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
16 20
21 using base::WeakPtr;
17 using content::BrowserContext; 22 using content::BrowserContext;
18 using content::BrowserThread; 23 using content::BrowserThread;
19 using content::StoragePartition; 24 using content::StoragePartition;
20 25
21 namespace extensions { 26 namespace {
22 27
23 // static 28 // Helper function that deletes data of a given |storage_origin| in a given
24 void DataDeleter::StartDeleting(Profile* profile, 29 // |partition|.
25 const std::string& extension_id, 30 void DeleteOrigin(Profile* profile,
26 const GURL& storage_origin) { 31 StoragePartition* partition,
32 const GURL& origin) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
28 DCHECK(profile); 34 DCHECK(profile);
35 DCHECK(partition);
29 36
30 const GURL& site = Extension::GetBaseURLFromExtensionId(extension_id); 37 if (origin.SchemeIs(extensions::kExtensionScheme)) {
31
32 StoragePartition* partition =
33 BrowserContext::GetStoragePartitionForSite(profile, site);
34
35 if (storage_origin.SchemeIs(extensions::kExtensionScheme)) {
36 // TODO(ajwong): Cookies are not properly isolated for 38 // TODO(ajwong): Cookies are not properly isolated for
37 // chrome-extension:// scheme. (http://crbug.com/158386). 39 // chrome-extension:// scheme. (http://crbug.com/158386).
38 // 40 //
39 // However, no isolated apps actually can write to kExtensionScheme 41 // However, no isolated apps actually can write to kExtensionScheme
40 // origins. Thus, it is benign to delete from the 42 // origins. Thus, it is benign to delete from the
41 // RequestContextForExtensions because there's nothing stored there. We 43 // RequestContextForExtensions because there's nothing stored there. We
42 // preserve this code path without checking for isolation because it's 44 // preserve this code path without checking for isolation because it's
43 // simpler than special casing. This code should go away once we merge 45 // simpler than special casing. This code should go away once we merge
44 // the various URLRequestContexts (http://crbug.com/159193). 46 // the various URLRequestContexts (http://crbug.com/159193).
45 partition->ClearDataForOrigin( 47 partition->ClearDataForOrigin(
46 StoragePartition::REMOVE_DATA_MASK_ALL & 48 StoragePartition::REMOVE_DATA_MASK_ALL &
47 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), 49 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
48 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 50 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
49 storage_origin, 51 origin,
50 profile->GetRequestContextForExtensions()); 52 profile->GetRequestContextForExtensions());
51 } else { 53 } else {
52 // We don't need to worry about the media request context because that 54 // We don't need to worry about the media request context because that
53 // shares the same cookie store as the main request context. 55 // shares the same cookie store as the main request context.
54 partition->ClearDataForOrigin( 56 partition->ClearDataForOrigin(
55 StoragePartition::REMOVE_DATA_MASK_ALL & 57 StoragePartition::REMOVE_DATA_MASK_ALL &
56 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), 58 (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE),
57 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 59 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
58 storage_origin, 60 origin,
59 partition->GetURLRequestContext()); 61 partition->GetURLRequestContext());
60 } 62 }
63 }
64
65 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) {
66 if (!es)
67 return;
68 es->extension_prefs()->SetNeedsStorageGarbageCollection(true);
69 }
70
71 } // namespace
72
73 namespace extensions {
74
75 // static
76 void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) {
77 DCHECK(profile);
78 DCHECK(extension);
79
80 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
81 BrowserContext::AsyncObliterateStoragePartition(
82 profile,
83 profile->GetExtensionService()->GetSiteForExtensionId(extension->id()),
84 base::Bind(&OnNeedsToGarbageCollectIsolatedStorage,
85 profile->GetExtensionService()->AsWeakPtr()));
86 } else {
87 GURL launch_web_url_origin(
88 extensions::AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
89
90 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
91 profile,
92 Extension::GetBaseURLFromExtensionId(extension->id()));
93
94 if (extension->is_hosted_app() &&
95 !profile->GetExtensionSpecialStoragePolicy()->
96 IsStorageProtected(launch_web_url_origin)) {
97 DeleteOrigin(profile, partition, launch_web_url_origin);
98 }
99 DeleteOrigin(profile, partition, extension->url());
100 }
61 101
62 // Begin removal of the settings for the current extension. 102 // Begin removal of the settings for the current extension.
63 profile->GetExtensionService()->settings_frontend()-> 103 profile->GetExtensionService()->settings_frontend()->
64 DeleteStorageSoon(extension_id); 104 DeleteStorageSoon(extension->id());
65 } 105 }
66 106
67 } // namespace extensions 107 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/data_deleter.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698