Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 content::Source<Profile>(profile_)); | 99 content::Source<Profile>(profile_)); |
| 100 registrar_.Add(this, | 100 registrar_.Add(this, |
| 101 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 101 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 102 content::Source<Profile>(profile_)); | 102 content::Source<Profile>(profile_)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ManagedValueStoreCache::ExtensionTracker::Observe( | 105 void ManagedValueStoreCache::ExtensionTracker::Observe( |
| 106 int type, | 106 int type, |
| 107 const content::NotificationSource& source, | 107 const content::NotificationSource& source, |
| 108 const content::NotificationDetails& details) { | 108 const content::NotificationDetails& details) { |
| 109 // Some extensions are installed on the first run before the ExtensionService | |
| 110 // becomes ready. Wait until all of them are ready before registering the | |
| 111 // schemas of managed extensions, so that the policy loaders are reloaded at | |
| 112 // most once. | |
| 113 if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) | |
|
bartfab (slow)
2013/11/25 14:24:02
Nit: #include "extensions/common/one_shot_event.h"
Joao da Silva
2013/11/25 15:40:38
Done.
| |
| 114 return; | |
| 115 | |
| 109 scoped_ptr<ExtensionSet> added; | 116 scoped_ptr<ExtensionSet> added; |
| 110 const Extension* removed = NULL; | 117 const Extension* removed = NULL; |
| 111 | 118 |
| 112 switch (type) { | 119 switch (type) { |
| 113 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 120 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
| 114 ExtensionService* service = | 121 ExtensionService* service = |
| 115 ExtensionSystem::Get(profile_)->extension_service(); | 122 ExtensionSystem::Get(profile_)->extension_service(); |
| 116 added = service->GenerateInstalledExtensionsSet(); | 123 added = service->GenerateInstalledExtensionsSet(); |
| 117 break; | 124 break; |
| 118 } | 125 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 263 callback.Run(GetStoreFor(extension->id())); | 270 callback.Run(GetStoreFor(extension->id())); |
| 264 } | 271 } |
| 265 | 272 |
| 266 void ManagedValueStoreCache::DeleteStorageSoon( | 273 void ManagedValueStoreCache::DeleteStorageSoon( |
| 267 const std::string& extension_id) { | 274 const std::string& extension_id) { |
| 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 269 // It's possible that the store exists, but hasn't been loaded yet | 276 // It's possible that the store exists, but hasn't been loaded yet |
| 270 // (because the extension is unloaded, for example). Open the database to | 277 // (because the extension is unloaded, for example). Open the database to |
| 271 // clear it if it exists. | 278 // clear it if it exists. |
| 272 // TODO(joaodasilva): move this check to a ValueStore method. | 279 if (!HasStore(extension_id)) |
| 273 if (!base::DirectoryExists(base_path_.AppendASCII(extension_id))) | |
| 274 return; | 280 return; |
| 275 GetStoreFor(extension_id)->DeleteStorage(); | 281 GetStoreFor(extension_id)->DeleteStorage(); |
| 276 store_map_.erase(extension_id); | 282 store_map_.erase(extension_id); |
| 277 } | 283 } |
| 278 | 284 |
| 279 void ManagedValueStoreCache::OnPolicyServiceInitialized( | 285 void ManagedValueStoreCache::OnPolicyServiceInitialized( |
| 280 policy::PolicyDomain domain) { | 286 policy::PolicyDomain domain) { |
| 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 282 | 288 |
| 283 if (domain != policy::POLICY_DOMAIN_EXTENSIONS) | 289 if (domain != policy::POLICY_DOMAIN_EXTENSIONS) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE, | 327 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE, |
| 322 base::Unretained(this), | 328 base::Unretained(this), |
| 323 ns.component_id, | 329 ns.component_id, |
| 324 base::Passed(current.DeepCopy()))); | 330 base::Passed(current.DeepCopy()))); |
| 325 } | 331 } |
| 326 | 332 |
| 327 void ManagedValueStoreCache::UpdatePolicyOnFILE( | 333 void ManagedValueStoreCache::UpdatePolicyOnFILE( |
| 328 const std::string& extension_id, | 334 const std::string& extension_id, |
| 329 scoped_ptr<policy::PolicyMap> current_policy) { | 335 scoped_ptr<policy::PolicyMap> current_policy) { |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 337 | |
| 338 if (!HasStore(extension_id) && current_policy->empty()) { | |
| 339 // Don't create the store now if there are no concrete policies configured | |
|
bartfab (slow)
2013/11/25 14:24:02
Nit: What do you mean by "concrete policies"? Do y
Joao da Silva
2013/11/25 15:40:38
Yes; removed the "concrete" since it was just conf
| |
| 340 // for this extension. If the extension uses the storage.managed API then | |
| 341 // the store will be created at RunWithValueStoreForExtension(). | |
| 342 return; | |
| 343 } | |
| 344 | |
| 331 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); | 345 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); |
| 332 } | 346 } |
| 333 | 347 |
| 334 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( | 348 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( |
| 335 const std::string& extension_id) { | 349 const std::string& extension_id) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 337 | 351 |
| 338 PolicyValueStoreMap::iterator it = store_map_.find(extension_id); | 352 PolicyValueStoreMap::iterator it = store_map_.find(extension_id); |
| 339 if (it != store_map_.end()) | 353 if (it != store_map_.end()) |
| 340 return it->second.get(); | 354 return it->second.get(); |
| 341 | 355 |
| 342 // Create the store now, and serve the cached policy until the PolicyService | 356 // Create the store now, and serve the cached policy until the PolicyService |
| 343 // sends updated values. | 357 // sends updated values. |
| 344 PolicyValueStore* store = new PolicyValueStore( | 358 PolicyValueStore* store = new PolicyValueStore( |
| 345 extension_id, | 359 extension_id, |
| 346 observers_, | 360 observers_, |
| 347 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); | 361 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); |
| 348 store_map_[extension_id] = make_linked_ptr(store); | 362 store_map_[extension_id] = make_linked_ptr(store); |
| 349 | 363 |
| 350 return store; | 364 return store; |
| 351 } | 365 } |
| 352 | 366 |
| 367 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) { | |
| 368 // TODO(joaodasilva): move this check to a ValueStore method. | |
| 369 return base::DirectoryExists(base_path_.AppendASCII(extension_id)); | |
| 370 } | |
| 371 | |
| 353 } // namespace extensions | 372 } // namespace extensions |
| OLD | NEW |