Home | History | Annotate | Download | only in storage
      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_SYNC_OR_LOCAL_VALUE_STORE_CACHE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_OR_LOCAL_VALUE_STORE_CACHE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "chrome/browser/extensions/api/storage/settings_observer.h"
     13 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.h"
     14 #include "chrome/browser/extensions/api/storage/value_store_cache.h"
     15 
     16 namespace base {
     17 class FilePath;
     18 }
     19 
     20 namespace extensions {
     21 
     22 class SettingsBackend;
     23 class SettingsStorageFactory;
     24 
     25 // ValueStoreCache for the LOCAL and SYNC namespaces. It owns a backend for
     26 // apps and another for extensions. Each backend takes care of persistence and
     27 // syncing.
     28 class SyncOrLocalValueStoreCache : public ValueStoreCache {
     29  public:
     30   SyncOrLocalValueStoreCache(
     31       settings_namespace::Namespace settings_namespace,
     32       const scoped_refptr<SettingsStorageFactory>& factory,
     33       const SettingsStorageQuotaEnforcer::Limits& quota,
     34       const scoped_refptr<SettingsObserverList>& observers,
     35       const base::FilePath& profile_path);
     36   virtual ~SyncOrLocalValueStoreCache();
     37 
     38   SettingsBackend* GetAppBackend() const;
     39   SettingsBackend* GetExtensionBackend() const;
     40 
     41   // ValueStoreCache implementation:
     42 
     43   virtual void RunWithValueStoreForExtension(
     44       const StorageCallback& callback,
     45       scoped_refptr<const Extension> extension) OVERRIDE;
     46 
     47   virtual void DeleteStorageSoon(const std::string& extension_id) OVERRIDE;
     48 
     49  private:
     50   void InitOnFileThread(const scoped_refptr<SettingsStorageFactory>& factory,
     51                         const SettingsStorageQuotaEnforcer::Limits& quota,
     52                         const scoped_refptr<SettingsObserverList>& observers,
     53                         const base::FilePath& profile_path);
     54 
     55   settings_namespace::Namespace settings_namespace_;
     56   scoped_ptr<SettingsBackend> app_backend_;
     57   scoped_ptr<SettingsBackend> extension_backend_;
     58 
     59   DISALLOW_COPY_AND_ASSIGN(SyncOrLocalValueStoreCache);
     60 };
     61 
     62 }  // namespace extensions
     63 
     64 #endif  // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_OR_LOCAL_VALUE_STORE_CACHE_H_
     65