12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_POLICY_VALUE_STORE_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_STORAGE_POLICY_VALUE_STORE_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "extensions/browser/api/storage/settings_observer.h" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "extensions/browser/value_store/value_store.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace policy { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PolicyMap; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace extensions { 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A ValueStore that is backed by another, persistent ValueStore, and stores 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the policies for a specific extension there. This ValueStore is used to 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// run the function of the storage.managed namespace; it's read-only for the 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// extension. The ManagedValueStoreCache sends updated policy to this store 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// and manages its lifetime. 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PolicyValueStore : public ValueStore { 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PolicyValueStore(const std::string& extension_id, 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const scoped_refptr<SettingsObserverList>& observers, 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ValueStore> delegate); 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~PolicyValueStore(); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Stores |policy| in the persistent database represented by the |delegate_| 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // and notifies observers with the changes from the previous policy. 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void SetCurrentPolicy(const policy::PolicyMap& policy); 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Clears all the stored data and deletes the database. 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DeleteStorage(); 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ValueStore implementation: 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual size_t GetBytesInUse(const std::string& key) OVERRIDE; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE; 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual size_t GetBytesInUse() OVERRIDE; 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReadResult Get(const std::string& key) OVERRIDE; 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReadResult Get() OVERRIDE; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual WriteResult Set( 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WriteOptions options, 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& key, 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::Value& value) OVERRIDE; 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual WriteResult Set( 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WriteOptions options, const base::DictionaryValue& values) OVERRIDE; 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual WriteResult Remove(const std::string& key) OVERRIDE; 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual WriteResult Clear() OVERRIDE; 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Hopefully, as a Read-Only database, there is no reason to use these. 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool Restore() OVERRIDE; 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool RestoreKey(const std::string& key) OVERRIDE; 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // For unit tests. 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ValueStore* delegate() { return delegate_.get(); } 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string extension_id_; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<SettingsObserverList> observers_; 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ValueStore> delegate_; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PolicyValueStore); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace extensions 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_POLICY_VALUE_STORE_H_ 76