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

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: Added comment 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_observer.h" 16 #include "chrome/browser/extensions/settings/settings_observer.h"
17 #include "chrome/browser/extensions/settings/settings_storage_factory.h" 17 #include "chrome/browser/extensions/settings/settings_storage_factory.h"
18 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" 18 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h"
19 #include "chrome/browser/value_store/leveldb_value_store.h" 19 #include "chrome/browser/extensions/settings/value_store_cache.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 // The component of extension settings which runs on the UI thread, as opposed 27 // The component of extension settings which runs on the UI thread, as opposed
28 // to SettingsBackend which lives on the FILE thread. 28 // to SettingsBackend which lives on the FILE thread.
29 // All public methods, must be called on the UI thread, with the exception of 29 // All public methods, must be called on the UI thread, with the exception of
30 // GetBackendForSync(), which must be called on the FILE thread. 30 // GetBackendForSync(), which must be called on the FILE thread.
31 class SettingsFrontend { 31 class SettingsFrontend {
32 public: 32 public:
33 // Creates with the default factory. Ownership of |profile| not taken. 33 // Creates with the default factory.
34 static SettingsFrontend* Create(Profile* profile); 34 static SettingsFrontend* Create(Profile* profile);
35 35
36 // Creates with a specific factory |storage_factory| (presumably for tests). 36 // Creates with a specific factory |storage_factory| (presumably for tests).
37 // Ownership of |profile| not taken.
38 static SettingsFrontend* Create( 37 static SettingsFrontend* Create(
39 const scoped_refptr<SettingsStorageFactory>& storage_factory, 38 const scoped_refptr<SettingsStorageFactory>& storage_factory,
40 // Owership NOT taken.
41 Profile* profile); 39 Profile* profile);
42 40
43 virtual ~SettingsFrontend(); 41 virtual ~SettingsFrontend();
44 42
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 43 // Must only be called from the FILE thread. |type| should be either
50 // APP_SETTINGS or EXTENSION_SETTINGS. 44 // APP_SETTINGS or EXTENSION_SETTINGS.
51 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const; 45 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const;
52 46
53 // Runs |callback| on the FILE thread with the storage area for 47 // 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 48 // for the |extension_id|. If there is no extension with that ID, the storage
55 // will be NULL. 49 // area will be NULL.
56 void RunWithStorage( 50 void RunWithStorage(
57 const std::string& extension_id, 51 const std::string& extension_id,
58 settings_namespace::Namespace settings_namespace, 52 settings_namespace::Namespace settings_namespace,
59 const StorageCallback& callback); 53 const ValueStoreCache::StorageCallback& callback);
60 54
61 // Deletes the settings for an extension (on the FILE thread). 55 // Deletes the settings for the given |extension_id|.
62 void DeleteStorageSoon(const std::string& extension_id); 56 void DeleteStorageSoon(const std::string& extension_id);
63 57
64 // Gets the thread-safe observer list. 58 // Gets the thread-safe observer list.
65 scoped_refptr<SettingsObserverList> GetObservers(); 59 scoped_refptr<SettingsObserverList> GetObservers();
66 60
67 private: 61 private:
62 typedef std::map<settings_namespace::Namespace, ValueStoreCache*> CacheMap;
63
68 SettingsFrontend( 64 SettingsFrontend(
69 const scoped_refptr<SettingsStorageFactory>& storage_factory, 65 const scoped_refptr<SettingsStorageFactory>& storage_factory,
70 // Ownership NOT taken.
71 Profile* profile); 66 Profile* profile);
72 67
73 // The quota limit configurations for the local and sync areas, taken out of 68 // The quota limit configurations for the local and sync areas, taken out of
74 // the schema in chrome/common/extensions/api/storage.json. 69 // the schema in chrome/common/extensions/api/storage.json.
75 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_; 70 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_;
76 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_; 71 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_;
77 72
78 // The (non-incognito) Profile this Frontend belongs to. 73 // The (non-incognito) Profile this Frontend belongs to.
79 Profile* const profile_; 74 Profile* const profile_;
80 75
81 // List of observers to settings changes. 76 // List of observers to settings changes.
82 scoped_refptr<SettingsObserverList> observers_; 77 scoped_refptr<SettingsObserverList> observers_;
83 78
84 // Observer for |profile_|. 79 // Observer for |profile_|.
85 scoped_ptr<SettingsObserver> profile_observer_; 80 scoped_ptr<SettingsObserver> profile_observer_;
86 81
87 // Ref-counted container for each SettingsBackend object. There are 4: an 82 // Maps a known namespace to its corresponding ValueStoreCache. The caches
88 // apps and an extensions Backend for the LOCAL namespace, and likewise for 83 // are owned by this object.
89 // the SYNC namespace. They only differ in what directory the database for 84 CacheMap caches_;
90 // each exists in.
91 class BackendWrapper;
92 struct BackendWrappers {
93 BackendWrappers();
94 ~BackendWrappers();
95 scoped_refptr<BackendWrapper> app;
96 scoped_refptr<BackendWrapper> extension;
97 };
98 std::map<settings_namespace::Namespace, BackendWrappers> backends_;
99 85
100 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); 86 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend);
101 }; 87 };
102 88
103 } // namespace extensions 89 } // namespace extensions
104 90
105 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_ 91 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_FRONTEND_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_api.cc ('k') | chrome/browser/extensions/settings/settings_frontend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698