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

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

Issue 310183005: Added uninstall option to notification of high disk usage by an extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@exstorage_refactor
Patch Set: Created 6 years, 6 months 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/scoped_observer.h" 12 #include "base/scoped_observer.h"
13 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
13 #include "components/keyed_service/core/keyed_service.h" 14 #include "components/keyed_service/core/keyed_service.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
16 #include "extensions/browser/extension_registry_observer.h" 17 #include "extensions/browser/extension_registry_observer.h"
17 18
18 namespace content { 19 namespace content {
19 class BrowserContext; 20 class BrowserContext;
20 } 21 }
21 22
22 namespace gfx { 23 namespace gfx {
23 class Image; 24 class Image;
24 } 25 }
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 class Extension; 29 class Extension;
29 class ExtensionPrefs; 30 class ExtensionPrefs;
30 class ExtensionRegistry; 31 class ExtensionRegistry;
31 class StorageEventObserver; 32 class StorageEventObserver;
32 33
33 // ExtensionStorageMonitor monitors the storage usage of extensions and apps 34 // ExtensionStorageMonitor monitors the storage usage of extensions and apps
34 // that are granted unlimited storage and displays notifications when high 35 // that are granted unlimited storage and displays notifications when high
35 // usage is detected. 36 // usage is detected.
36 class ExtensionStorageMonitor : public KeyedService, 37 class ExtensionStorageMonitor : public KeyedService,
37 public content::NotificationObserver, 38 public content::NotificationObserver,
38 public ExtensionRegistryObserver { 39 public ExtensionRegistryObserver,
40 public ExtensionUninstallDialog::Delegate {
39 public: 41 public:
40 static ExtensionStorageMonitor* Get(content::BrowserContext* context); 42 static ExtensionStorageMonitor* Get(content::BrowserContext* context);
41 43
42 // Indices of buttons in the notification. Exposed for testing. 44 // Indices of buttons in the notification. Exposed for testing.
43 enum ButtonIndex { 45 enum ButtonIndex {
44 BUTTON_DISABLE_NOTIFICATION = 0 46 BUTTON_DISABLE_NOTIFICATION = 0,
47 BUTTON_UNINSTALL
45 }; 48 };
46 49
47 explicit ExtensionStorageMonitor(content::BrowserContext* context); 50 explicit ExtensionStorageMonitor(content::BrowserContext* context);
48 virtual ~ExtensionStorageMonitor(); 51 virtual ~ExtensionStorageMonitor();
49 52
50 private: 53 private:
51 // content::NotificationObserver overrides: 54 // content::NotificationObserver overrides:
52 virtual void Observe(int type, 55 virtual void Observe(int type,
53 const content::NotificationSource& source, 56 const content::NotificationSource& source,
54 const content::NotificationDetails& details) OVERRIDE; 57 const content::NotificationDetails& details) OVERRIDE;
55 58
56 // ExtensionRegistryObserver overrides: 59 // ExtensionRegistryObserver overrides:
57 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, 60 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
58 const Extension* extension) OVERRIDE; 61 const Extension* extension) OVERRIDE;
59 virtual void OnExtensionUnloaded( 62 virtual void OnExtensionUnloaded(
60 content::BrowserContext* browser_context, 63 content::BrowserContext* browser_context,
61 const Extension* extension, 64 const Extension* extension,
62 UnloadedExtensionInfo::Reason reason) OVERRIDE; 65 UnloadedExtensionInfo::Reason reason) OVERRIDE;
63 virtual void OnExtensionWillBeInstalled( 66 virtual void OnExtensionWillBeInstalled(
64 content::BrowserContext* browser_context, 67 content::BrowserContext* browser_context,
65 const Extension* extension, 68 const Extension* extension,
66 bool is_update, 69 bool is_update,
67 bool from_ephemeral, 70 bool from_ephemeral,
68 const std::string& old_name) OVERRIDE; 71 const std::string& old_name) OVERRIDE;
69 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, 72 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
70 const Extension* extension) OVERRIDE; 73 const Extension* extension) OVERRIDE;
71 74
75 // Overridden from ExtensionUninstallDialog::Delegate:
76 virtual void ExtensionUninstallAccepted() OVERRIDE;
77 virtual void ExtensionUninstallCanceled() OVERRIDE;
78
72 std::string GetNotificationId(const std::string& extension_id); 79 std::string GetNotificationId(const std::string& extension_id);
73 80
74 void OnStorageThresholdExceeded(const std::string& extension_id, 81 void OnStorageThresholdExceeded(const std::string& extension_id,
75 int64 next_threshold, 82 int64 next_threshold,
76 int64 current_usage); 83 int64 current_usage);
77 void OnImageLoaded(const std::string& extension_id, 84 void OnImageLoaded(const std::string& extension_id,
78 int64 current_usage, 85 int64 current_usage,
79 const gfx::Image& image); 86 const gfx::Image& image);
80 void OnNotificationButtonClick(const std::string& extension_id, 87 void OnNotificationButtonClick(const std::string& extension_id,
81 int button_index); 88 int button_index);
82 89
83 void DisableStorageMonitoring(const std::string& extension_id); 90 void DisableStorageMonitoring(const std::string& extension_id);
84 void StartMonitoringStorage(const Extension* extension); 91 void StartMonitoringStorage(const Extension* extension);
85 void StopMonitoringStorage(const std::string& extension_id); 92 void StopMonitoringStorage(const std::string& extension_id);
86 void StopMonitoringAll(); 93 void StopMonitoringAll();
87 94
88 void RemoveNotificationForExtension(const std::string& extension_id); 95 void RemoveNotificationForExtension(const std::string& extension_id);
89 void RemoveAllNotifications(); 96 void RemoveAllNotifications();
90 97
98 // Displays the prompt for uninstalling the extension.
99 void ShowUninstallPrompt(const std::string& extension_id);
100
91 // Returns/sets the next threshold for displaying a notification if an 101 // Returns/sets the next threshold for displaying a notification if an
92 // extension or app consumes excessive disk space. 102 // extension or app consumes excessive disk space.
93 int64 GetNextStorageThreshold(const std::string& extension_id) const; 103 int64 GetNextStorageThreshold(const std::string& extension_id) const;
94 void SetNextStorageThreshold(const std::string& extension_id, 104 void SetNextStorageThreshold(const std::string& extension_id,
95 int64 next_threshold); 105 int64 next_threshold);
96 106
97 // Returns the raw next storage threshold value stored in prefs. Returns 0 if 107 // Returns the raw next storage threshold value stored in prefs. Returns 0 if
98 // the initial threshold has not yet been reached. 108 // the initial threshold has not yet been reached.
99 int64 GetNextStorageThresholdFromPrefs(const std::string& extension_id) const; 109 int64 GetNextStorageThresholdFromPrefs(const std::string& extension_id) const;
100 110
(...skipping 24 matching lines...) Expand all
125 extensions::ExtensionPrefs* extension_prefs_; 135 extensions::ExtensionPrefs* extension_prefs_;
126 136
127 content::NotificationRegistrar registrar_; 137 content::NotificationRegistrar registrar_;
128 ScopedObserver<extensions::ExtensionRegistry, 138 ScopedObserver<extensions::ExtensionRegistry,
129 extensions::ExtensionRegistryObserver> 139 extensions::ExtensionRegistryObserver>
130 extension_registry_observer_; 140 extension_registry_observer_;
131 141
132 // StorageEventObserver monitors storage for extensions on the IO thread. 142 // StorageEventObserver monitors storage for extensions on the IO thread.
133 scoped_refptr<StorageEventObserver> storage_observer_; 143 scoped_refptr<StorageEventObserver> storage_observer_;
134 144
145 // Modal dialog used to confirm removal of an extension.
146 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_;
147
148 // The ID of the extension that is the subject of the uninstall confirmation
149 // dialog.
150 std::string uninstall_extension_id_;
151
135 base::WeakPtrFactory<ExtensionStorageMonitor> weak_ptr_factory_; 152 base::WeakPtrFactory<ExtensionStorageMonitor> weak_ptr_factory_;
136 153
137 friend class StorageEventObserver; 154 friend class StorageEventObserver;
138 friend class ExtensionStorageMonitorTest; 155 friend class ExtensionStorageMonitorTest;
139 156
140 DISALLOW_COPY_AND_ASSIGN(ExtensionStorageMonitor); 157 DISALLOW_COPY_AND_ASSIGN(ExtensionStorageMonitor);
141 }; 158 };
142 159
143 } // namespace extensions 160 } // namespace extensions
144 161
145 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_ 162 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_STORAGE_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/extension_storage_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698