OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" |
| 13 #include "extensions/browser/extension_registry_observer.h" |
| 14 |
| 15 namespace content { |
| 16 class BrowserContext; |
| 17 } |
| 18 |
| 19 namespace gfx { |
| 20 class Image; |
| 21 } |
| 22 |
| 23 namespace extensions { |
| 24 |
| 25 class Extension; |
| 26 class StorageEventObserver; |
| 27 |
| 28 // ExtensionStorageMonitor monitors the storage usage of extensions and apps |
| 29 // that are granted unlimited storage and displays notifications when high |
| 30 // usage is detected. |
| 31 class ExtensionStorageMonitor : public KeyedService, |
| 32 public content::NotificationObserver, |
| 33 public ExtensionRegistryObserver { |
| 34 public: |
| 35 static ExtensionStorageMonitor* Get(content::BrowserContext* context); |
| 36 |
| 37 // Indices of buttons in the notification. Exposed for testing. |
| 38 enum ButtonIndex { |
| 39 BUTTON_DISABLE_NOTIFICATION = 0 |
| 40 }; |
| 41 |
| 42 explicit ExtensionStorageMonitor(content::BrowserContext* context); |
| 43 virtual ~ExtensionStorageMonitor(); |
| 44 |
| 45 private: |
| 46 // content::NotificationObserver overrides: |
| 47 virtual void Observe(int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) OVERRIDE; |
| 50 |
| 51 // ExtensionRegistryObserver overrides: |
| 52 virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE; |
| 53 |
| 54 static std::string GetNotificationId(const std::string& extension_id); |
| 55 |
| 56 void OnStorageThresholdExceeded(const std::string& extension_id, |
| 57 int64 next_threshold, |
| 58 int64 current_usage); |
| 59 void OnImageLoaded(const std::string& extension_id, |
| 60 int64 current_usage, |
| 61 const gfx::Image& image); |
| 62 void OnNotificationButtonClick(const std::string& extension_id, |
| 63 int button_index); |
| 64 |
| 65 void DisableStorageMonitoring(const std::string& extension_id); |
| 66 void StartMonitoringStorage(const Extension* extension); |
| 67 void StopMonitoringStorage(const std::string& extension_id); |
| 68 void StopMonitoringAll(); |
| 69 |
| 70 // Initially, monitoring will only be applied to ephemeral apps. This flag |
| 71 // is set by tests to enable for all extensions and apps. |
| 72 bool enable_for_all_extensions_; |
| 73 |
| 74 // A lower threshold is set by tests. |
| 75 int64 initial_extension_threshold_; |
| 76 int64 initial_ephemeral_threshold_; |
| 77 int observer_rate_; |
| 78 |
| 79 content::BrowserContext* context_; |
| 80 content::NotificationRegistrar registrar_; |
| 81 scoped_refptr<StorageEventObserver> storage_observer_; |
| 82 base::WeakPtrFactory<ExtensionStorageMonitor> weak_ptr_factory_; |
| 83 |
| 84 friend class StorageEventObserver; |
| 85 friend class ExtensionStorageMonitorTest; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(ExtensionStorageMonitor); |
| 88 }; |
| 89 |
| 90 } // namespace extensions |
| 91 |
| 92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ |
OLD | NEW |