Commit 4ff043e5 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Handle promotion of ephemeral apps in the ExtensionStorageMonitor

Ephemeral apps have a lower initial threshold, which should be
increased when they are promoted to regular installed apps.
This patch also moves the storaged monitoring related prefs
into ExtensionStorageMonitor, as they are specific only to
this service.

BUG=374018
TEST= browser_tests (ExtensionStorageMonitorTest.*)

Review URL: https://codereview.chromium.org/314563003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274813 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a06ca60
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
...@@ -25,6 +26,8 @@ class Image; ...@@ -25,6 +26,8 @@ class Image;
namespace extensions { namespace extensions {
class Extension; class Extension;
class ExtensionPrefs;
class ExtensionRegistry;
class StorageEventObserver; class StorageEventObserver;
// ExtensionStorageMonitor monitors the storage usage of extensions and apps // ExtensionStorageMonitor monitors the storage usage of extensions and apps
...@@ -53,10 +56,18 @@ class ExtensionStorageMonitor : public KeyedService, ...@@ -53,10 +56,18 @@ class ExtensionStorageMonitor : public KeyedService,
// ExtensionRegistryObserver overrides: // ExtensionRegistryObserver overrides:
virtual void OnExtensionLoaded(content::BrowserContext* browser_context, virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) OVERRIDE; const Extension* extension) OVERRIDE;
virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, virtual void OnExtensionUnloaded(
const Extension* extension, content::BrowserContext* browser_context,
UnloadedExtensionInfo::Reason reason) const Extension* extension,
OVERRIDE; UnloadedExtensionInfo::Reason reason) OVERRIDE;
virtual void OnExtensionWillBeInstalled(
content::BrowserContext* browser_context,
const Extension* extension,
bool is_update,
bool from_ephemeral,
const std::string& old_name) OVERRIDE;
virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
const Extension* extension) OVERRIDE;
std::string GetNotificationId(const std::string& extension_id); std::string GetNotificationId(const std::string& extension_id);
...@@ -73,23 +84,54 @@ class ExtensionStorageMonitor : public KeyedService, ...@@ -73,23 +84,54 @@ class ExtensionStorageMonitor : public KeyedService,
void StartMonitoringStorage(const Extension* extension); void StartMonitoringStorage(const Extension* extension);
void StopMonitoringStorage(const std::string& extension_id); void StopMonitoringStorage(const std::string& extension_id);
void StopMonitoringAll(); void StopMonitoringAll();
void RemoveNotificationForExtension(const std::string& extension_id); void RemoveNotificationForExtension(const std::string& extension_id);
void RemoveAllNotifications(); void RemoveAllNotifications();
// Returns/sets the next threshold for displaying a notification if an
// extension or app consumes excessive disk space.
int64 GetNextStorageThreshold(const std::string& extension_id) const;
void SetNextStorageThreshold(const std::string& extension_id,
int64 next_threshold);
// Returns the raw next storage threshold value stored in prefs. Returns 0 if
// the initial threshold has not yet been reached.
int64 GetNextStorageThresholdFromPrefs(const std::string& extension_id) const;
// Returns/sets whether notifications should be shown if an extension or app
// consumes too much disk space.
bool IsStorageNotificationEnabled(const std::string& extension_id) const;
void SetStorageNotificationEnabled(const std::string& extension_id,
bool enable_notifications);
// Initially, monitoring will only be applied to ephemeral apps. This flag // Initially, monitoring will only be applied to ephemeral apps. This flag
// is set by tests to enable for all extensions and apps. // is set by tests to enable for all extensions and apps.
bool enable_for_all_extensions_; bool enable_for_all_extensions_;
// The first notification is shown after the initial threshold is exceeded.
// Ephemeral apps have a lower threshold than fully installed extensions.
// A lower threshold is set by tests. // A lower threshold is set by tests.
int64 initial_extension_threshold_; int64 initial_extension_threshold_;
int64 initial_ephemeral_threshold_; int64 initial_ephemeral_threshold_;
// The rate (in seconds) at which we would like to receive storage updates
// from QuotaManager. Overridden in tests.
int observer_rate_; int observer_rate_;
// IDs of extensions that notifications were shown for.
std::set<std::string> notified_extension_ids_; std::set<std::string> notified_extension_ids_;
content::BrowserContext* context_; content::BrowserContext* context_;
extensions::ExtensionPrefs* extension_prefs_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
// StorageEventObserver monitors storage for extensions on the IO thread.
scoped_refptr<StorageEventObserver> storage_observer_; scoped_refptr<StorageEventObserver> storage_observer_;
base::WeakPtrFactory<ExtensionStorageMonitor> weak_ptr_factory_; base::WeakPtrFactory<ExtensionStorageMonitor> weak_ptr_factory_;
friend class StorageEventObserver; friend class StorageEventObserver;
......
...@@ -194,15 +194,6 @@ const char kPrefInstallParam[] = "install_parameter"; ...@@ -194,15 +194,6 @@ const char kPrefInstallParam[] = "install_parameter";
// A list of installed ids and a signature. // A list of installed ids and a signature.
const char kInstallSignature[] = "extensions.install_signature"; const char kInstallSignature[] = "extensions.install_signature";
// A preference that stores the next threshold for displaying a notification
// when an extension or app consumes excessive disk space. This will not be
// set until the extension/app reaches the initial threshold.
const char kPrefNextStorageThreshold[] = "next_storage_threshold";
// If this preference is set to true, notifications will be suppressed when an
// extension or app consumes excessive disk space.
const char kPrefDisableStorageNotifications[] = "disable_storage_notifications";
// Provider of write access to a dictionary storing extension prefs. // Provider of write access to a dictionary storing extension prefs.
class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
public: public:
...@@ -1939,44 +1930,6 @@ void ExtensionPrefs::SetInstallParam(const std::string& extension_id, ...@@ -1939,44 +1930,6 @@ void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
new base::StringValue(install_parameter)); new base::StringValue(install_parameter));
} }
int64 ExtensionPrefs::GetNextStorageThreshold(
const std::string& extension_id) const {
int64 next_threshold;
if (ReadInt64(GetExtensionPref(extension_id),
kPrefNextStorageThreshold,
&next_threshold)) {
return next_threshold;
}
return 0;
}
void ExtensionPrefs::SetNextStorageThreshold(const std::string& extension_id,
int64 next_threshold) {
ScopedExtensionPrefUpdate update(prefs_, extension_id);
SaveInt64(update.Get(), kPrefNextStorageThreshold, next_threshold);
}
bool ExtensionPrefs::IsStorageNotificationEnabled(
const std::string& extension_id) const {
bool disable_notifications;
if (ReadPrefAsBoolean(extension_id,
kPrefDisableStorageNotifications,
&disable_notifications)) {
return !disable_notifications;
}
return true;
}
void ExtensionPrefs::SetStorageNotificationEnabled(
const std::string& extension_id, bool enable_notifications) {
UpdateExtensionPref(
extension_id,
kPrefDisableStorageNotifications,
enable_notifications ? NULL : new base::FundamentalValue(true));
}
ExtensionPrefs::ExtensionPrefs( ExtensionPrefs::ExtensionPrefs(
PrefService* prefs, PrefService* prefs,
const base::FilePath& root_dir, const base::FilePath& root_dir,
......
...@@ -558,19 +558,6 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService { ...@@ -558,19 +558,6 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
void SetInstallParam(const std::string& extension_id, void SetInstallParam(const std::string& extension_id,
const std::string& install_parameter); const std::string& install_parameter);
// Gets/sets the next threshold for displaying a notification if an extension
// or app consumes excessive disk space. Returns 0 if the initial threshold
// has not yet been reached.
int64 GetNextStorageThreshold(const std::string& extension_id) const;
void SetNextStorageThreshold(const std::string& extension_id,
int64 next_threshold);
// Gets/sets whether notifications should be shown if an extension or app
// consumes too much disk space.
bool IsStorageNotificationEnabled(const std::string& extension_id) const;
void SetStorageNotificationEnabled(const std::string& extension_id,
bool enable_notifications);
private: private:
friend class ExtensionPrefsBlacklistedExtensions; // Unit test. friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
friend class ExtensionPrefsUninstallExtension; // Unit test. friend class ExtensionPrefsUninstallExtension; // Unit test.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment