| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/api/storage/policy_value_store.h" | 15 #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
| 16 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" | 16 #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" |
| 17 #include "chrome/browser/extensions/event_names.h" | 17 #include "chrome/browser/extensions/event_names.h" |
| 18 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
| 21 #include "chrome/browser/policy/policy_domain_descriptor.h" | 21 #include "chrome/browser/policy/policy_domain_descriptor.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector.h" | 22 #include "chrome/browser/policy/profile_policy_connector.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/value_store/value_store_change.h" | 25 #include "chrome/browser/value_store/value_store_change.h" |
| 26 #include "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h
" | 26 #include "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h
" |
| 27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 29 #include "chrome/common/extensions/extension_set.h" | 28 #include "chrome/common/extensions/extension_set.h" |
| 30 #include "chrome/common/extensions/manifest.h" | 29 #include "chrome/common/extensions/manifest.h" |
| 31 #include "chrome/common/extensions/permissions/api_permission.h" | 30 #include "chrome/common/extensions/permissions/api_permission.h" |
| 32 #include "components/policy/core/common/policy_schema.h" | 31 #include "components/policy/core/common/policy_schema.h" |
| 33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_observer.h" | 33 #include "content/public/browser/notification_observer.h" |
| 35 #include "content/public/browser/notification_registrar.h" | 34 #include "content/public/browser/notification_registrar.h" |
| 36 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 36 #include "extensions/common/manifest_constants.h" |
| 37 | 37 |
| 38 using content::BrowserThread; | 38 using content::BrowserThread; |
| 39 | 39 |
| 40 namespace extensions { | 40 namespace extensions { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 const char kLoadSchemasBackgroundTaskTokenName[] = | 44 const char kLoadSchemasBackgroundTaskTokenName[] = |
| 45 "load_managed_storage_schemas_token"; | 45 "load_managed_storage_schemas_token"; |
| 46 | 46 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const content::NotificationDetails& details) { | 97 const content::NotificationDetails& details) { |
| 98 if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) | 98 if (!ExtensionSystem::Get(profile_)->ready().is_signaled()) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 scoped_refptr<policy::PolicyDomainDescriptor> descriptor( | 101 scoped_refptr<policy::PolicyDomainDescriptor> descriptor( |
| 102 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS)); | 102 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS)); |
| 103 const ExtensionSet* set = | 103 const ExtensionSet* set = |
| 104 ExtensionSystem::Get(profile_)->extension_service()->extensions(); | 104 ExtensionSystem::Get(profile_)->extension_service()->extensions(); |
| 105 scoped_ptr<ExtensionSet> managed_extensions(new ExtensionSet()); | 105 scoped_ptr<ExtensionSet> managed_extensions(new ExtensionSet()); |
| 106 for (ExtensionSet::const_iterator it = set->begin(); it != set->end(); ++it) { | 106 for (ExtensionSet::const_iterator it = set->begin(); it != set->end(); ++it) { |
| 107 if ((*it)->manifest()->HasPath( | 107 if ((*it)->manifest()->HasPath(manifest_keys::kStorageManagedSchema)) { |
| 108 extension_manifest_keys::kStorageManagedSchema)) { | |
| 109 managed_extensions->Insert(*it); | 108 managed_extensions->Insert(*it); |
| 110 } | 109 } |
| 111 | 110 |
| 112 // TODO(joaodasilva): also load extensions that use the storage API for now, | 111 // TODO(joaodasilva): also load extensions that use the storage API for now, |
| 113 // to support the Legacy Browser Support extension. Remove this for M30. | 112 // to support the Legacy Browser Support extension. Remove this for M30. |
| 114 // http://crbug.com/240704 | 113 // http://crbug.com/240704 |
| 115 if ((*it)->HasAPIPermission(APIPermission::kStorage)) | 114 if ((*it)->HasAPIPermission(APIPermission::kStorage)) |
| 116 managed_extensions->Insert(*it); | 115 managed_extensions->Insert(*it); |
| 117 } | 116 } |
| 118 | 117 |
| 119 // Load the schema files in a background thread. | 118 // Load the schema files in a background thread. |
| 120 BrowserThread::PostBlockingPoolSequencedTask( | 119 BrowserThread::PostBlockingPoolSequencedTask( |
| 121 kLoadSchemasBackgroundTaskTokenName, FROM_HERE, | 120 kLoadSchemasBackgroundTaskTokenName, FROM_HERE, |
| 122 base::Bind(&ExtensionTracker::LoadSchemas, | 121 base::Bind(&ExtensionTracker::LoadSchemas, |
| 123 base::Passed(&managed_extensions), | 122 base::Passed(&managed_extensions), |
| 124 weak_factory_.GetWeakPtr())); | 123 weak_factory_.GetWeakPtr())); |
| 125 } | 124 } |
| 126 | 125 |
| 127 // static | 126 // static |
| 128 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas( | 127 void ManagedValueStoreCache::ExtensionTracker::LoadSchemas( |
| 129 scoped_ptr<ExtensionSet> extensions, | 128 scoped_ptr<ExtensionSet> extensions, |
| 130 base::WeakPtr<ExtensionTracker> self) { | 129 base::WeakPtr<ExtensionTracker> self) { |
| 131 scoped_refptr<policy::PolicyDomainDescriptor> descriptor = | 130 scoped_refptr<policy::PolicyDomainDescriptor> descriptor = |
| 132 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); | 131 new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); |
| 133 | 132 |
| 134 for (ExtensionSet::const_iterator it = extensions->begin(); | 133 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 135 it != extensions->end(); ++it) { | 134 it != extensions->end(); ++it) { |
| 136 std::string schema_file; | 135 std::string schema_file; |
| 137 if (!(*it)->manifest()->GetString( | 136 if (!(*it)->manifest()->GetString( |
| 138 extension_manifest_keys::kStorageManagedSchema, &schema_file)) { | 137 manifest_keys::kStorageManagedSchema, &schema_file)) { |
| 139 // TODO(joaodasilva): Remove this for M30. http://crbug.com/240704 | 138 // TODO(joaodasilva): Remove this for M30. http://crbug.com/240704 |
| 140 if ((*it)->HasAPIPermission(APIPermission::kStorage)) { | 139 if ((*it)->HasAPIPermission(APIPermission::kStorage)) { |
| 141 descriptor->RegisterComponent((*it)->id(), | 140 descriptor->RegisterComponent((*it)->id(), |
| 142 scoped_ptr<policy::PolicySchema>()); | 141 scoped_ptr<policy::PolicySchema>()); |
| 143 } else { | 142 } else { |
| 144 NOTREACHED(); | 143 NOTREACHED(); |
| 145 } | 144 } |
| 146 continue; | 145 continue; |
| 147 } | 146 } |
| 148 // The extension should have been validated, so assume the schema exists | 147 // The extension should have been validated, so assume the schema exists |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 continuation.Run(); | 401 continuation.Run(); |
| 403 } | 402 } |
| 404 | 403 |
| 405 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { | 404 policy::PolicyService* ManagedValueStoreCache::GetPolicyService() { |
| 406 policy::ProfilePolicyConnector* connector = | 405 policy::ProfilePolicyConnector* connector = |
| 407 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | 406 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); |
| 408 return connector->policy_service(); | 407 return connector->policy_service(); |
| 409 } | 408 } |
| 410 | 409 |
| 411 } // namespace extensions | 410 } // namespace extensions |
| OLD | NEW |