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

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

Issue 421193002: Fix ExtensionServiceTest.ClearExtensionData flakiness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use base::DoNothing for empty callbacks Created 6 years, 4 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 | Annotate | Revision Log
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/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_special_storage_policy.h" 8 #include "chrome/browser/extensions/extension_special_storage_policy.h"
9 #include "chrome/browser/extensions/extension_util.h" 9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 19 matching lines...) Expand all
30 using content::StoragePartition; 30 using content::StoragePartition;
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 namespace { 34 namespace {
35 35
36 // Helper function that deletes data of a given |storage_origin| in a given 36 // Helper function that deletes data of a given |storage_origin| in a given
37 // |partition|. 37 // |partition|.
38 void DeleteOrigin(Profile* profile, 38 void DeleteOrigin(Profile* profile,
39 StoragePartition* partition, 39 StoragePartition* partition,
40 const GURL& origin) { 40 const GURL& origin,
41 const base::Closure& callback) {
41 DCHECK_CURRENTLY_ON(BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
42 DCHECK(profile); 43 DCHECK(profile);
43 DCHECK(partition); 44 DCHECK(partition);
44 45
45 if (origin.SchemeIs(kExtensionScheme)) { 46 if (origin.SchemeIs(kExtensionScheme)) {
46 // TODO(ajwong): Cookies are not properly isolated for 47 // TODO(ajwong): Cookies are not properly isolated for
47 // chrome-extension:// scheme. (http://crbug.com/158386). 48 // chrome-extension:// scheme. (http://crbug.com/158386).
48 // 49 //
49 // However, no isolated apps actually can write to kExtensionScheme 50 // However, no isolated apps actually can write to kExtensionScheme
50 // origins. Thus, it is benign to delete from the 51 // origins. Thus, it is benign to delete from the
51 // RequestContextForExtensions because there's nothing stored there. We 52 // RequestContextForExtensions because there's nothing stored there. We
52 // preserve this code path without checking for isolation because it's 53 // 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 // simpler than special casing. This code should go away once we merge
54 // the various URLRequestContexts (http://crbug.com/159193). 55 // the various URLRequestContexts (http://crbug.com/159193).
55 partition->ClearDataForOrigin( 56 partition->ClearDataForOrigin(
56 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, 57 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
57 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 58 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
58 origin, 59 origin,
59 profile->GetRequestContextForExtensions()); 60 profile->GetRequestContextForExtensions(),
61 callback);
60 } else { 62 } else {
61 // We don't need to worry about the media request context because that 63 // We don't need to worry about the media request context because that
62 // shares the same cookie store as the main request context. 64 // shares the same cookie store as the main request context.
63 partition->ClearDataForOrigin( 65 partition->ClearDataForOrigin(
64 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE, 66 ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE,
65 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 67 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
66 origin, 68 origin,
67 partition->GetURLRequestContext()); 69 partition->GetURLRequestContext(),
70 callback);
68 } 71 }
69 } 72 }
70 73
71 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es) { 74 void OnNeedsToGarbageCollectIsolatedStorage(WeakPtr<ExtensionService> es,
72 if (!es) 75 const base::Closure& callback) {
73 return; 76 if (es)
74 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true); 77 ExtensionPrefs::Get(es->profile())->SetNeedsStorageGarbageCollection(true);
78 callback.Run();
75 } 79 }
76 80
77 } // namespace 81 } // namespace
78 82
79 // static 83 // static
80 void DataDeleter::StartDeleting(Profile* profile, const Extension* extension) { 84 void DataDeleter::StartDeleting(Profile* profile,
85 const Extension* extension,
86 const base::Closure& callback) {
81 DCHECK(profile); 87 DCHECK(profile);
82 DCHECK(extension); 88 DCHECK(extension);
83 89
84 if (AppIsolationInfo::HasIsolatedStorage(extension)) { 90 if (AppIsolationInfo::HasIsolatedStorage(extension)) {
85 BrowserContext::AsyncObliterateStoragePartition( 91 BrowserContext::AsyncObliterateStoragePartition(
86 profile, 92 profile,
87 util::GetSiteForExtensionId(extension->id(), profile), 93 util::GetSiteForExtensionId(extension->id(), profile),
88 base::Bind( 94 base::Bind(
89 &OnNeedsToGarbageCollectIsolatedStorage, 95 &OnNeedsToGarbageCollectIsolatedStorage,
90 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr())); 96 ExtensionSystem::Get(profile)->extension_service()->AsWeakPtr(),
97 callback));
91 } else { 98 } else {
92 GURL launch_web_url_origin( 99 GURL launch_web_url_origin(
93 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin()); 100 AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin());
94 101
95 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( 102 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
96 profile, 103 profile,
97 Extension::GetBaseURLFromExtensionId(extension->id())); 104 Extension::GetBaseURLFromExtensionId(extension->id()));
98 105
99 if (extension->is_hosted_app() && 106 if (extension->is_hosted_app() &&
100 !profile->GetExtensionSpecialStoragePolicy()-> 107 !profile->GetExtensionSpecialStoragePolicy()->
101 IsStorageProtected(launch_web_url_origin)) { 108 IsStorageProtected(launch_web_url_origin)) {
102 DeleteOrigin(profile, partition, launch_web_url_origin); 109 DeleteOrigin(profile,
110 partition,
111 launch_web_url_origin,
112 base::Bind(&base::DoNothing));
103 } 113 }
104 DeleteOrigin(profile, partition, extension->url()); 114 DeleteOrigin(profile, partition, extension->url(), callback);
105 } 115 }
106 116
107 #if defined(ENABLE_EXTENSIONS) 117 #if defined(ENABLE_EXTENSIONS)
108 // Begin removal of the settings for the current extension. 118 // Begin removal of the settings for the current extension.
109 // StorageFrontend may not exist in unit tests. 119 // StorageFrontend may not exist in unit tests.
110 StorageFrontend* frontend = StorageFrontend::Get(profile); 120 StorageFrontend* frontend = StorageFrontend::Get(profile);
111 if (frontend) 121 if (frontend)
112 frontend->DeleteStorageSoon(extension->id()); 122 frontend->DeleteStorageSoon(extension->id());
113 #endif // defined(ENABLE_EXTENSIONS) 123 #endif // defined(ENABLE_EXTENSIONS)
114 } 124 }
115 125
116 } // namespace extensions 126 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/data_deleter.h ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698