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 storage::TemporaryStorageConfiguration |
cmumford
2016/10/25 20:30:54
const storage::TemporaryStorageConfiguration& conf
michaeln
2016/10/26 21:47:53
Done.
| |
91 int64_t per_app_quota = | 91 config = quota_manager->storage_config(); |
92 global_quota / storage::QuotaManager::kPerHostTemporaryPortion; | 92 if (config.per_host_quota > 0) { |
93 // 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 |
94 // exceed 100%. | 94 // exceed 100%. |
95 UMA_HISTOGRAM_COUNTS_100( | 95 UMA_HISTOGRAM_COUNTS_100( |
96 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage", | 96 "Extensions.HostedAppUnlimitedStorageTemporaryStorageUsage", |
cmumford
2016/10/25 20:30:54
This doesn't change the meaning of Extensions.Host
michaeln
2016/10/26 21:47:53
i don't think it does
| |
97 100.0 * usage / per_app_quota); | 97 100.0 * usage / config.per_host_quota); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 // StorageEventObserver monitors the storage usage of extensions and lives on | 103 // 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 | 104 // the IO thread. When a threshold is exceeded, a message will be posted to the |
105 // UI thread, which displays the notification. | 105 // UI thread, which displays the notification. |
106 class StorageEventObserver | 106 class StorageEventObserver |
107 : public base::RefCountedThreadSafe<StorageEventObserver, | 107 : public base::RefCountedThreadSafe<StorageEventObserver, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 if (event.filter.storage_type == storage::kStorageTypePersistent) { | 231 if (event.filter.storage_type == storage::kStorageTypePersistent) { |
232 UMA_HISTOGRAM_MEMORY_KB( | 232 UMA_HISTOGRAM_MEMORY_KB( |
233 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", | 233 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", |
234 event.usage); | 234 event.usage); |
235 } else { | 235 } else { |
236 // 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 |
237 // storage. | 237 // storage. |
238 BrowserThread::PostTask( | 238 BrowserThread::PostTask( |
239 BrowserThread::IO, | 239 BrowserThread::IO, |
240 FROM_HERE, | 240 FROM_HERE, |
241 base::Bind(&storage::QuotaManager::GetTemporaryGlobalQuota, | 241 base::Bind(&LogTemporaryStorageUsage, |
242 state.quota_manager, | 242 state.quota_manager, event.usage)); |
243 base::Bind(&LogTemporaryStorageUsage, event.usage))); | |
244 } | 243 } |
245 } | 244 } |
246 | 245 |
247 if (state.next_threshold != -1 && | 246 if (state.next_threshold != -1 && |
248 event.usage >= state.next_threshold) { | 247 event.usage >= state.next_threshold) { |
249 while (event.usage >= state.next_threshold) | 248 while (event.usage >= state.next_threshold) |
250 state.next_threshold *= 2; | 249 state.next_threshold *= 2; |
251 | 250 |
252 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
253 BrowserThread::UI, | 252 BrowserThread::UI, |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 void ExtensionStorageMonitor::SetStorageNotificationEnabled( | 647 void ExtensionStorageMonitor::SetStorageNotificationEnabled( |
649 const std::string& extension_id, | 648 const std::string& extension_id, |
650 bool enable_notifications) { | 649 bool enable_notifications) { |
651 extension_prefs_->UpdateExtensionPref( | 650 extension_prefs_->UpdateExtensionPref( |
652 extension_id, | 651 extension_id, |
653 kPrefDisableStorageNotifications, | 652 kPrefDisableStorageNotifications, |
654 enable_notifications ? NULL : new base::FundamentalValue(true)); | 653 enable_notifications ? NULL : new base::FundamentalValue(true)); |
655 } | 654 } |
656 | 655 |
657 } // namespace extensions | 656 } // namespace extensions |
OLD | NEW |