Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SETTINGS_FRONTEND_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback.h" | |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/callback.h" | 12 #include "base/observer_list_threadsafe.h" |
| 13 #include "chrome/browser/extensions/extension_settings_observer.h" | |
| 12 #include "chrome/browser/sync/api/syncable_service.h" | 14 #include "chrome/browser/sync/api/syncable_service.h" |
| 15 #include "content/common/notification_observer.h" | |
| 16 #include "content/common/notification_registrar.h" | |
| 13 | 17 |
| 14 class FilePath; | 18 class FilePath; |
| 19 class Profile; | |
| 15 class ExtensionSettingsBackend; | 20 class ExtensionSettingsBackend; |
| 16 class ExtensionSettingsStorage; | 21 class ExtensionSettingsStorage; |
| 17 | 22 |
| 18 // The component of extension settings which runs on the UI thread, as opposed | 23 // The component of extension settings which runs on the UI thread, as opposed |
| 19 // to ExtensionSettingsBackend which lives on the FILE thread. | 24 // to ExtensionSettingsBackend which lives on the FILE thread. |
| 20 class ExtensionSettingsFrontend { | 25 class ExtensionSettingsFrontend : public NotificationObserver { |
| 21 public: | 26 public: |
| 22 explicit ExtensionSettingsFrontend(const FilePath& base_path); | 27 explicit ExtensionSettingsFrontend(Profile* profile); |
| 28 virtual ~ExtensionSettingsFrontend(); | |
| 23 | 29 |
| 24 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback; | 30 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback; |
| 25 | 31 |
| 26 // Runs |callback| on the FILE thread with the extension settings. | 32 // Runs |callback| on the FILE thread with the extension settings. |
| 27 void RunWithBackend(const BackendCallback& callback); | 33 void RunWithBackend(const BackendCallback& callback); |
| 28 | 34 |
| 29 ~ExtensionSettingsFrontend(); | 35 // Adds an observer to settings changes. |
| 36 void AddObserver(ExtensionSettingsObserver* observer); | |
| 37 | |
| 38 // Removes an observer to settings changes. | |
| 39 void RemoveObserver(ExtensionSettingsObserver* observer); | |
| 40 | |
| 41 // Sends a change event to all settings change observer. |profile| is the | |
| 42 // profile that the change originated from. | |
| 43 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.
| |
| 44 Profile* profile, | |
| 45 const std::string& extension_id, | |
| 46 const ExtensionSettingsObserver::ChangeList& changes); | |
| 47 | |
| 48 // NotificationObserver implementation. | |
| 49 virtual void Observe( | |
| 50 int type, | |
| 51 const NotificationSource& source, | |
| 52 const NotificationDetails& details) OVERRIDE; | |
| 30 | 53 |
| 31 private: | 54 private: |
| 32 // Ref-counted container for the ExtensionSettingsBackend object. | 55 // Ref-counted container for the ExtensionSettingsBackend object. |
| 33 class Core : public base::RefCountedThreadSafe<Core> { | 56 class Core : public base::RefCountedThreadSafe<Core> { |
| 34 public: | 57 public: |
| 35 // Constructed on UI thread. | 58 // Constructed on UI thread. |
| 36 Core(); | 59 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.
| |
| 37 | 60 |
| 38 // Does any FILE thread specific initialization, such as construction of | 61 // Does any FILE thread specific initialization, such as construction of |
| 39 // |backend_|. Must be called before any call to | 62 // |backend_|. Must be called before any call to |
| 40 // RunWithBackendOnFileThread(). | 63 // RunWithBackendOnFileThread(). |
| 41 void InitOnFileThread(const FilePath& base_path); | 64 void InitOnFileThread(const FilePath& base_path); |
| 42 | 65 |
| 43 // Runs |callback| with the extension backend. | 66 // Runs |callback| with the extension backend. |
| 44 void RunWithBackendOnFileThread(const BackendCallback& callback); | 67 void RunWithBackendOnFileThread(const BackendCallback& callback); |
| 45 | 68 |
| 46 private: | 69 private: |
| 47 // Can be destroyed on either the UI or FILE thread. | 70 // Can be destroyed on either the UI or FILE thread. |
| 48 virtual ~Core(); | 71 virtual ~Core(); |
| 49 friend class base::RefCountedThreadSafe<Core>; | 72 friend class base::RefCountedThreadSafe<Core>; |
| 50 | 73 |
| 74 // Thread safe. | |
| 75 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > | |
| 76 observers_; | |
| 77 | |
| 51 // Lives on the FILE thread. | 78 // Lives on the FILE thread. |
| 52 ExtensionSettingsBackend* backend_; | 79 ExtensionSettingsBackend* backend_; |
| 53 | 80 |
| 54 DISALLOW_COPY_AND_ASSIGN(Core); | 81 DISALLOW_COPY_AND_ASSIGN(Core); |
| 55 }; | 82 }; |
| 56 | 83 |
| 84 // Observer which sends events to a target profile iff the profile isn't the | |
| 85 // originating profile for the event. | |
| 86 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.
| |
| 87 public: | |
| 88 explicit DefaultObserver(Profile* target_profile); | |
| 89 virtual ~DefaultObserver(); | |
| 90 | |
| 91 virtual void OnSettingsChanged( | |
| 92 Profile* origin_profile, | |
| 93 const std::string& extension_id, | |
| 94 const std::string& event_json) OVERRIDE; | |
| 95 | |
| 96 private: | |
| 97 Profile* target_profile_; | |
| 98 }; | |
| 99 | |
| 100 // Called when a profile is created. | |
| 101 void OnProfileCreated(Profile* profile); | |
| 102 | |
| 103 // Called when a profile is destroyed. | |
| 104 void OnProfileDestroyed(Profile* profile); | |
| 105 | |
| 106 // List of observers to settings changes. | |
| 107 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_; | |
| 108 | |
| 109 // Map of Profiles to their Observers. This is so that when Profiles are | |
| 110 // destroyed we can remove the associated Observer. | |
| 111 // 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
| |
| 112 std::map<Profile*, DefaultObserver*> profile_observers_; | |
| 113 | |
| 114 // Ref-counted core. | |
| 57 scoped_refptr<Core> core_; | 115 scoped_refptr<Core> core_; |
| 58 | 116 |
| 117 // Profile which owns the frontend. | |
| 118 Profile* profile_; | |
| 119 | |
| 120 // For profile created/destroyed notifications. | |
| 121 NotificationRegistrar registrar_; | |
| 122 | |
| 59 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); | 123 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); |
| 60 }; | 124 }; |
| 61 | 125 |
| 62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ | 126 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ |
| OLD | NEW |