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

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

Issue 2592793002: Revert of Change how the quota system computes the total poolsize for temporary storage (Closed)
Patch Set: Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_storage_monitor.h" 5 #include "chrome/browser/extensions/extension_storage_monitor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // We want to know the usage of hosted apps' storage. 77 // We want to know the usage of hosted apps' storage.
78 return ShouldMonitorStorageFor(extension) && extension->is_hosted_app(); 78 return ShouldMonitorStorageFor(extension) && extension->is_hosted_app();
79 } 79 }
80 80
81 const Extension* GetExtensionById(content::BrowserContext* context, 81 const Extension* GetExtensionById(content::BrowserContext* context,
82 const std::string& extension_id) { 82 const std::string& extension_id) {
83 return ExtensionRegistry::Get(context)->GetExtensionById( 83 return ExtensionRegistry::Get(context)->GetExtensionById(
84 extension_id, ExtensionRegistry::EVERYTHING); 84 extension_id, ExtensionRegistry::EVERYTHING);
85 } 85 }
86 86
87 void LogTemporaryStorageUsage( 87 void LogTemporaryStorageUsage(int64_t usage,
88 scoped_refptr<storage::QuotaManager> quota_manager, 88 storage::QuotaStatusCode status,
89 int64_t usage) { 89 int64_t global_quota) {
90 const storage::QuotaSettings& settings = quota_manager->settings(); 90 if (status == storage::kQuotaStatusOk) {
91 if (settings.per_host_quota > 0) { 91 int64_t per_app_quota =
92 global_quota / storage::QuotaManager::kPerHostTemporaryPortion;
92 // Note we use COUNTS_100 (instead of PERCENT) because this can potentially 93 // Note we use COUNTS_100 (instead of PERCENT) because this can potentially
93 // exceed 100%. 94 // exceed 100%.
94 UMA_HISTOGRAM_COUNTS_100( 95 UMA_HISTOGRAM_COUNTS_100(
95 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage", 96 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage",
96 100.0 * usage / settings.per_host_quota); 97 100.0 * usage / per_app_quota);
97 } 98 }
98 } 99 }
99 100
100 } // namespace 101 } // namespace
101 102
102 // StorageEventObserver monitors the storage usage of extensions and lives on 103 // StorageEventObserver monitors the storage usage of extensions and lives on
103 // the IO thread. When a threshold is exceeded, a message will be posted to the 104 // the IO thread. When a threshold is exceeded, a message will be posted to the
104 // UI thread, which displays the notification. 105 // UI thread, which displays the notification.
105 class StorageEventObserver 106 class StorageEventObserver
106 : public base::RefCountedThreadSafe<StorageEventObserver, 107 : public base::RefCountedThreadSafe<StorageEventObserver,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 StorageState& state = iter->second; 228 StorageState& state = iter->second;
228 229
229 if (state.should_uma) { 230 if (state.should_uma) {
230 if (event.filter.storage_type == storage::kStorageTypePersistent) { 231 if (event.filter.storage_type == storage::kStorageTypePersistent) {
231 UMA_HISTOGRAM_MEMORY_KB( 232 UMA_HISTOGRAM_MEMORY_KB(
232 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", 233 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage",
233 event.usage); 234 event.usage);
234 } else { 235 } else {
235 // We can't use the quota in the event because it assumes unlimited 236 // We can't use the quota in the event because it assumes unlimited
236 // storage. 237 // storage.
237 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 238 BrowserThread::PostTask(
238 base::Bind(&LogTemporaryStorageUsage, 239 BrowserThread::IO,
239 state.quota_manager, event.usage)); 240 FROM_HERE,
241 base::Bind(&storage::QuotaManager::GetTemporaryGlobalQuota,
242 state.quota_manager,
243 base::Bind(&LogTemporaryStorageUsage, event.usage)));
240 } 244 }
241 } 245 }
242 246
243 if (state.next_threshold != -1 && 247 if (state.next_threshold != -1 &&
244 event.usage >= state.next_threshold) { 248 event.usage >= state.next_threshold) {
245 while (event.usage >= state.next_threshold) 249 while (event.usage >= state.next_threshold)
246 state.next_threshold *= 2; 250 state.next_threshold *= 2;
247 251
248 BrowserThread::PostTask( 252 BrowserThread::PostTask(
249 BrowserThread::UI, 253 BrowserThread::UI,
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 void ExtensionStorageMonitor::SetStorageNotificationEnabled( 648 void ExtensionStorageMonitor::SetStorageNotificationEnabled(
645 const std::string& extension_id, 649 const std::string& extension_id,
646 bool enable_notifications) { 650 bool enable_notifications) {
647 extension_prefs_->UpdateExtensionPref( 651 extension_prefs_->UpdateExtensionPref(
648 extension_id, 652 extension_id,
649 kPrefDisableStorageNotifications, 653 kPrefDisableStorageNotifications,
650 enable_notifications ? NULL : new base::FundamentalValue(true)); 654 enable_notifications ? NULL : new base::FundamentalValue(true));
651 } 655 }
652 656
653 } // namespace extensions 657 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698