OLD | NEW |
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 Loading... |
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(int64_t usage, | 87 void LogTemporaryStorageUsage( |
88 storage::QuotaStatusCode status, | 88 scoped_refptr<storage::QuotaManager> quota_manager, |
89 int64_t global_quota) { | 89 int64_t usage) { |
90 if (status == storage::kQuotaStatusOk) { | 90 const storage::QuotaSettings& settings = quota_manager->settings(); |
91 int64_t per_app_quota = | 91 if (settings.per_host_quota > 0) { |
92 global_quota / storage::QuotaManager::kPerHostTemporaryPortion; | |
93 // Note we use COUNTS_100 (instead of PERCENT) because this can potentially | 92 // Note we use COUNTS_100 (instead of PERCENT) because this can potentially |
94 // exceed 100%. | 93 // exceed 100%. |
95 UMA_HISTOGRAM_COUNTS_100( | 94 UMA_HISTOGRAM_COUNTS_100( |
96 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage", | 95 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage", |
97 100.0 * usage / per_app_quota); | 96 100.0 * usage / settings.per_host_quota); |
98 } | 97 } |
99 } | 98 } |
100 | 99 |
101 } // namespace | 100 } // namespace |
102 | 101 |
103 // StorageEventObserver monitors the storage usage of extensions and lives on | 102 // StorageEventObserver monitors the storage usage of extensions and lives on |
104 // the IO thread. When a threshold is exceeded, a message will be posted to the | 103 // the IO thread. When a threshold is exceeded, a message will be posted to the |
105 // UI thread, which displays the notification. | 104 // UI thread, which displays the notification. |
106 class StorageEventObserver | 105 class StorageEventObserver |
107 : public base::RefCountedThreadSafe<StorageEventObserver, | 106 : public base::RefCountedThreadSafe<StorageEventObserver, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 StorageState& state = iter->second; | 227 StorageState& state = iter->second; |
229 | 228 |
230 if (state.should_uma) { | 229 if (state.should_uma) { |
231 if (event.filter.storage_type == storage::kStorageTypePersistent) { | 230 if (event.filter.storage_type == storage::kStorageTypePersistent) { |
232 UMA_HISTOGRAM_MEMORY_KB( | 231 UMA_HISTOGRAM_MEMORY_KB( |
233 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", | 232 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", |
234 event.usage); | 233 event.usage); |
235 } else { | 234 } else { |
236 // We can't use the quota in the event because it assumes unlimited | 235 // We can't use the quota in the event because it assumes unlimited |
237 // storage. | 236 // storage. |
238 BrowserThread::PostTask( | 237 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
239 BrowserThread::IO, | 238 base::Bind(&LogTemporaryStorageUsage, |
240 FROM_HERE, | 239 state.quota_manager, event.usage)); |
241 base::Bind(&storage::QuotaManager::GetTemporaryGlobalQuota, | |
242 state.quota_manager, | |
243 base::Bind(&LogTemporaryStorageUsage, event.usage))); | |
244 } | 240 } |
245 } | 241 } |
246 | 242 |
247 if (state.next_threshold != -1 && | 243 if (state.next_threshold != -1 && |
248 event.usage >= state.next_threshold) { | 244 event.usage >= state.next_threshold) { |
249 while (event.usage >= state.next_threshold) | 245 while (event.usage >= state.next_threshold) |
250 state.next_threshold *= 2; | 246 state.next_threshold *= 2; |
251 | 247 |
252 BrowserThread::PostTask( | 248 BrowserThread::PostTask( |
253 BrowserThread::UI, | 249 BrowserThread::UI, |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 void ExtensionStorageMonitor::SetStorageNotificationEnabled( | 644 void ExtensionStorageMonitor::SetStorageNotificationEnabled( |
649 const std::string& extension_id, | 645 const std::string& extension_id, |
650 bool enable_notifications) { | 646 bool enable_notifications) { |
651 extension_prefs_->UpdateExtensionPref( | 647 extension_prefs_->UpdateExtensionPref( |
652 extension_id, | 648 extension_id, |
653 kPrefDisableStorageNotifications, | 649 kPrefDisableStorageNotifications, |
654 enable_notifications ? NULL : new base::FundamentalValue(true)); | 650 enable_notifications ? NULL : new base::FundamentalValue(true)); |
655 } | 651 } |
656 | 652 |
657 } // namespace extensions | 653 } // namespace extensions |
OLD | NEW |