Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / storage / managed_value_store_cache.h
bloba4202be76ae73f45e84220e2f72a3aaaa8b264ab
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_MANAGED_VALUE_STORE_CACHE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_MANAGED_VALUE_STORE_CACHE_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "components/policy/core/common/policy_service.h"
18 #include "extensions/browser/api/storage/settings_observer.h"
19 #include "extensions/browser/api/storage/value_store_cache.h"
21 class Profile;
23 namespace content {
24 class BrowserContext;
27 namespace policy {
28 class PolicyMap;
31 namespace extensions {
33 class PolicyValueStore;
34 class SettingsStorageFactory;
36 // A ValueStoreCache that manages a PolicyValueStore for each extension that
37 // uses the storage.managed namespace. This class observes policy changes and
38 // which extensions listen for storage.onChanged(), and sends the appropriate
39 // updates to the corresponding PolicyValueStore on the FILE thread.
40 class ManagedValueStoreCache : public ValueStoreCache,
41 public policy::PolicyService::Observer {
42 public:
43 // |factory| is used to create databases for the PolicyValueStores.
44 // |observers| is the list of SettingsObservers to notify when a ValueStore
45 // changes.
46 ManagedValueStoreCache(content::BrowserContext* context,
47 const scoped_refptr<SettingsStorageFactory>& factory,
48 const scoped_refptr<SettingsObserverList>& observers);
49 ~ManagedValueStoreCache() override;
51 private:
52 class ExtensionTracker;
54 // Maps an extension ID to its PolicyValueStoreMap.
55 typedef std::map<std::string, linked_ptr<PolicyValueStore> >
56 PolicyValueStoreMap;
58 // ValueStoreCache implementation:
59 void ShutdownOnUI() override;
60 void RunWithValueStoreForExtension(
61 const StorageCallback& callback,
62 scoped_refptr<const Extension> extension) override;
63 void DeleteStorageSoon(const std::string& extension_id) override;
65 // PolicyService::Observer implementation:
66 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override;
67 void OnPolicyUpdated(const policy::PolicyNamespace& ns,
68 const policy::PolicyMap& previous,
69 const policy::PolicyMap& current) override;
71 // Posted by OnPolicyUpdated() to update a PolicyValueStore on the FILE
72 // thread.
73 void UpdatePolicyOnFILE(const std::string& extension_id,
74 scoped_ptr<policy::PolicyMap> current_policy);
76 // Returns an existing PolicyValueStore for |extension_id|, or NULL.
77 PolicyValueStore* GetStoreFor(const std::string& extension_id);
79 // Returns true if a backing store has been created for |extension_id|.
80 bool HasStore(const std::string& extension_id) const;
82 // The profile that owns the extension system being used. This is used to
83 // get the PolicyService, the EventRouter and the ExtensionService.
84 Profile* profile_;
86 // The |profile_|'s PolicyService.
87 policy::PolicyService* policy_service_;
89 // Observes extension loading and unloading, and keeps the Profile's
90 // PolicyService aware of the current list of extensions.
91 scoped_ptr<ExtensionTracker> extension_tracker_;
93 // These live on the FILE thread.
94 scoped_refptr<SettingsStorageFactory> storage_factory_;
95 scoped_refptr<SettingsObserverList> observers_;
96 base::FilePath base_path_;
98 // All the PolicyValueStores live on the FILE thread, and |store_map_| can be
99 // accessed only on the FILE thread as well.
100 PolicyValueStoreMap store_map_;
102 DISALLOW_COPY_AND_ASSIGN(ManagedValueStoreCache);
105 } // namespace extensions
107 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_MANAGED_VALUE_STORE_CACHE_H_