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

Side by Side 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: fix clang build 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/policy/schema_registry_service_factory.h" 5 #include "chrome/browser/policy/schema_registry_service_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h"
bartfab (slow) 2014/06/20 09:44:23 Nit: Move this to the header, which uses DISALLOW_
Joao da Silva 2014/06/20 15:36:08 Done.
8 #include "chrome/browser/policy/schema_registry_service.h" 9 #include "chrome/browser/policy/schema_registry_service.h"
9 #include "components/keyed_service/content/browser_context_dependency_manager.h" 10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
10 #include "components/policy/core/common/schema.h" 11 #include "components/policy/core/common/schema.h"
11 #include "components/policy/core/common/schema_registry.h" 12 #include "components/policy/core/common/schema_registry.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 14
15 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/login/users/user.h"
18 #include "chrome/browser/chromeos/login/users/user_manager.h"
19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
20 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
22 #include "chrome/browser/profiles/profile.h"
23 #endif
24
14 namespace policy { 25 namespace policy {
15 26
27 #if defined(OS_CHROMEOS)
28 namespace {
29
30 DeviceLocalAccountPolicyBroker* GetBroker(content::BrowserContext* context) {
31 Profile* profile = Profile::FromBrowserContext(context);
32
33 if (chromeos::ProfileHelper::IsSigninProfile(profile))
34 return NULL;
35
36 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
37 chromeos::User* user = user_manager->GetUserByProfile(profile);
38 if (!user)
39 return NULL;
40
41 BrowserPolicyConnectorChromeOS* connector =
42 g_browser_process->platform_part()->browser_policy_connector_chromeos();
bartfab (slow) 2014/06/20 09:44:23 Nit: #include "chrome/browser/browser_process_plat
Joao da Silva 2014/06/20 15:36:08 Done.
43 DeviceLocalAccountPolicyService* service =
44 connector->GetDeviceLocalAccountPolicyService();
45 return service->GetBrokerForUser(user->email());
46 }
47
48 } // namespace
49 #endif // OS_CHROMEOS
50
16 // static 51 // static
17 SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { 52 SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() {
18 return Singleton<SchemaRegistryServiceFactory>::get(); 53 return Singleton<SchemaRegistryServiceFactory>::get();
19 } 54 }
20 55
21 // static 56 // static
22 SchemaRegistryService* SchemaRegistryServiceFactory::GetForContext( 57 SchemaRegistryService* SchemaRegistryServiceFactory::GetForContext(
23 content::BrowserContext* context) { 58 content::BrowserContext* context) {
24 return GetInstance()->GetForContextInternal(context); 59 return GetInstance()->GetForContextInternal(context);
25 } 60 }
(...skipping 27 matching lines...) Expand all
53 return it->second; 88 return it->second;
54 } 89 }
55 90
56 scoped_ptr<SchemaRegistryService> 91 scoped_ptr<SchemaRegistryService>
57 SchemaRegistryServiceFactory::CreateForContextInternal( 92 SchemaRegistryServiceFactory::CreateForContextInternal(
58 content::BrowserContext* context, 93 content::BrowserContext* context,
59 const Schema& chrome_schema, 94 const Schema& chrome_schema,
60 CombinedSchemaRegistry* global_registry) { 95 CombinedSchemaRegistry* global_registry) {
61 DCHECK(!context->IsOffTheRecord()); 96 DCHECK(!context->IsOffTheRecord());
62 DCHECK(registries_.find(context) == registries_.end()); 97 DCHECK(registries_.find(context) == registries_.end());
63 SchemaRegistryService* registry = 98
64 new SchemaRegistryService(chrome_schema, global_registry); 99 scoped_ptr<SchemaRegistryService> registry;
65 registries_[context] = registry; 100
66 return make_scoped_ptr(registry); 101 #if defined(OS_CHROMEOS)
102 DeviceLocalAccountPolicyBroker* broker = GetBroker(context);
103 if (broker) {
104 // The DeviceLocalAccountPolicyBroker creates a SchemaRegistryService for
105 // device local accounts earlier, so that the external data can be preloaded
bartfab (slow) 2014/06/20 09:44:23 Nit: s/device local/device-local/
Joao da Silva 2014/06/20 15:36:08 Done.
106 // before the session is started. Transfer its ownership now.
107 registry = broker->release_schema_registry();
108 }
109 #endif
110
111 if (!registry)
112 registry.reset(new SchemaRegistryService(chrome_schema, global_registry));
113
114 registries_[context] = registry.get();
115 return registry.Pass();
67 } 116 }
68 117
69 void SchemaRegistryServiceFactory::BrowserContextShutdown( 118 void SchemaRegistryServiceFactory::BrowserContextShutdown(
70 content::BrowserContext* context) { 119 content::BrowserContext* context) {
71 if (context->IsOffTheRecord()) 120 if (context->IsOffTheRecord())
72 return; 121 return;
73 RegistryMap::iterator it = registries_.find(context); 122 RegistryMap::iterator it = registries_.find(context);
74 if (it != registries_.end()) 123 if (it != registries_.end()) {
124 #if defined(OS_CHROMEOS)
125 DeviceLocalAccountPolicyBroker* broker = GetBroker(context);
126 if (broker) {
127 // Give the broker a notification to clean up any observers of the
128 // SchemaRegistryService.
129 broker->OnSchemaRegistryShutdown();
130 }
131 #endif
75 it->second->Shutdown(); 132 it->second->Shutdown();
76 else 133 } else {
77 NOTREACHED(); 134 NOTREACHED();
135 }
78 } 136 }
79 137
80 void SchemaRegistryServiceFactory::BrowserContextDestroyed( 138 void SchemaRegistryServiceFactory::BrowserContextDestroyed(
81 content::BrowserContext* context) { 139 content::BrowserContext* context) {
82 registries_.erase(context); 140 registries_.erase(context);
83 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); 141 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context);
84 } 142 }
85 143
86 void SchemaRegistryServiceFactory::SetEmptyTestingFactory( 144 void SchemaRegistryServiceFactory::SetEmptyTestingFactory(
87 content::BrowserContext* context) {} 145 content::BrowserContext* context) {}
88 146
89 void SchemaRegistryServiceFactory::CreateServiceNow( 147 void SchemaRegistryServiceFactory::CreateServiceNow(
90 content::BrowserContext* context) {} 148 content::BrowserContext* context) {}
91 149
92 } // namespace policy 150 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698