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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS)); | 105 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS)); |
106 const ExtensionSet* set = | 106 const ExtensionSet* set = |
107 ExtensionSystem::Get(profile_)->extension_service()->extensions(); | 107 ExtensionSystem::Get(profile_)->extension_service()->extensions(); |
108 scoped_ptr<ExtensionSet> managed_extensions(new ExtensionSet()); | 108 scoped_ptr<ExtensionSet> managed_extensions(new ExtensionSet()); |
109 for (ExtensionSet::const_iterator it = set->begin(); it != set->end(); ++it) { | 109 for (ExtensionSet::const_iterator it = set->begin(); it != set->end(); ++it) { |
110 if ((*it)->manifest()->HasPath(manifest_keys::kStorageManagedSchema)) { | 110 if ((*it)->manifest()->HasPath(manifest_keys::kStorageManagedSchema)) { |
111 managed_extensions->Insert(*it); | 111 managed_extensions->Insert(*it); |
112 } | 112 } |
113 | 113 |
114 // TODO(joaodasilva): also load extensions that use the storage API for now, | 114 // TODO(joaodasilva): also load extensions that use the storage API for now, |
115 // to support the Legacy Browser Support extension. Remove this for M30. | 115 // to support the Legacy Browser Support extension. Remove this. |
116 // http://crbug.com/240704 | 116 // http://crbug.com/240704 |
117 if ((*it)->HasAPIPermission(APIPermission::kStorage)) | 117 if ((*it)->HasAPIPermission(APIPermission::kStorage)) |
118 managed_extensions->Insert(*it); | 118 managed_extensions->Insert(*it); |
119 } | 119 } |
120 | 120 |
121 // Load the schema files in a background thread. | 121 // Load the schema files in a background thread. |
122 BrowserThread::PostBlockingPoolSequencedTask( | 122 BrowserThread::PostBlockingPoolSequencedTask( |
123 kLoadSchemasBackgroundTaskTokenName, FROM_HERE, | 123 kLoadSchemasBackgroundTaskTokenName, FROM_HERE, |
124 base::Bind(&ExtensionTracker::LoadSchemas, | 124 base::Bind(&ExtensionTracker::LoadSchemas, |
125 base::Passed(&managed_extensions), | 125 base::Passed(&managed_extensions), |
126 weak_factory_.GetWeakPtr())); | 126 weak_factory_.GetWeakPtr())); |
127 } | 127 } |
128 | 128 |
129 // static | 129 // static |
130 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas( | 130 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas( |
131 scoped_ptr<ExtensionSet> extensions, | 131 scoped_ptr<ExtensionSet> extensions, |
132 base::WeakPtr<ExtensionTracker> self) { | 132 base::WeakPtr<ExtensionTracker> self) { |
133 scoped_refptr<policy::PolicyDomainDescriptor> descriptor = | 133 scoped_refptr<policy::PolicyDomainDescriptor> descriptor = |
134 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); | 134 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); |
135 | 135 |
136 for (ExtensionSet::const_iterator it = extensions->begin(); | 136 for (ExtensionSet::const_iterator it = extensions->begin(); |
137 it != extensions->end(); ++it) { | 137 it != extensions->end(); ++it) { |
138 std::string schema_file; | 138 std::string schema_file; |
139 if (!(*it)->manifest()->GetString( | 139 if (!(*it)->manifest()->GetString( |
140 manifest_keys::kStorageManagedSchema, &schema_file)) { | 140 manifest_keys::kStorageManagedSchema, &schema_file)) { |
141 // TODO(joaodasilva): Remove this for M32. http://crbug.com/240704 | 141 // TODO(joaodasilva): Remove this. http://crbug.com/240704 |
142 if ((*it)->HasAPIPermission(APIPermission::kStorage)) { | 142 if ((*it)->HasAPIPermission(APIPermission::kStorage)) { |
143 descriptor->RegisterComponent((*it)->id(), | 143 descriptor->RegisterComponent((*it)->id(), policy::Schema()); |
144 scoped_ptr<policy::SchemaOwner>()); | |
145 } else { | 144 } else { |
146 NOTREACHED(); | 145 NOTREACHED(); |
147 } | 146 } |
148 continue; | 147 continue; |
149 } | 148 } |
150 // The extension should have been validated, so assume the schema exists | 149 // The extension should have been validated, so assume the schema exists |
151 // and is valid. | 150 // and is valid. |
152 std::string error; | 151 std::string error; |
153 scoped_ptr<policy::SchemaOwner> schema = | 152 policy::Schema schema = |
154 StorageSchemaManifestHandler::GetSchema(it->get(), &error); | 153 StorageSchemaManifestHandler::GetSchema(it->get(), &error); |
155 CHECK(schema) << error; | 154 CHECK(schema.valid()) << error; |
156 descriptor->RegisterComponent((*it)->id(), schema.Pass()); | 155 descriptor->RegisterComponent((*it)->id(), schema); |
157 } | 156 } |
158 | 157 |
159 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
160 BrowserThread::UI, FROM_HERE, | 159 BrowserThread::UI, FROM_HERE, |
161 base::Bind(&ExtensionTracker::RegisterDomain, self, descriptor)); | 160 base::Bind(&ExtensionTracker::RegisterDomain, self, descriptor)); |
162 } | 161 } |
163 | 162 |
164 void ManagedValueStoreCache::ExtensionTracker::RegisterDomain( | 163 void ManagedValueStoreCache::ExtensionTracker::RegisterDomain( |
165 scoped_refptr<const policy::PolicyDomainDescriptor> descriptor) { | 164 scoped_refptr<const policy::PolicyDomainDescriptor> descriptor) { |
166 policy::ProfilePolicyConnector* connector = | 165 policy::ProfilePolicyConnector* connector = |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 continuation.Run(); | 403 continuation.Run(); |
405 } | 404 } |
406 | 405 |
407 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { | 406 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { |
408 policy::ProfilePolicyConnector* connector = | 407 policy::ProfilePolicyConnector* connector = |
409 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | 408 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); |
410 return connector->policy_service(); | 409 return connector->policy_service(); |
411 } | 410 } |
412 | 411 |
413 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |