| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 extension_registry_observer_; | 100 extension_registry_observer_; |
| 101 policy::SchemaRegistry* schema_registry_; | 101 policy::SchemaRegistry* schema_registry_; |
| 102 base::WeakPtrFactory<ExtensionTracker> weak_factory_; | 102 base::WeakPtrFactory<ExtensionTracker> weak_factory_; |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(ExtensionTracker); | 104 DISALLOW_COPY_AND_ASSIGN(ExtensionTracker); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 ManagedValueStoreCache::ExtensionTracker::ExtensionTracker(Profile* profile) | 107 ManagedValueStoreCache::ExtensionTracker::ExtensionTracker(Profile* profile) |
| 108 : profile_(profile), | 108 : profile_(profile), |
| 109 extension_registry_observer_(this), | 109 extension_registry_observer_(this), |
| 110 schema_registry_( | 110 schema_registry_(policy::SchemaRegistryServiceFactory::GetForContext( |
| 111 policy::SchemaRegistryServiceFactory::GetForContext(profile)), | 111 profile)->registry()), |
| 112 weak_factory_(this) { | 112 weak_factory_(this) { |
| 113 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 113 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 114 // Load schemas when the extension system is ready. It might be ready now. | 114 // Load schemas when the extension system is ready. It might be ready now. |
| 115 ExtensionSystem::Get(profile_)->ready().Post( | 115 ExtensionSystem::Get(profile_)->ready().Post( |
| 116 FROM_HERE, | 116 FROM_HERE, |
| 117 base::Bind(&ExtensionTracker::OnExtensionsReady, | 117 base::Bind(&ExtensionTracker::OnExtensionsReady, |
| 118 weak_factory_.GetWeakPtr())); | 118 weak_factory_.GetWeakPtr())); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void ManagedValueStoreCache::ExtensionTracker::OnExtensionWillBeInstalled( | 121 void ManagedValueStoreCache::ExtensionTracker::OnExtensionWillBeInstalled( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 void ManagedValueStoreCache::OnPolicyServiceInitialized( | 284 void ManagedValueStoreCache::OnPolicyServiceInitialized( |
| 285 policy::PolicyDomain domain) { | 285 policy::PolicyDomain domain) { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 286 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 287 | 287 |
| 288 if (domain != policy::POLICY_DOMAIN_EXTENSIONS) | 288 if (domain != policy::POLICY_DOMAIN_EXTENSIONS) |
| 289 return; | 289 return; |
| 290 | 290 |
| 291 // The PolicyService now has all the initial policies ready. Send policy | 291 // The PolicyService now has all the initial policies ready. Send policy |
| 292 // for all the managed extensions to their backing stores now. | 292 // for all the managed extensions to their backing stores now. |
| 293 policy::SchemaRegistry* registry = | 293 policy::SchemaRegistry* registry = |
| 294 policy::SchemaRegistryServiceFactory::GetForContext(profile_); | 294 policy::SchemaRegistryServiceFactory::GetForContext(profile_)->registry(); |
| 295 const policy::ComponentMap* map = registry->schema_map()->GetComponents( | 295 const policy::ComponentMap* map = registry->schema_map()->GetComponents( |
| 296 policy::POLICY_DOMAIN_EXTENSIONS); | 296 policy::POLICY_DOMAIN_EXTENSIONS); |
| 297 if (!map) | 297 if (!map) |
| 298 return; | 298 return; |
| 299 | 299 |
| 300 const policy::PolicyMap empty_map; | 300 const policy::PolicyMap empty_map; |
| 301 for (policy::ComponentMap::const_iterator it = map->begin(); | 301 for (policy::ComponentMap::const_iterator it = map->begin(); |
| 302 it != map->end(); ++it) { | 302 it != map->end(); ++it) { |
| 303 const policy::PolicyNamespace ns(policy::POLICY_DOMAIN_EXTENSIONS, | 303 const policy::PolicyNamespace ns(policy::POLICY_DOMAIN_EXTENSIONS, |
| 304 it->first); | 304 it->first); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 362 |
| 363 return store; | 363 return store; |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const { | 366 bool ManagedValueStoreCache::HasStore(const std::string& extension_id) const { |
| 367 // TODO(joaodasilva): move this check to a ValueStore method. | 367 // TODO(joaodasilva): move this check to a ValueStore method. |
| 368 return base::DirectoryExists(base_path_.AppendASCII(extension_id)); | 368 return base::DirectoryExists(base_path_.AppendASCII(extension_id)); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace extensions | 371 } // namespace extensions |
| OLD | NEW |