OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | |
14 #include "chrome/browser/extensions/api/storage/settings_observer.h" | |
15 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" | |
16 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.
h" | |
17 #include "chrome/browser/extensions/api/storage/value_store_cache.h" | |
18 #include "sync/api/syncable_service.h" | |
19 | |
20 class Profile; | |
21 | |
22 namespace extensions { | |
23 | |
24 // The component of extension settings which runs on the UI thread, as opposed | |
25 // to SettingsBackend which lives on the FILE thread. | |
26 // All public methods, must be called on the UI thread, with the exception of | |
27 // GetBackendForSync(), which must be called on the FILE thread. | |
28 class SettingsFrontend { | |
29 public: | |
30 // Creates with the default factory. | |
31 static SettingsFrontend* Create(Profile* profile); | |
32 | |
33 // Creates with a specific factory |storage_factory| (presumably for tests). | |
34 static SettingsFrontend* Create( | |
35 const scoped_refptr<SettingsStorageFactory>& storage_factory, | |
36 Profile* profile); | |
37 | |
38 virtual ~SettingsFrontend(); | |
39 | |
40 // Must only be called from the FILE thread. |type| should be either | |
41 // APP_SETTINGS or EXTENSION_SETTINGS. | |
42 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const; | |
43 | |
44 // Returns true if |settings_namespace| is a valid namespace. | |
45 bool IsStorageEnabled(settings_namespace::Namespace settings_namespace) const; | |
46 | |
47 // Runs |callback| with the storage area of the given |settings_namespace| | |
48 // for the |extension_id|. | |
49 void RunWithStorage( | |
50 const std::string& extension_id, | |
51 settings_namespace::Namespace settings_namespace, | |
52 const ValueStoreCache::StorageCallback& callback); | |
53 | |
54 // Deletes the settings for the given |extension_id|. | |
55 void DeleteStorageSoon(const std::string& extension_id); | |
56 | |
57 // Gets the thread-safe observer list. | |
58 scoped_refptr<SettingsObserverList> GetObservers(); | |
59 | |
60 void DisableStorageForTesting( | |
61 settings_namespace::Namespace settings_namespace); | |
62 | |
63 private: | |
64 typedef std::map<settings_namespace::Namespace, ValueStoreCache*> CacheMap; | |
65 | |
66 SettingsFrontend( | |
67 const scoped_refptr<SettingsStorageFactory>& storage_factory, | |
68 Profile* profile); | |
69 | |
70 // The quota limit configurations for the local and sync areas, taken out of | |
71 // the schema in chrome/common/extensions/api/storage.json. | |
72 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_; | |
73 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_; | |
74 | |
75 // The (non-incognito) Profile this Frontend belongs to. | |
76 Profile* const profile_; | |
77 | |
78 // List of observers to settings changes. | |
79 scoped_refptr<SettingsObserverList> observers_; | |
80 | |
81 // Observer for |profile_|. | |
82 scoped_ptr<SettingsObserver> profile_observer_; | |
83 | |
84 // Maps a known namespace to its corresponding ValueStoreCache. The caches | |
85 // are owned by this object. | |
86 CacheMap caches_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); | |
89 }; | |
90 | |
91 } // namespace extensions | |
92 | |
93 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ | |
OLD | NEW |