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

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

Issue 612983004: Gather metrics on hosted app unlimitedStorage usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/extension_special_storage_policy.h" 5 #include "chrome/browser/extensions/extension_special_storage_policy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/metrics/histogram.h"
10 #include "base/stl_util.h" 12 #include "base/stl_util.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/content_settings/cookie_settings.h" 14 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" 16 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
15 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
16 #include "components/content_settings/core/common/content_settings.h" 19 #include "components/content_settings/core/common/content_settings.h"
17 #include "components/content_settings/core/common/content_settings_types.h" 20 #include "components/content_settings/core/common/content_settings_types.h"
21 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/storage_partition.h"
19 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
20 #include "extensions/common/constants.h" 25 #include "extensions/common/constants.h"
21 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
22 #include "extensions/common/extension_set.h" 27 #include "extensions/common/extension_set.h"
23 #include "extensions/common/permissions/permissions_data.h" 28 #include "extensions/common/permissions/permissions_data.h"
29 #include "storage/browser/quota/quota_manager.h"
30 #include "storage/common/quota/quota_status_code.h"
31 #include "storage/common/quota/quota_types.h"
24 32
25 using content::BrowserThread; 33 using content::BrowserThread;
26 using extensions::APIPermission; 34 using extensions::APIPermission;
27 using extensions::Extension; 35 using extensions::Extension;
28 using storage::SpecialStoragePolicy; 36 using storage::SpecialStoragePolicy;
29 37
38 namespace {
39
40 void ReportQuotaUsage(storage::QuotaStatusCode code, int64 usage, int64 quota) {
41 if (code == storage::kQuotaStatusOk) {
42 // We're interested in the amount of space hosted apps are using. Record it
43 // when the extension is granted the unlimited storage permission (once per
44 // extension load, so on average once per run).
45 UMA_HISTOGRAM_MEMORY_KB("Extensions.HostedAppUnlimitedStorageUsage", usage);
46 }
47 }
48
49 // Log the usage for a hosted app with unlimited storage.
50 void LogHostedAppUnlimitedStorageUsage(
51 scoped_refptr<const Extension> extension,
52 content::BrowserContext* browser_context) {
53 GURL launch_url =
54 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin();
55 content::StoragePartition* partition =
56 browser_context ? // |browser_context| can be NULL in unittests.
57 content::BrowserContext::GetStoragePartitionForSite(browser_context,
58 launch_url) :
59 NULL;
60 if (partition) {
61 // We only have to query for kStorageTypePersistent data usage, because apps
62 // cannot ask for any more temporary storage, according to
63 // https://developers.google.com/chrome/whitepapers/storage.
64 BrowserThread::PostTask(
65 BrowserThread::IO,
66 FROM_HERE,
67 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps,
68 partition->GetQuotaManager(),
69 launch_url,
70 storage::kStorageTypePersistent,
71 base::Bind(&ReportQuotaUsage)));
72 }
73 }
74
75 } // namespace
76
30 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( 77 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(
31 CookieSettings* cookie_settings) 78 CookieSettings* cookie_settings)
32 : cookie_settings_(cookie_settings) {} 79 : cookie_settings_(cookie_settings) {}
33 80
34 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} 81 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {}
35 82
36 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { 83 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
37 if (origin.SchemeIs(extensions::kExtensionScheme)) 84 if (origin.SchemeIs(extensions::kExtensionScheme))
38 return true; 85 return true;
39 base::AutoLock locker(lock_); 86 base::AutoLock locker(lock_);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 141 }
95 142
96 const extensions::ExtensionSet* 143 const extensions::ExtensionSet*
97 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( 144 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
98 const GURL& origin) { 145 const GURL& origin) {
99 base::AutoLock locker(lock_); 146 base::AutoLock locker(lock_);
100 return protected_apps_.ExtensionsContaining(origin); 147 return protected_apps_.ExtensionsContaining(origin);
101 } 148 }
102 149
103 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( 150 void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
104 const extensions::Extension* extension) { 151 const extensions::Extension* extension,
152 content::BrowserContext* browser_context) {
105 DCHECK(extension); 153 DCHECK(extension);
106 if (!(NeedsProtection(extension) || 154 if (!(NeedsProtection(extension) ||
107 extension->permissions_data()->HasAPIPermission( 155 extension->permissions_data()->HasAPIPermission(
108 APIPermission::kUnlimitedStorage) || 156 APIPermission::kUnlimitedStorage) ||
109 extension->permissions_data()->HasAPIPermission( 157 extension->permissions_data()->HasAPIPermission(
110 APIPermission::kFileBrowserHandler) || 158 APIPermission::kFileBrowserHandler) ||
111 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || 159 extensions::AppIsolationInfo::HasIsolatedStorage(extension) ||
112 extension->is_app())) { 160 extension->is_app())) {
113 return; 161 return;
114 } 162 }
115 163
116 int change_flags = 0; 164 int change_flags = 0;
117 { 165 {
118 base::AutoLock locker(lock_); 166 base::AutoLock locker(lock_);
119 if (NeedsProtection(extension) && protected_apps_.Add(extension)) 167 if (NeedsProtection(extension) && protected_apps_.Add(extension))
120 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; 168 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED;
121 // FIXME: Does GrantRightsForExtension imply |extension| is installed? 169 // FIXME: Does GrantRightsForExtension imply |extension| is installed?
122 if (extension->is_app()) 170 if (extension->is_app())
123 installed_apps_.Add(extension); 171 installed_apps_.Add(extension);
124 172
125 if (extension->permissions_data()->HasAPIPermission( 173 if (extension->permissions_data()->HasAPIPermission(
126 APIPermission::kUnlimitedStorage) && 174 APIPermission::kUnlimitedStorage) &&
127 unlimited_extensions_.Add(extension)) 175 unlimited_extensions_.Add(extension)) {
176 if (extension->is_hosted_app())
177 LogHostedAppUnlimitedStorageUsage(extension, browser_context);
178
128 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; 179 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED;
180 }
129 181
130 if (extension->permissions_data()->HasAPIPermission( 182 if (extension->permissions_data()->HasAPIPermission(
131 APIPermission::kFileBrowserHandler)) 183 APIPermission::kFileBrowserHandler))
132 file_handler_extensions_.Add(extension); 184 file_handler_extensions_.Add(extension);
133 185
134 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) 186 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension))
135 isolated_extensions_.Add(extension); 187 isolated_extensions_.Add(extension);
136 } 188 }
137 189
138 if (change_flags) { 190 if (change_flags) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 333
282 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 334 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
283 ClearCache(); 335 ClearCache();
284 extensions_.Clear(); 336 extensions_.Clear();
285 } 337 }
286 338
287 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { 339 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() {
288 STLDeleteValues(&cached_results_); 340 STLDeleteValues(&cached_results_);
289 cached_results_.clear(); 341 cached_results_.clear();
290 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698