Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_API_STORAGE_SETTINGS_FRONTEND_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/extensions/api/storage/settings_observer.h" | 13 #include "chrome/browser/extensions/api/storage/settings_observer.h" |
| 14 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" | 14 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" |
| 15 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer. h" | |
| 16 #include "chrome/browser/extensions/api/storage/value_store_cache.h" | 15 #include "chrome/browser/extensions/api/storage/value_store_cache.h" |
| 17 #include "extensions/browser/api/storage/settings_namespace.h" | 16 #include "extensions/browser/api/storage/settings_namespace.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 19 #include "sync/api/syncable_service.h" | |
| 20 | 18 |
| 21 namespace content { | 19 namespace content { |
| 22 class BrowserContext; | 20 class BrowserContext; |
| 23 } | 21 } |
| 24 | 22 |
| 25 namespace extensions { | 23 namespace extensions { |
| 26 | 24 |
| 27 // The component of extension settings which runs on the UI thread, as opposed | 25 // The component of extension settings which runs on the UI thread, as opposed |
| 28 // to SettingsBackend which lives on the FILE thread. | 26 // to SettingsBackend which lives on the FILE thread. |
| 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. | |
| 31 class SettingsFrontend : public BrowserContextKeyedAPI { | 27 class SettingsFrontend : public BrowserContextKeyedAPI { |
| 32 public: | 28 public: |
| 33 // Returns the current instance for |context|. | 29 // Returns the current instance for |context|. |
| 34 static SettingsFrontend* Get(content::BrowserContext* context); | 30 static SettingsFrontend* Get(content::BrowserContext* context); |
| 35 | 31 |
| 36 // Creates with a specific |storage_factory|. Caller owns the object. | 32 // Creates with a specific |storage_factory|. Caller owns the object. |
| 37 static SettingsFrontend* CreateForTesting( | 33 static SettingsFrontend* CreateForTesting( |
| 38 const scoped_refptr<SettingsStorageFactory>& storage_factory, | 34 const scoped_refptr<SettingsStorageFactory>& storage_factory, |
| 39 content::BrowserContext* context); | 35 content::BrowserContext* context); |
| 40 | 36 |
| 41 // Public so tests can create and delete their own instances. | 37 // Public so tests can create and delete their own instances. |
| 42 virtual ~SettingsFrontend(); | 38 virtual ~SettingsFrontend(); |
| 43 | 39 |
| 44 // Must only be called from the FILE thread. |type| should be either | 40 // Returns the value store cache for |settings_namespace|. |
| 45 // APP_SETTINGS or EXTENSION_SETTINGS. | 41 ValueStoreCache* GetValueStoreCache( |
| 46 syncer::SyncableService* GetBackendForSync(syncer::ModelType type) const; | 42 settings_namespace::Namespace settings_namespace) const; |
| 47 | 43 |
| 48 // Returns true if |settings_namespace| is a valid namespace. | 44 // Returns true if |settings_namespace| is a valid namespace. |
| 49 bool IsStorageEnabled(settings_namespace::Namespace settings_namespace) const; | 45 bool IsStorageEnabled(settings_namespace::Namespace settings_namespace) const; |
| 50 | 46 |
| 51 // Runs |callback| with the storage area of the given |settings_namespace| | 47 // Runs |callback| with the storage area of the given |settings_namespace| |
| 52 // for the |extension|. | 48 // for the |extension|. |
| 53 void RunWithStorage(scoped_refptr<const Extension> extension, | 49 void RunWithStorage(scoped_refptr<const Extension> extension, |
| 54 settings_namespace::Namespace settings_namespace, | 50 settings_namespace::Namespace settings_namespace, |
| 55 const ValueStoreCache::StorageCallback& callback); | 51 const ValueStoreCache::StorageCallback& callback); |
| 56 | 52 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 76 | 72 |
| 77 // Constructor for normal BrowserContextKeyedAPI usage. | 73 // Constructor for normal BrowserContextKeyedAPI usage. |
| 78 explicit SettingsFrontend(content::BrowserContext* context); | 74 explicit SettingsFrontend(content::BrowserContext* context); |
| 79 | 75 |
| 80 // Constructor for tests. | 76 // Constructor for tests. |
| 81 SettingsFrontend(const scoped_refptr<SettingsStorageFactory>& storage_factory, | 77 SettingsFrontend(const scoped_refptr<SettingsStorageFactory>& storage_factory, |
| 82 content::BrowserContext* context); | 78 content::BrowserContext* context); |
| 83 | 79 |
| 84 void Init(const scoped_refptr<SettingsStorageFactory>& storage_factory); | 80 void Init(const scoped_refptr<SettingsStorageFactory>& storage_factory); |
| 85 | 81 |
| 86 // The quota limit configurations for the local and sync areas, taken out of | |
| 87 // the schema in chrome/common/extensions/api/storage.json. | |
| 88 const SettingsStorageQuotaEnforcer::Limits local_quota_limit_; | |
|
James Cook
2014/03/05 18:37:39
These were only used to init value store caches. I
| |
| 89 const SettingsStorageQuotaEnforcer::Limits sync_quota_limit_; | |
| 90 | |
| 91 // The (non-incognito) browser context this Frontend belongs to. | 82 // The (non-incognito) browser context this Frontend belongs to. |
| 92 content::BrowserContext* const browser_context_; | 83 content::BrowserContext* const browser_context_; |
| 93 | 84 |
| 94 // List of observers to settings changes. | 85 // List of observers to settings changes. |
| 95 scoped_refptr<SettingsObserverList> observers_; | 86 scoped_refptr<SettingsObserverList> observers_; |
| 96 | 87 |
| 97 // Observer for |browser_context_|. | 88 // Observer for |browser_context_|. |
| 98 scoped_ptr<SettingsObserver> browser_context_observer_; | 89 scoped_ptr<SettingsObserver> browser_context_observer_; |
| 99 | 90 |
| 100 // Maps a known namespace to its corresponding ValueStoreCache. The caches | 91 // Maps a known namespace to its corresponding ValueStoreCache. The caches |
| 101 // are owned by this object. | 92 // are owned by this object. |
| 102 CacheMap caches_; | 93 CacheMap caches_; |
| 103 | 94 |
| 104 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); | 95 DISALLOW_COPY_AND_ASSIGN(SettingsFrontend); |
| 105 }; | 96 }; |
| 106 | 97 |
| 107 } // namespace extensions | 98 } // namespace extensions |
| 108 | 99 |
| 109 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_FRONTEND_H_ |
| OLD | NEW |