| 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_BACKEND_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_BACKEND_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.
h" | |
| 14 | |
| 15 namespace syncer { | |
| 16 class SyncableService; | |
| 17 } | |
| 18 | |
| 19 class ValueStore; | |
| 20 | |
| 21 namespace extensions { | |
| 22 class SettingsStorageFactory; | |
| 23 | |
| 24 // Performs work for the storage API on the FILE thread. | |
| 25 class SettingsBackend { | |
| 26 public: | |
| 27 SettingsBackend(const scoped_refptr<SettingsStorageFactory>& storage_factory, | |
| 28 const base::FilePath& base_path, | |
| 29 const SettingsStorageQuotaEnforcer::Limits& quota); | |
| 30 virtual ~SettingsBackend(); | |
| 31 | |
| 32 // Gets a weak reference to the storage area for |extension_id|. | |
| 33 // Must be run on the FILE thread. | |
| 34 virtual ValueStore* GetStorage(const std::string& extension_id) = 0; | |
| 35 | |
| 36 // Deletes all setting data for an extension. Call on the FILE thread. | |
| 37 virtual void DeleteStorage(const std::string& extension_id) = 0; | |
| 38 | |
| 39 // A slight hack so we can get a SyncableService from a SettingsBackend if | |
| 40 // it's actually a SyncStorageBackend. If called on a LocalStorageBackend, | |
| 41 // this asserts and returns null. | |
| 42 virtual syncer::SyncableService* GetAsSyncableService(); | |
| 43 | |
| 44 SettingsStorageFactory* storage_factory() const { | |
| 45 return storage_factory_.get(); | |
| 46 } | |
| 47 const base::FilePath& base_path() const { return base_path_; } | |
| 48 const SettingsStorageQuotaEnforcer::Limits& quota() const { return quota_; } | |
| 49 | |
| 50 protected: | |
| 51 // Creates a ValueStore decorated with quota-enforcing behavior (the default | |
| 52 // for both sync and local stores). If the database is corrupt, | |
| 53 // SettingsStorageQuotaEnforcer will try and restore it as part of the | |
| 54 // initialization process (by necessity, since we need to read the database to | |
| 55 // calculate the storage). | |
| 56 scoped_ptr<SettingsStorageQuotaEnforcer> CreateStorageForExtension( | |
| 57 const std::string& extension_id) const; | |
| 58 | |
| 59 private: | |
| 60 // The Factory to use for creating new ValueStores. | |
| 61 const scoped_refptr<SettingsStorageFactory> storage_factory_; | |
| 62 | |
| 63 // The base file path to use when creating new ValueStores. | |
| 64 const base::FilePath base_path_; | |
| 65 | |
| 66 // Quota limits (see SettingsStorageQuotaEnforcer). | |
| 67 const SettingsStorageQuotaEnforcer::Limits quota_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(SettingsBackend); | |
| 70 }; | |
| 71 | |
| 72 } // namespace extensions | |
| 73 | |
| 74 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SETTINGS_BACKEND_H_ | |
| OLD | NEW |