| 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" |
| 11 #include "base/memory/linked_ptr.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/callback.h" | 13 #include "base/observer_list_threadsafe.h" |
| 14 #include "chrome/browser/extensions/extension_settings_observer.h" |
| 12 #include "chrome/browser/sync/api/syncable_service.h" | 15 #include "chrome/browser/sync/api/syncable_service.h" |
| 16 #include "content/common/notification_observer.h" |
| 17 #include "content/common/notification_registrar.h" |
| 13 | 18 |
| 14 class FilePath; | 19 class FilePath; |
| 20 class Profile; |
| 15 class ExtensionSettingsBackend; | 21 class ExtensionSettingsBackend; |
| 16 class ExtensionSettingsStorage; | 22 class ExtensionSettingsStorage; |
| 17 | 23 |
| 18 // The component of extension settings which runs on the UI thread, as opposed | 24 // The component of extension settings which runs on the UI thread, as opposed |
| 19 // to ExtensionSettingsBackend which lives on the FILE thread. | 25 // to ExtensionSettingsBackend which lives on the FILE thread. |
| 20 class ExtensionSettingsFrontend { | 26 class ExtensionSettingsFrontend : public NotificationObserver { |
| 21 public: | 27 public: |
| 22 explicit ExtensionSettingsFrontend(const FilePath& base_path); | 28 explicit ExtensionSettingsFrontend(Profile* profile); |
| 29 virtual ~ExtensionSettingsFrontend(); |
| 23 | 30 |
| 24 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback; | 31 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback; |
| 25 | 32 |
| 26 // Runs |callback| on the FILE thread with the extension settings. | 33 // Runs |callback| on the FILE thread with the extension settings. |
| 27 void RunWithBackend(const BackendCallback& callback); | 34 void RunWithBackend(const BackendCallback& callback); |
| 28 | 35 |
| 29 ~ExtensionSettingsFrontend(); | 36 // Adds an observer to settings changes. |
| 37 void AddObserver(ExtensionSettingsObserver* observer); |
| 38 |
| 39 // Removes an observer to settings changes. |
| 40 void RemoveObserver(ExtensionSettingsObserver* observer); |
| 41 |
| 42 // NotificationObserver implementation. |
| 43 virtual void Observe( |
| 44 int type, |
| 45 const NotificationSource& source, |
| 46 const NotificationDetails& details) OVERRIDE; |
| 30 | 47 |
| 31 private: | 48 private: |
| 49 // Called when a profile is created. |
| 50 void OnProfileCreated(Profile* profile); |
| 51 |
| 52 // Called when a profile is destroyed. |
| 53 void OnProfileDestroyed(Profile* profile); |
| 54 |
| 55 // List of observers to settings changes. |
| 56 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_; |
| 57 |
| 58 // Map of Profiles to their Observers. This is so that when Profiles are |
| 59 // destroyed we can remove the associated Observer. |
| 60 // MUST ONLY BE ACCESSED ON THE UI THREAD. |
| 61 class DefaultObserver; |
| 62 std::map<Profile*, linked_ptr<DefaultObserver> > profile_observers_; |
| 63 |
| 32 // Ref-counted container for the ExtensionSettingsBackend object. | 64 // Ref-counted container for the ExtensionSettingsBackend object. |
| 33 class Core : public base::RefCountedThreadSafe<Core> { | 65 class Core; |
| 34 public: | 66 scoped_refptr<Core> core_; |
| 35 // Constructed on UI thread. | |
| 36 Core(); | |
| 37 | 67 |
| 38 // Does any FILE thread specific initialization, such as construction of | 68 // For profile created/destroyed notifications. |
| 39 // |backend_|. Must be called before any call to | 69 NotificationRegistrar registrar_; |
| 40 // RunWithBackendOnFileThread(). | |
| 41 void InitOnFileThread(const FilePath& base_path); | |
| 42 | |
| 43 // Runs |callback| with the extension backend. | |
| 44 void RunWithBackendOnFileThread(const BackendCallback& callback); | |
| 45 | |
| 46 private: | |
| 47 // Can be destroyed on either the UI or FILE thread. | |
| 48 virtual ~Core(); | |
| 49 friend class base::RefCountedThreadSafe<Core>; | |
| 50 | |
| 51 // Lives on the FILE thread. | |
| 52 ExtensionSettingsBackend* backend_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(Core); | |
| 55 }; | |
| 56 | |
| 57 scoped_refptr<Core> core_; | |
| 58 | 70 |
| 59 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); | 71 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); |
| 60 }; | 72 }; |
| 61 | 73 |
| 62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ |
| OLD | NEW |