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()) | |
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE, | 328 base::Bind(&ManagedValueStoreCache::UpdatePolicyOnFILE, |
322 base::Unretained(this), | 329 base::Unretained(this), |
323 ns.component_id, | 330 ns.component_id, |
324 base::Passed(current.DeepCopy()))); | 331 base::Passed(current.DeepCopy()))); |
325 } | 332 } |
326 | 333 |
327 void ManagedValueStoreCache::UpdatePolicyOnFILE( | 334 void ManagedValueStoreCache::UpdatePolicyOnFILE( |
328 const std::string& extension_id, | 335 const std::string& extension_id, |
329 scoped_ptr<policy::PolicyMap> current_policy) { | 336 scoped_ptr<policy::PolicyMap> current_policy) { |
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
338 | |
339 if (!base::DirectoryExists(base_path_.AppendASCII(extension_id)) && | |
not at google - send to devlin
2013/11/20 19:02:53
perhaps pull this into a local method like StoreEx
| |
340 current_policy->empty()) { | |
341 // Don't create the store now if there are no concrete policies configured | |
342 // for this extension. If the extension uses the storage.managed API then | |
343 // the store will be created at RunWithValueStoreForExtension(). | |
344 return; | |
345 } | |
346 | |
331 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); | 347 GetStoreFor(extension_id)->SetCurrentPolicy(*current_policy); |
332 } | 348 } |
333 | 349 |
334 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( | 350 PolicyValueStore* ManagedValueStoreCache::GetStoreFor( |
335 const std::string& extension_id) { | 351 const std::string& extension_id) { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
337 | 353 |
338 PolicyValueStoreMap::iterator it = store_map_.find(extension_id); | 354 PolicyValueStoreMap::iterator it = store_map_.find(extension_id); |
339 if (it != store_map_.end()) | 355 if (it != store_map_.end()) |
340 return it->second.get(); | 356 return it->second.get(); |
341 | 357 |
342 // Create the store now, and serve the cached policy until the PolicyService | 358 // Create the store now, and serve the cached policy until the PolicyService |
343 // sends updated values. | 359 // sends updated values. |
344 PolicyValueStore* store = new PolicyValueStore( | 360 PolicyValueStore* store = new PolicyValueStore( |
345 extension_id, | 361 extension_id, |
346 observers_, | 362 observers_, |
347 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); | 363 make_scoped_ptr(storage_factory_->Create(base_path_, extension_id))); |
348 store_map_[extension_id] = make_linked_ptr(store); | 364 store_map_[extension_id] = make_linked_ptr(store); |
349 | 365 |
350 return store; | 366 return store; |
351 } | 367 } |
352 | 368 |
353 } // namespace extensions | 369 } // namespace extensions |
OLD | NEW |