Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1930)

Unified Diff: chrome/browser/extensions/api/storage/managed_value_store_cache.cc

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: Fixed mac tests Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/storage/managed_value_store_cache.cc
diff --git a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
index c1957f301b47c70a2a1b7e3e110d5be58ded9e3f..03f43162a76624382c68103c6b37b21a56f1975b 100644
--- a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
+++ b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
@@ -17,9 +17,10 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
-#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/policy/schema_registry_service.h"
bartfab (slow) 2013/11/05 15:53:04 Nit: As commented elsewhere, in line with your usu
Joao da Silva 2013/11/07 13:15:00 It's needed so that this unit sees that a SchemaRe
+#include "chrome/browser/policy/schema_registry_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/value_store/value_store_change.h"
#include "chrome/common/extensions/api/storage.h"
@@ -28,6 +29,7 @@
#include "chrome/common/extensions/extension_set.h"
#include "components/policy/core/common/schema.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
@@ -66,15 +68,17 @@ class ManagedValueStoreCache::ExtensionTracker
const content::NotificationDetails& details) OVERRIDE;
private:
- // Loads the schemas of the |extensions| and passes a PolicyDomainDescriptor
- // to RegisterDomain().
+ bool IsEnterpriseExtension(const Extension* extension) const;
+
+ // Loads the schemas of the |extensions| and passes a ComponentMap to
+ // Register().
static void LoadSchemas(scoped_ptr<ExtensionSet> extensions,
base::WeakPtr<ExtensionTracker> self);
- void RegisterDomain(
- scoped_refptr<const policy::PolicyDomainDescriptor> descriptor);
+ void Register(const policy::ComponentMap* components);
Profile* profile_;
content::NotificationRegistrar registrar_;
+ policy::SchemaRegistry* schema_registry_;
bartfab (slow) 2013/11/05 15:53:04 Nit: #include "chrome/browser/policy/schema_regist
Joao da Silva 2013/11/07 13:15:00 Done.
base::WeakPtrFactory<ExtensionTracker> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ExtensionTracker);
@@ -82,6 +86,8 @@ class ManagedValueStoreCache::ExtensionTracker
ManagedValueStoreCache::ExtensionTracker::ExtensionTracker(Profile* profile)
: profile_(profile),
+ schema_registry_(
+ policy::SchemaRegistryServiceFactory::GetForContext(profile)),
weak_factory_(this) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSIONS_READY,
@@ -101,37 +107,64 @@ void ManagedValueStoreCache::ExtensionTracker::Observe(
if (!ExtensionSystem::Get(profile_)->ready().is_signaled())
return;
- scoped_refptr<policy::PolicyDomainDescriptor> descriptor(
- new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS));
- const ExtensionSet* set =
- ExtensionSystem::Get(profile_)->extension_service()->extensions();
- scoped_ptr<ExtensionSet> managed_extensions(new ExtensionSet());
- for (ExtensionSet::const_iterator it = set->begin(); it != set->end(); ++it) {
- if ((*it)->manifest()->HasPath(manifest_keys::kStorageManagedSchema)) {
- managed_extensions->Insert(*it);
+ if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
+ const Extension* extension =
+ content::Details<UnloadedExtensionInfo>(details)->extension;
+ if (IsEnterpriseExtension(extension)) {
+ schema_registry_->UnregisterComponent(policy::PolicyNamespace(
bartfab (slow) 2013/11/05 15:53:04 Nit: #include "components/policy/core/common/polic
Joao da Silva 2013/11/07 13:15:00 Done.
+ policy::POLICY_DOMAIN_EXTENSIONS, extension->id()));
}
+ return;
+ }
- // TODO(joaodasilva): also load extensions that use the storage API for now,
- // to support the Legacy Browser Support extension. Remove this.
- // http://crbug.com/240704
- if ((*it)->HasAPIPermission(APIPermission::kStorage))
- managed_extensions->Insert(*it);
+ scoped_ptr<ExtensionSet> set(new ExtensionSet());
bartfab (slow) 2013/11/05 15:53:04 Nit: No need for ().
Joao da Silva 2013/11/07 13:15:00 Done.
+ if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
+ const Extension* extension =
+ content::Details<const Extension>(details).ptr();
+ if (IsEnterpriseExtension(extension))
+ set->Insert(extension);
+ } else if (type == chrome::NOTIFICATION_EXTENSIONS_READY) {
+ const ExtensionSet* extensions =
+ ExtensionSystem::Get(profile_)->extension_service()->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
+ it != extensions->end(); ++it) {
+ if (IsEnterpriseExtension(*it))
+ set->Insert(*it);
+ }
+ } else {
+ NOTREACHED();
}
+ if (set->is_empty())
+ return;
+
// Load the schema files in a background thread.
BrowserThread::PostBlockingPoolSequencedTask(
kLoadSchemasBackgroundTaskTokenName, FROM_HERE,
base::Bind(&ExtensionTracker::LoadSchemas,
- base::Passed(&managed_extensions),
+ base::Passed(&set),
weak_factory_.GetWeakPtr()));
}
+bool ManagedValueStoreCache::ExtensionTracker::IsEnterpriseExtension(
+ const Extension* extension) const {
+ if (extension->manifest()->HasPath(manifest_keys::kStorageManagedSchema))
+ return true;
+
+ // TODO(joaodasilva): also load extensions that use the storage API for now,
+ // to support the Legacy Browser Support extension. Remove this.
+ // http://crbug.com/240704
+ if (extension->HasAPIPermission(APIPermission::kStorage))
+ return true;
+
+ return false;
+}
+
// static
void ManagedValueStoreCache::ExtensionTracker::LoadSchemas(
scoped_ptr<ExtensionSet> extensions,
base::WeakPtr<ExtensionTracker> self) {
- scoped_refptr<policy::PolicyDomainDescriptor> descriptor =
- new policy::PolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS);
+ policy::ComponentMap* components = new policy::ComponentMap();
bartfab (slow) 2013/11/05 15:53:04 Nit 1: No need for (). Nit 2: Use a scoped_ptr.
Joao da Silva 2013/11/07 13:15:00 Done.
for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
@@ -140,7 +173,7 @@ void ManagedValueStoreCache::ExtensionTracker::LoadSchemas(
manifest_keys::kStorageManagedSchema, &schema_file)) {
// TODO(joaodasilva): Remove this. http://crbug.com/240704
if ((*it)->HasAPIPermission(APIPermission::kStorage)) {
- descriptor->RegisterComponent((*it)->id(), policy::Schema());
+ (*components)[(*it)->id()] = policy::Schema();
} else {
NOTREACHED();
}
@@ -152,19 +185,18 @@ void ManagedValueStoreCache::ExtensionTracker::LoadSchemas(
policy::Schema schema =
StorageSchemaManifestHandler::GetSchema(it->get(), &error);
CHECK(schema.valid()) << error;
- descriptor->RegisterComponent((*it)->id(), schema);
+ (*components)[(*it)->id()] = schema;
}
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&ExtensionTracker::RegisterDomain, self, descriptor));
+ base::Bind(&ExtensionTracker::Register, self, base::Owned(components)));
}
-void ManagedValueStoreCache::ExtensionTracker::RegisterDomain(
- scoped_refptr<const policy::PolicyDomainDescriptor> descriptor) {
- policy::ProfilePolicyConnector* connector =
- policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);
- connector->policy_service()->RegisterPolicyDomain(descriptor);
+void ManagedValueStoreCache::ExtensionTracker::Register(
+ const policy::ComponentMap* components) {
+ schema_registry_->RegisterComponents(policy::POLICY_DOMAIN_EXTENSIONS,
+ *components);
}
ManagedValueStoreCache::ManagedValueStoreCache(
@@ -186,7 +218,10 @@ ManagedValueStoreCache::ManagedValueStoreCache(
GetPolicyService()->AddObserver(policy::POLICY_DOMAIN_EXTENSIONS, this);
- extension_tracker_.reset(new ExtensionTracker(profile_));
+ // Track the extensions of the original Profile only; the OTR profile has
+ // a subset of those.
+ if (!profile->IsOffTheRecord())
+ extension_tracker_.reset(new ExtensionTracker(profile_));
}
ManagedValueStoreCache::~ManagedValueStoreCache() {

Powered by Google App Engine
This is Rietveld 408576698