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_SETTINGS_SETTINGS_FRONTEND_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/observer_list_threadsafe.h" | 15 #include "base/observer_list_threadsafe.h" |
16 #include "chrome/browser/extensions/settings/settings_leveldb_storage.h" | 16 #include "chrome/browser/extensions/settings/settings_leveldb_storage.h" |
| 17 #include "chrome/browser/extensions/settings/settings_namespace.h" |
17 #include "chrome/browser/extensions/settings/settings_observer.h" | 18 #include "chrome/browser/extensions/settings/settings_observer.h" |
18 #include "chrome/browser/sync/api/syncable_service.h" | 19 #include "chrome/browser/sync/api/syncable_service.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 | 22 |
22 class Profile; | 23 class Profile; |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 class SettingsStorage; | 27 class SettingsStorage; |
27 | 28 |
28 // The component of extension settings which runs on the UI thread, as opposed | 29 // The component of extension settings which runs on the UI thread, as opposed |
29 // to SettingsBackend which lives on the FILE thread. | 30 // to SettingsBackend which lives on the FILE thread. |
30 // All public methods must be called on the UI thread. | 31 // All public methods must be called on the UI thread. |
31 class SettingsFrontend { | 32 class SettingsFrontend { |
32 public: | 33 public: |
33 // Creates with the default factory. Ownership of |profile| not taken. | 34 // Creates with the default factory. Ownership of |profile| not taken. |
34 static SettingsFrontend* Create(Profile* profile); | 35 static SettingsFrontend* Create(Profile* profile); |
35 | 36 |
36 static SettingsFrontend* Create( | 37 static SettingsFrontend* Create( |
37 // Ownership taken. | 38 const scoped_refptr<SettingsStorageFactory>& storage_factory, |
38 SettingsStorageFactory* storage_factory, | |
39 // Owership NOT taken. | 39 // Owership NOT taken. |
40 Profile* profile); | 40 Profile* profile); |
41 | 41 |
42 virtual ~SettingsFrontend(); | 42 virtual ~SettingsFrontend(); |
43 | 43 |
44 typedef base::Callback<void(SyncableService*)> SyncableServiceCallback; | 44 typedef base::Callback<void(SyncableService*)> SyncableServiceCallback; |
45 typedef base::Callback<void(SettingsStorage*)> StorageCallback; | 45 typedef base::Callback<void(SettingsStorage*)> StorageCallback; |
46 | 46 |
47 // Runs |callback| on the FILE thread with the SyncableService for | 47 // Runs |callback| on the FILE thread with the SyncableService for |
48 // |model_type|, either SETTINGS or APP_SETTINGS. | 48 // |model_type|, either SETTINGS or APP_SETTINGS. |
49 void RunWithSyncableService( | 49 void RunWithSyncableService( |
50 syncable::ModelType model_type, const SyncableServiceCallback& callback); | 50 syncable::ModelType model_type, const SyncableServiceCallback& callback); |
51 | 51 |
52 // Runs |callback| on the FILE thread with the storage area for | 52 // Runs |callback| on the FILE thread with the storage area for |
53 // |extension_id|. If there is no extension with that ID, the storage area | 53 // |extension_id|. If there is no extension with that ID, the storage area |
54 // will be NULL. | 54 // will be NULL. |
55 void RunWithStorage( | 55 void RunWithStorage( |
56 const std::string& extension_id, const StorageCallback& callback); | 56 const std::string& extension_id, |
| 57 settings_namespace::Namespace settings_namespace, |
| 58 const StorageCallback& callback); |
57 | 59 |
58 // Deletes the settings for an extension (on the FILE thread). | 60 // Deletes the settings for an extension (on the FILE thread). |
59 void DeleteStorageSoon(const std::string& extension_id); | 61 void DeleteStorageSoon(const std::string& extension_id); |
60 | 62 |
61 // Gets the thread-safe observer list. | 63 // Gets the thread-safe observer list. |
62 scoped_refptr<SettingsObserverList> GetObservers(); | 64 scoped_refptr<SettingsObserverList> GetObservers(); |
63 | 65 |
64 private: | 66 private: |
65 // Settings change Observer which forwards changes on to the extension | |
66 // processes for |profile| and its incognito partner if it exists. | |
67 class DefaultObserver : public SettingsObserver { | |
68 public: | |
69 explicit DefaultObserver(Profile* profile); | |
70 virtual ~DefaultObserver(); | |
71 | |
72 // SettingsObserver implementation. | |
73 virtual void OnSettingsChanged( | |
74 const std::string& extension_id, | |
75 const std::string& change_json) OVERRIDE; | |
76 | |
77 private: | |
78 Profile* const profile_; | |
79 }; | |
80 | |
81 SettingsFrontend( | 67 SettingsFrontend( |
82 // Ownership taken. | 68 const scoped_refptr<SettingsStorageFactory>& storage_factory, |
83 SettingsStorageFactory* storage_factory, | |
84 // Ownership NOT taken. | 69 // Ownership NOT taken. |
85 Profile* profile); | 70 Profile* profile); |
86 | 71 |
87 // The (non-incognito) Profile this Frontend belongs to. | 72 // The (non-incognito) Profile this Frontend belongs to. |
88 Profile* const profile_; | 73 Profile* const profile_; |
89 | 74 |
90 // List of observers to settings changes. | 75 // List of observers to settings changes. |
91 scoped_refptr<SettingsObserverList> observers_; | 76 scoped_refptr<SettingsObserverList> observers_; |
92 | 77 |
93 // Observer for |profile_|. | 78 // Observer for |profile_|. |
94 DefaultObserver default_observer_; | 79 scoped_ptr<SettingsObserver> profile_observer_; |
95 | 80 |
96 // Ref-counted container for the SettingsBackend object. | 81 // Ref-counted container for each SettingsBackend object. There are 4: an |
97 class Core; | 82 // apps and an extensions Backend for the LOCAL namespace, and likewise for |
98 scoped_refptr<Core> core_; | 83 // the SYNC namespace. They only differ in what directory the database for |
| 84 // each exists in (and the Backends in the SYNC namespace happen to be |
| 85 // returned from RunWithSyncableService). |
| 86 class BackendWrapper; |
| 87 struct BackendWrappers { |
| 88 BackendWrappers(); |
| 89 ~BackendWrappers(); |
| 90 scoped_refptr<BackendWrapper> app; |
| 91 scoped_refptr<BackendWrapper> extension; |
| 92 }; |
| 93 std::map<settings_namespace::Namespace, BackendWrappers> backends_; |
99 | 94 |
100 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); | 95 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); |
101 }; | 96 }; |
102 | 97 |
103 } // namespace extensions | 98 } // namespace extensions |
104 | 99 |
105 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ |
OLD | NEW |