| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 StorageState& state = iter->second; | 227 StorageState& state = iter->second; |
| 228 | 228 |
| 229 if (state.should_uma) { | 229 if (state.should_uma) { |
| 230 if (event.filter.storage_type == storage::kStorageTypePersistent) { | 230 if (event.filter.storage_type == storage::kStorageTypePersistent) { |
| 231 UMA_HISTOGRAM_MEMORY_KB( | 231 UMA_HISTOGRAM_MEMORY_KB( |
| 232 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", | 232 "Extensions.HostedAppUnlimitedStoragePersistentStorageUsage", |
| 233 event.usage); | 233 event.usage); |
| 234 } else { | 234 } else { |
| 235 // 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 |
| 236 // storage. | 236 // storage. |
| 237 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 237 BrowserThread::PostTask( |
| 238 base::Bind(&LogTemporaryStorageUsage, | 238 BrowserThread::IO, FROM_HERE, |
| 239 state.quota_manager, event.usage)); | 239 base::BindOnce(&LogTemporaryStorageUsage, state.quota_manager, |
| 240 event.usage)); |
| 240 } | 241 } |
| 241 } | 242 } |
| 242 | 243 |
| 243 if (state.next_threshold != -1 && | 244 if (state.next_threshold != -1 && |
| 244 event.usage >= state.next_threshold) { | 245 event.usage >= state.next_threshold) { |
| 245 while (event.usage >= state.next_threshold) | 246 while (event.usage >= state.next_threshold) |
| 246 state.next_threshold *= 2; | 247 state.next_threshold *= 2; |
| 247 | 248 |
| 248 BrowserThread::PostTask( | 249 BrowserThread::PostTask( |
| 249 BrowserThread::UI, | 250 BrowserThread::UI, FROM_HERE, |
| 250 FROM_HERE, | 251 base::BindOnce(&ExtensionStorageMonitor::OnStorageThresholdExceeded, |
| 251 base::Bind(&ExtensionStorageMonitor::OnStorageThresholdExceeded, | 252 storage_monitor_, state.extension_id, |
| 252 storage_monitor_, | 253 state.next_threshold, event.usage)); |
| 253 state.extension_id, | |
| 254 state.next_threshold, | |
| 255 event.usage)); | |
| 256 } | 254 } |
| 257 } | 255 } |
| 258 | 256 |
| 259 OriginStorageStateMap origin_state_map_; | 257 OriginStorageStateMap origin_state_map_; |
| 260 base::WeakPtr<ExtensionStorageMonitor> storage_monitor_; | 258 base::WeakPtr<ExtensionStorageMonitor> storage_monitor_; |
| 261 }; | 259 }; |
| 262 | 260 |
| 263 // ExtensionStorageMonitor | 261 // ExtensionStorageMonitor |
| 264 | 262 |
| 265 // static | 263 // static |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 325 |
| 328 int64_t next_threshold = GetNextStorageThresholdFromPrefs(extension->id()); | 326 int64_t next_threshold = GetNextStorageThresholdFromPrefs(extension->id()); |
| 329 if (next_threshold <= initial_extension_threshold_) { | 327 if (next_threshold <= initial_extension_threshold_) { |
| 330 // Clear the next threshold in the prefs. This effectively raises it to | 328 // Clear the next threshold in the prefs. This effectively raises it to |
| 331 // |initial_extension_threshold_|. If the current threshold is already | 329 // |initial_extension_threshold_|. If the current threshold is already |
| 332 // higher than this, leave it as is. | 330 // higher than this, leave it as is. |
| 333 SetNextStorageThreshold(extension->id(), 0); | 331 SetNextStorageThreshold(extension->id(), 0); |
| 334 | 332 |
| 335 if (storage_observer_.get()) { | 333 if (storage_observer_.get()) { |
| 336 BrowserThread::PostTask( | 334 BrowserThread::PostTask( |
| 337 BrowserThread::IO, | 335 BrowserThread::IO, FROM_HERE, |
| 338 FROM_HERE, | 336 base::BindOnce(&StorageEventObserver::UpdateThresholdForExtension, |
| 339 base::Bind(&StorageEventObserver::UpdateThresholdForExtension, | 337 storage_observer_, extension->id(), |
| 340 storage_observer_, | 338 initial_extension_threshold_)); |
| 341 extension->id(), | |
| 342 initial_extension_threshold_)); | |
| 343 } | 339 } |
| 344 } | 340 } |
| 345 } | 341 } |
| 346 | 342 |
| 347 void ExtensionStorageMonitor::OnExtensionUninstalled( | 343 void ExtensionStorageMonitor::OnExtensionUninstalled( |
| 348 content::BrowserContext* browser_context, | 344 content::BrowserContext* browser_context, |
| 349 const Extension* extension, | 345 const Extension* extension, |
| 350 extensions::UninstallReason reason) { | 346 extensions::UninstallReason reason) { |
| 351 RemoveNotificationForExtension(extension->id()); | 347 RemoveNotificationForExtension(extension->id()); |
| 352 } | 348 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 499 |
| 504 GURL storage_origin(site_url.GetOrigin()); | 500 GURL storage_origin(site_url.GetOrigin()); |
| 505 if (extension->is_hosted_app()) | 501 if (extension->is_hosted_app()) |
| 506 storage_origin = AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin(); | 502 storage_origin = AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin(); |
| 507 | 503 |
| 508 // Don't give a threshold if we're not enforcing. | 504 // Don't give a threshold if we're not enforcing. |
| 509 int next_threshold = | 505 int next_threshold = |
| 510 should_enforce ? GetNextStorageThreshold(extension->id()) : -1; | 506 should_enforce ? GetNextStorageThreshold(extension->id()) : -1; |
| 511 | 507 |
| 512 BrowserThread::PostTask( | 508 BrowserThread::PostTask( |
| 513 BrowserThread::IO, | 509 BrowserThread::IO, FROM_HERE, |
| 514 FROM_HERE, | 510 base::BindOnce(&StorageEventObserver::StartObservingForExtension, |
| 515 base::Bind(&StorageEventObserver::StartObservingForExtension, | 511 storage_observer_, quota_manager, extension->id(), |
| 516 storage_observer_, | 512 storage_origin, next_threshold, observer_rate_, |
| 517 quota_manager, | 513 for_metrics)); |
| 518 extension->id(), | |
| 519 storage_origin, | |
| 520 next_threshold, | |
| 521 observer_rate_, | |
| 522 for_metrics)); | |
| 523 } | 514 } |
| 524 | 515 |
| 525 void ExtensionStorageMonitor::StopMonitoringStorage( | 516 void ExtensionStorageMonitor::StopMonitoringStorage( |
| 526 const std::string& extension_id) { | 517 const std::string& extension_id) { |
| 527 if (!storage_observer_.get()) | 518 if (!storage_observer_.get()) |
| 528 return; | 519 return; |
| 529 | 520 |
| 530 BrowserThread::PostTask( | 521 BrowserThread::PostTask( |
| 531 BrowserThread::IO, | 522 BrowserThread::IO, FROM_HERE, |
| 532 FROM_HERE, | 523 base::BindOnce(&StorageEventObserver::StopObservingForExtension, |
| 533 base::Bind(&StorageEventObserver::StopObservingForExtension, | 524 storage_observer_, extension_id)); |
| 534 storage_observer_, | |
| 535 extension_id)); | |
| 536 } | 525 } |
| 537 | 526 |
| 538 void ExtensionStorageMonitor::StopMonitoringAll() { | 527 void ExtensionStorageMonitor::StopMonitoringAll() { |
| 539 extension_registry_observer_.RemoveAll(); | 528 extension_registry_observer_.RemoveAll(); |
| 540 | 529 |
| 541 RemoveAllNotifications(); | 530 RemoveAllNotifications(); |
| 542 | 531 |
| 543 if (!storage_observer_.get()) | 532 if (!storage_observer_.get()) |
| 544 return; | 533 return; |
| 545 | 534 |
| 546 BrowserThread::PostTask( | 535 BrowserThread::PostTask( |
| 547 BrowserThread::IO, | 536 BrowserThread::IO, FROM_HERE, |
| 548 FROM_HERE, | 537 base::BindOnce(&StorageEventObserver::StopObserving, storage_observer_)); |
| 549 base::Bind(&StorageEventObserver::StopObserving, storage_observer_)); | |
| 550 storage_observer_ = NULL; | 538 storage_observer_ = NULL; |
| 551 } | 539 } |
| 552 | 540 |
| 553 void ExtensionStorageMonitor::RemoveNotificationForExtension( | 541 void ExtensionStorageMonitor::RemoveNotificationForExtension( |
| 554 const std::string& extension_id) { | 542 const std::string& extension_id) { |
| 555 std::set<std::string>::iterator ext_id = | 543 std::set<std::string>::iterator ext_id = |
| 556 notified_extension_ids_.find(extension_id); | 544 notified_extension_ids_.find(extension_id); |
| 557 if (ext_id == notified_extension_ids_.end()) | 545 if (ext_id == notified_extension_ids_.end()) |
| 558 return; | 546 return; |
| 559 | 547 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 630 |
| 643 void ExtensionStorageMonitor::SetStorageNotificationEnabled( | 631 void ExtensionStorageMonitor::SetStorageNotificationEnabled( |
| 644 const std::string& extension_id, | 632 const std::string& extension_id, |
| 645 bool enable_notifications) { | 633 bool enable_notifications) { |
| 646 extension_prefs_->UpdateExtensionPref( | 634 extension_prefs_->UpdateExtensionPref( |
| 647 extension_id, kPrefDisableStorageNotifications, | 635 extension_id, kPrefDisableStorageNotifications, |
| 648 enable_notifications ? nullptr : base::MakeUnique<base::Value>(true)); | 636 enable_notifications ? nullptr : base::MakeUnique<base::Value>(true)); |
| 649 } | 637 } |
| 650 | 638 |
| 651 } // namespace extensions | 639 } // namespace extensions |
| OLD | NEW |