Added a BCKS to own a Profile's SchemaRegistry.

The SchemaRegistry contains information about the policy types that should be
loaded, and is a dependency of the policy providers. The new BCKS allows
creating the Profile's SchemaRegistry before the Profile's policy providers are
created and start providing Values to the PrefService.

Also added a global SchemaRegistry at the BrowserPolicyConnector that merges
the registries of all the Profiles. This enables shared policy providers (e.g.
the platform provider) to load policy for all the components of all the
Profiles.

[email protected], [email protected], [email protected]
[email protected]
BUG=270667

Review URL: https://codereview.chromium.org/50493014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233599 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 72d8fe0f..18a75dc 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -77,6 +77,9 @@
 #if defined(ENABLE_CONFIGURATION_POLICY)
 #include "chrome/browser/policy/configuration_policy_provider.h"
 #include "chrome/browser/policy/policy_service_impl.h"
+#include "chrome/browser/policy/schema_registry_service.h"
+#include "chrome/browser/policy/schema_registry_service_factory.h"
+#include "components/policy/core/common/schema.h"
 #else
 #include "chrome/browser/policy/policy_service_stub.h"
 #endif  // defined(ENABLE_CONFIGURATION_POLICY)
@@ -323,7 +326,8 @@
   // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
   // anymore, after converting the PrefService to a PKS. Until then it must
   // be associated with a TestingProfile too.
-  CreateProfilePolicyConnector();
+  if (!IsOffTheRecord())
+    CreateProfilePolicyConnector();
 
   extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
       this, extensions::TestExtensionSystem::Build);
@@ -628,6 +632,12 @@
 void TestingProfile::CreateProfilePolicyConnector() {
   scoped_ptr<policy::PolicyService> service;
 #if defined(ENABLE_CONFIGURATION_POLICY)
+  schema_registry_service_ =
+      policy::SchemaRegistryServiceFactory::CreateForContext(
+          this, policy::Schema(), NULL);
+  CHECK_EQ(schema_registry_service_.get(),
+           policy::SchemaRegistryServiceFactory::GetForContext(this));
+
   std::vector<policy::ConfigurationPolicyProvider*> providers;
   service.reset(new policy::PolicyServiceImpl(providers));
 #else