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

Side by Side Diff: chrome/browser/extensions/settings/settings_frontend.h

Issue 10784035: Refactored SettingsFrontend and forwarding of calls to the backends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list_threadsafe.h" 14 #include "base/observer_list_threadsafe.h"
15 #include "chrome/browser/extensions/settings/settings_namespace.h" 15 #include "chrome/browser/extensions/settings/settings_namespace.h"
16 #include "chrome/browser/extensions/settings/settings_namespace_frontend.h"
16 #include "chrome/browser/extensions/settings/settings_observer.h" 17 #include "chrome/browser/extensions/settings/settings_observer.h"
17 #include "chrome/browser/extensions/settings/settings_storage_factory.h" 18 #include "chrome/browser/extensions/settings/settings_storage_factory.h"
18 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" 19 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h"
19 #include "chrome/browser/value_store/leveldb_value_store.h"
20 #include "sync/api/syncable_service.h" 20 #include "sync/api/syncable_service.h"
21 21
22 class Profile; 22 class Profile;
23 class ValueStore; 23 class ValueStore;
24 24
25 namespace extensions { 25 namespace extensions {
26 26
27 class SettingsStorageFrontend;
28
27 // 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
28 // to SettingsBackend which lives on the FILE thread. 30 // to SettingsBackend which lives on the FILE thread.
29 // All public methods, must be called on the UI thread, with the exception of 31 // All public methods, must be called on the UI thread, with the exception of
30 // GetBackendForSync(), which must be called on the FILE thread. 32 // GetBackendForSync(), which must be called on the FILE thread.
31 class SettingsFrontend { 33 class SettingsFrontend {
32 public: 34 public:
33 // Creates with the default factory. Ownership of |profile| not taken. 35 // Creates with the default factory. Ownership of |profile| not taken.
34 static SettingsFrontend* Create(Profile* profile); 36 static SettingsFrontend* Create(Profile* profile);
35 37
36 // Creates with a specific factory |storage_factory| (presumably for tests). 38 // Creates with a specific factory |storage_factory| (presumably for tests).
37 // Ownership of |profile| not taken. 39 // Ownership of |profile| not taken.
38 static SettingsFrontend* Create( 40 static SettingsFrontend* Create(
39 const scoped_refptr<SettingsStorageFactory>& storage_factory, 41 const scoped_refptr<SettingsStorageFactory>& storage_factory,
40 // Owership NOT taken. 42 // Ownership NOT taken.
not at google - send to devlin 2012/07/18 07:46:18 probably an unnecessary comment in the first place
Joao da Silva 2012/07/18 21:40:25 Removed these comments.
41 Profile* profile); 43 Profile* profile);
42 44
43 virtual ~SettingsFrontend(); 45 virtual ~SettingsFrontend();
44 46
45 typedef base::Callback<void(syncer::SyncableService*)>
46 SyncableServiceCallback;
47 typedef base::Callback<void(ValueStore*)> StorageCallback;
48
49 // Must only be called from the FILE thread. |type| should be either 47 // Must only be called from the FILE thread. |type| should be either
50 // APP_SETTINGS or EXTENSION_SETTINGS. 48 // APP_SETTINGS or EXTENSION_SETTINGS.
51 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const; 49 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const;
52 50
53 // Runs |callback| on the FILE thread with the storage area for 51 // Runs |callback| with the storage area of the given |settings_namespace|
54 // |extension_id|. If there is no extension with that ID, the storage area 52 // for the |extension_id|. If there is no extension with that ID, the storage
55 // will be NULL. 53 // area will be NULL.
56 void RunWithStorage( 54 void RunWithStorage(
57 const std::string& extension_id, 55 const std::string& extension_id,
58 settings_namespace::Namespace settings_namespace, 56 settings_namespace::Namespace settings_namespace,
59 const StorageCallback& callback); 57 const SettingsNamespaceFrontend::StorageCallback& callback);
60 58
61 // Deletes the settings for an extension (on the FILE thread). 59 // Deletes the settings for the given |extension_id|.
62 void DeleteStorageSoon(const std::string& extension_id); 60 void DeleteStorageSoon(const std::string& extension_id);
63 61
64 // Gets the thread-safe observer list. 62 // Gets the thread-safe observer list.
65 scoped_refptr<SettingsObserverList> GetObservers(); 63 scoped_refptr<SettingsObserverList> GetObservers();
66 64
67 private: 65 private:
66 typedef std::map<settings_namespace::Namespace, SettingsNamespaceFrontend*>
67 FrontendMap;
68
68 SettingsFrontend( 69 SettingsFrontend(
69 const scoped_refptr<SettingsStorageFactory>& storage_factory, 70 const scoped_refptr<SettingsStorageFactory>& storage_factory,
70 // Ownership NOT taken. 71 // Ownership NOT taken.
71 Profile* profile); 72 Profile* profile);
72 73
73 // The quota limit configurations for the local and sync areas, taken out of 74 // The quota limit configurations for the local and sync areas, taken out of
74 // the schema in chrome/common/extensions/api/storage.json. 75 // the schema in chrome/common/extensions/api/storage.json.
75 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_; 76 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_;
76 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_; 77 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_;
77 78
78 // The (non-incognito) Profile this Frontend belongs to. 79 // The (non-incognito) Profile this Frontend belongs to.
79 Profile* const profile_; 80 Profile* const profile_;
80 81
81 // List of observers to settings changes. 82 // List of observers to settings changes.
82 scoped_refptr<SettingsObserverList> observers_; 83 scoped_refptr<SettingsObserverList> observers_;
83 84
84 // Observer for |profile_|. 85 // Observer for |profile_|.
85 scoped_ptr<SettingsObserver> profile_observer_; 86 scoped_ptr<SettingsObserver> profile_observer_;
86 87
87 // Ref-counted container for each SettingsBackend object. There are 4: an 88 // Maps a known namespace to its corresponding frontend. The frontends are
88 // apps and an extensions Backend for the LOCAL namespace, and likewise for 89 // owned by this object.
89 // the SYNC namespace. They only differ in what directory the database for 90 FrontendMap frontends_;
90 // each exists in. 91
91 class BackendWrapper; 92 // Points to the 'sync' namespace frontend using its specific type, so that
92 struct BackendWrappers { 93 // its backends can be retrieved by GetBackendForSync().
93 BackendWrappers(); 94 SettingsStorageFrontend* sync_frontend_;
94 ~BackendWrappers();
95 scoped_refptr<BackendWrapper> app;
96 scoped_refptr<BackendWrapper> extension;
97 };
98 std::map<settings_namespace::Namespace, BackendWrappers> backends_;
99 95
100 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); 96 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend);
101 }; 97 };
102 98
103 } // namespace extensions 99 } // namespace extensions
104 100
105 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ 101 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698