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

Unified Diff: chrome/browser/extensions/extension_settings_frontend.h

Issue 8177022: Add onChanged events to the extension settings API, both from sync and between (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_settings_frontend.h
diff --git a/chrome/browser/extensions/extension_settings_frontend.h b/chrome/browser/extensions/extension_settings_frontend.h
index 7fe3dc00b91ae9564be38b910b6cd4b1e2bad315..fa9ea1f85e9c54caadeecc0b52ca03851ce782fa 100644
--- a/chrome/browser/extensions/extension_settings_frontend.h
+++ b/chrome/browser/extensions/extension_settings_frontend.h
@@ -6,34 +6,57 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_
#pragma once
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
-#include "base/callback.h"
+#include "base/observer_list_threadsafe.h"
+#include "chrome/browser/extensions/extension_settings_observer.h"
#include "chrome/browser/sync/api/syncable_service.h"
+#include "content/common/notification_observer.h"
+#include "content/common/notification_registrar.h"
class FilePath;
+class Profile;
class ExtensionSettingsBackend;
class ExtensionSettingsStorage;
// The component of extension settings which runs on the UI thread, as opposed
// to ExtensionSettingsBackend which lives on the FILE thread.
-class ExtensionSettingsFrontend {
+class ExtensionSettingsFrontend : public NotificationObserver {
public:
- explicit ExtensionSettingsFrontend(const FilePath& base_path);
+ explicit ExtensionSettingsFrontend(Profile* profile);
+ virtual ~ExtensionSettingsFrontend();
typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback;
// Runs |callback| on the FILE thread with the extension settings.
void RunWithBackend(const BackendCallback& callback);
- ~ExtensionSettingsFrontend();
+ // Adds an observer to settings changes.
+ void AddObserver(ExtensionSettingsObserver* observer);
+
+ // Removes an observer to settings changes.
+ void RemoveObserver(ExtensionSettingsObserver* observer);
+
+ // Sends a change event to all settings change observer. |profile| is the
+ // profile that the change originated from.
+ void TriggerOnSettingsChanged(
Matt Perry 2011/10/07 22:39:52 Is this actually used? I only see TriggerOnSetting
not at google - send to devlin 2011/10/10 01:00:16 Done.
+ Profile* profile,
+ const std::string& extension_id,
+ const ExtensionSettingsObserver::ChangeList& changes);
+
+ // NotificationObserver implementation.
+ virtual void Observe(
+ int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE;
private:
// Ref-counted container for the ExtensionSettingsBackend object.
class Core : public base::RefCountedThreadSafe<Core> {
public:
// Constructed on UI thread.
- Core();
+ explicit Core(ObserverListThreadSafe<ExtensionSettingsObserver>* observers);
akalin 2011/10/07 21:06:23 const ref to scoped_refptr
not at google - send to devlin 2011/10/10 01:00:16 Done.
// Does any FILE thread specific initialization, such as construction of
// |backend_|. Must be called before any call to
@@ -48,14 +71,55 @@ class ExtensionSettingsFrontend {
virtual ~Core();
friend class base::RefCountedThreadSafe<Core>;
+ // Thread safe.
+ scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> >
+ observers_;
+
// Lives on the FILE thread.
ExtensionSettingsBackend* backend_;
DISALLOW_COPY_AND_ASSIGN(Core);
};
+ // Observer which sends events to a target profile iff the profile isn't the
+ // originating profile for the event.
+ class DefaultObserver : public ExtensionSettingsObserver {
Matt Perry 2011/10/07 22:39:52 nit: move the implementation into the .cc file. yo
not at google - send to devlin 2011/10/10 01:00:16 Done.
+ public:
+ explicit DefaultObserver(Profile* target_profile);
+ virtual ~DefaultObserver();
+
+ virtual void OnSettingsChanged(
+ Profile* origin_profile,
+ const std::string& extension_id,
+ const std::string& event_json) OVERRIDE;
+
+ private:
+ Profile* target_profile_;
+ };
+
+ // Called when a profile is created.
+ void OnProfileCreated(Profile* profile);
+
+ // Called when a profile is destroyed.
+ void OnProfileDestroyed(Profile* profile);
+
+ // List of observers to settings changes.
+ scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_;
+
+ // Map of Profiles to their Observers. This is so that when Profiles are
+ // destroyed we can remove the associated Observer.
+ // MUST ONLY BE ACCESSED ON THE UI THREAD.
akalin 2011/10/07 21:06:23 this warning goes for any member of this class bes
not at google - send to devlin 2011/10/10 01:00:16 I think that observers_, core_, and registrar_ (fw
+ std::map<Profile*, DefaultObserver*> profile_observers_;
+
+ // Ref-counted core.
scoped_refptr<Core> core_;
+ // Profile which owns the frontend.
+ Profile* profile_;
+
+ // For profile created/destroyed notifications.
+ NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend);
};

Powered by Google App Engine
This is Rietveld 408576698