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

Unified Diff: chrome/browser/policy/schema_registry_service_factory.cc

Issue 342233005: Move ownership of the ComponentCloudPolicyService to the broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months 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/policy/schema_registry_service_factory.cc
diff --git a/chrome/browser/policy/schema_registry_service_factory.cc b/chrome/browser/policy/schema_registry_service_factory.cc
index eaa526848015ce7c60056e06a8583ffa2acc077e..465e47d8e6aee111d71f88d9014e986cebc14c8a 100644
--- a/chrome/browser/policy/schema_registry_service_factory.cc
+++ b/chrome/browser/policy/schema_registry_service_factory.cc
@@ -11,8 +11,51 @@
#include "components/policy/core/common/schema_registry.h"
#include "content/public/browser/browser_context.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_process_platform_part_chromeos.h"
+#include "chrome/browser/chromeos/login/users/user.h"
+#include "chrome/browser/chromeos/login/users/user_manager.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/profiles/profile.h"
+#endif
+
namespace policy {
+#if defined(OS_CHROMEOS)
+namespace {
+
+DeviceLocalAccountPolicyBroker* GetBroker(content::BrowserContext* context) {
+ Profile* profile = Profile::FromBrowserContext(context);
+
+ if (chromeos::ProfileHelper::IsSigninProfile(profile))
+ return NULL;
+
+ if (!chromeos::UserManager::IsInitialized()) {
+ // Bail out in unit tests that don't have a UserManager.
+ return NULL;
+ }
+
+ chromeos::UserManager* user_manager = chromeos::UserManager::Get();
+ chromeos::User* user = user_manager->GetUserByProfile(profile);
+ if (!user)
+ return NULL;
+
+ BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ DeviceLocalAccountPolicyService* service =
+ connector->GetDeviceLocalAccountPolicyService();
+ if (!service)
+ return NULL;
+
+ return service->GetBrokerForUser(user->email());
+}
+
+} // namespace
+#endif // OS_CHROMEOS
+
// static
SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() {
return Singleton<SchemaRegistryServiceFactory>::get();
@@ -60,7 +103,23 @@ SchemaRegistryServiceFactory::CreateForContextInternal(
CombinedSchemaRegistry* global_registry) {
DCHECK(!context->IsOffTheRecord());
DCHECK(registries_.find(context) == registries_.end());
- scoped_ptr<SchemaRegistry> registry(new SchemaRegistry);
+
+ scoped_ptr<SchemaRegistry> registry;
+
+#if defined(OS_CHROMEOS)
+ DeviceLocalAccountPolicyBroker* broker = GetBroker(context);
+ if (broker) {
+ // The SchemaRegistry for a device-local account is owned by its
+ // DeviceLocalAccountPolicyBroker, which uses the registry to fetch and
+ // cache policy even if there is no active session for that account.
+ // Use a ForwardingSchemaRegistry that wraps this SchemaRegistry.
+ registry.reset(new ForwardingSchemaRegistry(broker->schema_registry()));
+ }
+#endif
+
+ if (!registry)
+ registry.reset(new SchemaRegistry);
+
scoped_ptr<SchemaRegistryService> service(new SchemaRegistryService(
registry.Pass(), chrome_schema, global_registry));
registries_[context] = service.get();
« no previous file with comments | « chrome/browser/policy/schema_registry_service_factory.h ('k') | chrome/browser/policy/test/policy_testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698