Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/extensions/api/storage/managed_value_store_cache.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/extensions/api/storage/managed_value_store_cache.h" 5 #include "chrome/browser/extensions/api/storage/managed_value_store_cache.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 bool is_update, 84 bool is_update,
85 const std::string& old_name) override; 85 const std::string& old_name) override;
86 void OnExtensionUninstalled(content::BrowserContext* browser_context, 86 void OnExtensionUninstalled(content::BrowserContext* browser_context,
87 const Extension* extension, 87 const Extension* extension,
88 extensions::UninstallReason reason) override; 88 extensions::UninstallReason reason) override;
89 89
90 // Handler for the signal from ExtensionSystem::ready(). 90 // Handler for the signal from ExtensionSystem::ready().
91 void OnExtensionsReady(); 91 void OnExtensionsReady();
92 92
93 // Starts a schema load for all extensions that use managed storage. 93 // Starts a schema load for all extensions that use managed storage.
94 void LoadSchemas(scoped_ptr<ExtensionSet> added); 94 void LoadSchemas(std::unique_ptr<ExtensionSet> added);
95 95
96 bool UsesManagedStorage(const Extension* extension) const; 96 bool UsesManagedStorage(const Extension* extension) const;
97 97
98 // Loads the schemas of the |extensions| and passes a ComponentMap to 98 // Loads the schemas of the |extensions| and passes a ComponentMap to
99 // Register(). 99 // Register().
100 static void LoadSchemasOnBlockingPool(scoped_ptr<ExtensionSet> extensions, 100 static void LoadSchemasOnBlockingPool(
101 base::WeakPtr<ExtensionTracker> self); 101 std::unique_ptr<ExtensionSet> extensions,
102 base::WeakPtr<ExtensionTracker> self);
102 void Register(const policy::ComponentMap* components); 103 void Register(const policy::ComponentMap* components);
103 104
104 Profile* profile_; 105 Profile* profile_;
105 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 106 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
106 extension_registry_observer_; 107 extension_registry_observer_;
107 policy::SchemaRegistry* schema_registry_; 108 policy::SchemaRegistry* schema_registry_;
108 base::WeakPtrFactory<ExtensionTracker> weak_factory_; 109 base::WeakPtrFactory<ExtensionTracker> weak_factory_;
109 110
110 DISALLOW_COPY_AND_ASSIGN(ExtensionTracker); 111 DISALLOW_COPY_AND_ASSIGN(ExtensionTracker);
111 }; 112 };
(...skipping 16 matching lines...) Expand all
128 content::BrowserContext* browser_context, 129 content::BrowserContext* browser_context,
129 const Extension* extension, 130 const Extension* extension,
130 bool is_update, 131 bool is_update,
131 const std::string& old_name) { 132 const std::string& old_name) {
132 // Some extensions are installed on the first run before the ExtensionSystem 133 // Some extensions are installed on the first run before the ExtensionSystem
133 // becomes ready. Wait until all of them are ready before registering the 134 // becomes ready. Wait until all of them are ready before registering the
134 // schemas of managed extensions, so that the policy loaders are reloaded at 135 // schemas of managed extensions, so that the policy loaders are reloaded at
135 // most once. 136 // most once.
136 if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) 137 if (!ExtensionSystem::Get(profile_)->ready().is_signaled())
137 return; 138 return;
138 scoped_ptr<ExtensionSet> added(new ExtensionSet); 139 std::unique_ptr<ExtensionSet> added(new ExtensionSet);
139 added->Insert(extension); 140 added->Insert(extension);
140 LoadSchemas(std::move(added)); 141 LoadSchemas(std::move(added));
141 } 142 }
142 143
143 void ManagedValueStoreCache::ExtensionTracker::OnExtensionUninstalled( 144 void ManagedValueStoreCache::ExtensionTracker::OnExtensionUninstalled(
144 content::BrowserContext* browser_context, 145 content::BrowserContext* browser_context,
145 const Extension* extension, 146 const Extension* extension,
146 extensions::UninstallReason reason) { 147 extensions::UninstallReason reason) {
147 if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) 148 if (!ExtensionSystem::Get(profile_)->ready().is_signaled())
148 return; 149 return;
149 if (extension && UsesManagedStorage(extension)) { 150 if (extension && UsesManagedStorage(extension)) {
150 schema_registry_->UnregisterComponent(policy::PolicyNamespace( 151 schema_registry_->UnregisterComponent(policy::PolicyNamespace(
151 policy::POLICY_DOMAIN_EXTENSIONS, extension->id())); 152 policy::POLICY_DOMAIN_EXTENSIONS, extension->id()));
152 } 153 }
153 } 154 }
154 155
155 void ManagedValueStoreCache::ExtensionTracker::OnExtensionsReady() { 156 void ManagedValueStoreCache::ExtensionTracker::OnExtensionsReady() {
156 // Load schemas for all installed extensions. 157 // Load schemas for all installed extensions.
157 LoadSchemas( 158 LoadSchemas(
158 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet()); 159 ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet());
159 } 160 }
160 161
161 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas( 162 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas(
162 scoped_ptr<ExtensionSet> added) { 163 std::unique_ptr<ExtensionSet> added) {
163 // Filter out extensions that don't use managed storage. 164 // Filter out extensions that don't use managed storage.
164 ExtensionSet::const_iterator it = added->begin(); 165 ExtensionSet::const_iterator it = added->begin();
165 while (it != added->end()) { 166 while (it != added->end()) {
166 std::string to_remove; 167 std::string to_remove;
167 if (!UsesManagedStorage(it->get())) 168 if (!UsesManagedStorage(it->get()))
168 to_remove = (*it)->id(); 169 to_remove = (*it)->id();
169 ++it; 170 ++it;
170 if (!to_remove.empty()) 171 if (!to_remove.empty())
171 added->Remove(to_remove); 172 added->Remove(to_remove);
172 } 173 }
(...skipping 10 matching lines...) Expand all
183 const Extension* extension) const { 184 const Extension* extension) const {
184 if (extension->manifest()->HasPath(manifest_keys::kStorageManagedSchema)) 185 if (extension->manifest()->HasPath(manifest_keys::kStorageManagedSchema))
185 return true; 186 return true;
186 187
187 // TODO(joaodasilva): remove this by M35. 188 // TODO(joaodasilva): remove this by M35.
188 return extension->id() == kLegacyBrowserSupportExtensionId; 189 return extension->id() == kLegacyBrowserSupportExtensionId;
189 } 190 }
190 191
191 // static 192 // static
192 void ManagedValueStoreCache::ExtensionTracker::LoadSchemasOnBlockingPool( 193 void ManagedValueStoreCache::ExtensionTracker::LoadSchemasOnBlockingPool(
193 scoped_ptr<ExtensionSet> extensions, 194 std::unique_ptr<ExtensionSet> extensions,
194 base::WeakPtr<ExtensionTracker> self) { 195 base::WeakPtr<ExtensionTracker> self) {
195 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 196 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
196 scoped_ptr<policy::ComponentMap> components(new policy::ComponentMap); 197 std::unique_ptr<policy::ComponentMap> components(new policy::ComponentMap);
197 198
198 for (ExtensionSet::const_iterator it = extensions->begin(); 199 for (ExtensionSet::const_iterator it = extensions->begin();
199 it != extensions->end(); ++it) { 200 it != extensions->end(); ++it) {
200 std::string schema_file; 201 std::string schema_file;
201 if (!(*it)->manifest()->GetString( 202 if (!(*it)->manifest()->GetString(
202 manifest_keys::kStorageManagedSchema, &schema_file)) { 203 manifest_keys::kStorageManagedSchema, &schema_file)) {
203 // TODO(joaodasilva): Remove this. http://crbug.com/325349 204 // TODO(joaodasilva): Remove this. http://crbug.com/325349
204 (*components)[(*it)->id()] = policy::Schema(); 205 (*components)[(*it)->id()] = policy::Schema();
205 continue; 206 continue;
206 } 207 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 BrowserThread::PostTask( 333 BrowserThread::PostTask(
333 BrowserThread::FILE, FROM_HERE, 334 BrowserThread::FILE, FROM_HERE,
334 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE, 335 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE,
335 base::Unretained(this), 336 base::Unretained(this),
336 ns.component_id, 337 ns.component_id,
337 base::Passed(current.DeepCopy()))); 338 base::Passed(current.DeepCopy())));
338 } 339 }
339 340
340 void ManagedValueStoreCache::UpdatePolicyOnFILE( 341 void ManagedValueStoreCache::UpdatePolicyOnFILE(
341 const std::string& extension_id, 342 const std::string& extension_id,
342 scoped_ptr<policy::PolicyMap> current_policy) { 343 std::unique_ptr<policy::PolicyMap> current_policy) {
343 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 344 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
344 345
345 if (!HasStore(extension_id) && current_policy->empty()) { 346 if (!HasStore(extension_id) && current_policy->empty()) {
346 // Don't create the store now if there are no policies configured for this 347 // Don't create the store now if there are no policies configured for this
347 // extension. If the extension uses the storage.managed API then the store 348 // extension. If the extension uses the storage.managed API then the store
348 // will be created at RunWithValueStoreForExtension(). 349 // will be created at RunWithValueStoreForExtension().
349 return; 350 return;
350 } 351 }
351 352
352 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); 353 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy);
(...skipping 18 matching lines...) Expand all
371 return store; 372 return store;
372 } 373 }
373 374
374 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const { 375 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const {
375 // Note: Currently only manage extensions (not apps). 376 // Note: Currently only manage extensions (not apps).
376 return storage_factory_->HasSettings(settings_namespace::MANAGED, 377 return storage_factory_->HasSettings(settings_namespace::MANAGED,
377 kManagedModelType, extension_id); 378 kManagedModelType, extension_id);
378 } 379 }
379 380
380 } // namespace extensions 381 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698