summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/app_window_geometry_cache.cc55
-rw-r--r--apps/app_window_geometry_cache.h32
-rw-r--r--apps/app_window_geometry_cache_unittest.cc32
3 files changed, 62 insertions, 57 deletions
diff --git a/apps/app_window_geometry_cache.cc b/apps/app_window_geometry_cache.cc
index c89988b..ce6290e 100644
--- a/apps/app_window_geometry_cache.cc
+++ b/apps/app_window_geometry_cache.cc
@@ -7,14 +7,12 @@
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_types.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/extension.h"
@@ -32,13 +30,9 @@ AppWindowGeometryCache::AppWindowGeometryCache(
Profile* profile,
extensions::ExtensionPrefs* prefs)
: prefs_(prefs),
- sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)) {
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
- content::Source<Profile>(profile));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
- content::Source<Profile>(profile));
+ sync_delay_(base::TimeDelta::FromMilliseconds(kSyncTimeoutMilliseconds)),
+ extension_registry_observer_(this) {
+ extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
}
AppWindowGeometryCache::~AppWindowGeometryCache() {}
@@ -192,29 +186,18 @@ AppWindowGeometryCache::WindowData::WindowData()
AppWindowGeometryCache::WindowData::~WindowData() {}
-void AppWindowGeometryCache::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
- std::string extension_id =
- content::Details<const extensions::Extension>(details).ptr()->id();
- LoadGeometryFromStorage(extension_id);
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
- std::string extension_id =
- content::Details<const extensions::UnloadedExtensionInfo>(details)
- .ptr()
- ->extension->id();
- OnExtensionUnloaded(extension_id);
- break;
- }
- default:
- NOTREACHED();
- return;
- }
+void AppWindowGeometryCache::OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension) {
+ LoadGeometryFromStorage(extension->id());
+}
+
+void AppWindowGeometryCache::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ extensions::UnloadedExtensionInfo::Reason reason) {
+ SyncToStorage();
+ cache_.erase(extension->id());
}
void AppWindowGeometryCache::SetSyncDelayForTests(int timeout_ms) {
@@ -274,12 +257,6 @@ void AppWindowGeometryCache::LoadGeometryFromStorage(
}
}
-void AppWindowGeometryCache::OnExtensionUnloaded(
- const std::string& extension_id) {
- SyncToStorage();
- cache_.erase(extension_id);
-}
-
///////////////////////////////////////////////////////////////////////////////
// Factory boilerplate
diff --git a/apps/app_window_geometry_cache.h b/apps/app_window_geometry_cache.h
index 2076428..8813eea 100644
--- a/apps/app_window_geometry_cache.h
+++ b/apps/app_window_geometry_cache.h
@@ -12,13 +12,13 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
+#include "base/scoped_observer.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
+#include "extensions/browser/extension_registry_observer.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/rect.h"
@@ -26,6 +26,7 @@ class Profile;
namespace extensions {
class ExtensionPrefs;
+class ExtensionRegistry;
}
namespace apps {
@@ -34,7 +35,7 @@ namespace apps {
// for IO when creating a new window, and to not cause IO on every window
// geometry change.
class AppWindowGeometryCache : public KeyedService,
- public content::NotificationObserver {
+ public extensions::ExtensionRegistryObserver {
public:
class Factory : public BrowserContextKeyedServiceFactory {
public:
@@ -122,31 +123,38 @@ class AppWindowGeometryCache : public KeyedService,
// Data stored for each extension.
typedef std::map<std::string, WindowData> ExtensionData;
- // content::NotificationObserver
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ // ExtensionRegistryObserver implementation.
+ virtual void OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension) OVERRIDE;
+ virtual void OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const extensions::Extension* extension,
+ extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
void LoadGeometryFromStorage(const std::string& extension_id);
- void OnExtensionUnloaded(const std::string& extension_id);
void SyncToStorage();
// Preferences storage.
extensions::ExtensionPrefs* prefs_;
- // Cached data
+ // Cached data.
std::map<std::string, ExtensionData> cache_;
- // Data that still needs saving
+ // Data that still needs saving.
std::set<std::string> unsynced_extensions_;
- // The timer used to save the data
+ // The timer used to save the data.
base::OneShotTimer<AppWindowGeometryCache> sync_timer_;
// The timeout value we'll use for |sync_timer_|.
base::TimeDelta sync_delay_;
- content::NotificationRegistrar registrar_;
+ // Listen to extension load, unloaded notifications.
+ ScopedObserver<extensions::ExtensionRegistry,
+ extensions::ExtensionRegistryObserver>
+ extension_registry_observer_;
+
ObserverList<Observer> observers_;
};
diff --git a/apps/app_window_geometry_cache_unittest.cc b/apps/app_window_geometry_cache_unittest.cc
index ccff882..50240c7 100644
--- a/apps/app_window_geometry_cache_unittest.cc
+++ b/apps/app_window_geometry_cache_unittest.cc
@@ -11,23 +11,38 @@
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/common/extension_builder.h"
+#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
+using content::BrowserThread;
+
+namespace apps {
+
+namespace {
const char kWindowId[] = "windowid";
const char kWindowId2[] = "windowid2";
-using content::BrowserThread;
+// Create a very simple extension with id.
+scoped_refptr<extensions::Extension> CreateExtension(const std::string& id) {
+ return extensions::ExtensionBuilder()
+ .SetManifest(extensions::DictionaryBuilder().Set("name", "test").Set(
+ "version", "0.1"))
+ .SetID(id)
+ .Build();
+}
-namespace apps {
+} // namespace
// Base class for tests.
class AppWindowGeometryCacheTest : public testing::Test {
public:
AppWindowGeometryCacheTest()
- : ui_thread_(BrowserThread::UI, &ui_message_loop_) {
+ : profile_(new TestingProfile),
+ ui_thread_(BrowserThread::UI, &ui_message_loop_) {
prefs_.reset(new extensions::TestExtensionPrefs(
ui_message_loop_.message_loop_proxy().get()));
- cache_.reset(new AppWindowGeometryCache(&profile_, prefs_->prefs()));
+ cache_.reset(new AppWindowGeometryCache(profile_.get(), prefs_->prefs()));
cache_->SetSyncDelayForTests(0);
}
@@ -45,7 +60,7 @@ class AppWindowGeometryCacheTest : public testing::Test {
void UnloadExtension(const std::string& extension_id);
protected:
- TestingProfile profile_;
+ scoped_ptr<TestingProfile> profile_;
base::MessageLoopForUI ui_message_loop_;
content::TestBrowserThread ui_thread_;
scoped_ptr<extensions::TestExtensionPrefs> prefs_;
@@ -86,7 +101,12 @@ void AppWindowGeometryCacheTest::LoadExtension(
void AppWindowGeometryCacheTest::UnloadExtension(
const std::string& extension_id) {
- cache_->OnExtensionUnloaded(extension_id);
+ scoped_refptr<extensions::Extension> extension =
+ CreateExtension(extension_id);
+ cache_->OnExtensionUnloaded(
+ profile_.get(),
+ extension.get(),
+ extensions::UnloadedExtensionInfo::REASON_DISABLE);
WaitForSync();
}