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

Side by Side Diff: components/policy/core/browser/browser_policy_connector.cc

Issue 240903002: Add consumer_device_management_service() in BrowserPolicyConnectorChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/policy/core/browser/browser_policy_connector.h" 5 #include "components/policy/core/browser/browser_policy_connector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 13 matching lines...) Expand all
24 #include "components/policy/core/common/policy_switches.h" 24 #include "components/policy/core/common/policy_switches.h"
25 #include "google_apis/gaia/gaia_auth_util.h" 25 #include "google_apis/gaia/gaia_auth_util.h"
26 #include "net/url_request/url_request_context_getter.h" 26 #include "net/url_request/url_request_context_getter.h"
27 #include "policy/policy_constants.h" 27 #include "policy/policy_constants.h"
28 #include "third_party/icu/source/i18n/unicode/regex.h" 28 #include "third_party/icu/source/i18n/unicode/regex.h"
29 29
30 namespace policy { 30 namespace policy {
31 31
32 namespace { 32 namespace {
33 33
34 // The URL for the device management server. 34 // The URL for the enterprise device management server.
35 const char kDefaultDeviceManagementServerUrl[] = 35 const char kDefaultEnterpriseDeviceManagementServerUrl[] =
36 "https://m.google.com/devicemanagement/data/api";
37
38 // TODO(davidyu): use the right URL once the server is ready.
39 // The URL for the consumer device management server.
40 const char kDefaultConsumerDeviceManagementServerUrl[] =
36 "https://m.google.com/devicemanagement/data/api"; 41 "https://m.google.com/devicemanagement/data/api";
37 42
38 // Used in BrowserPolicyConnector::SetPolicyProviderForTesting. 43 // Used in BrowserPolicyConnector::SetPolicyProviderForTesting.
39 bool g_created_policy_service = false; 44 bool g_created_policy_service = false;
40 ConfigurationPolicyProvider* g_testing_provider = NULL; 45 ConfigurationPolicyProvider* g_testing_provider = NULL;
41 46
42 // Returns true if |domain| matches the regex |pattern|. 47 // Returns true if |domain| matches the regex |pattern|.
43 bool MatchDomain(const base::string16& domain, const base::string16& pattern) { 48 bool MatchDomain(const base::string16& domain, const base::string16& pattern) {
44 UErrorCode status = U_ZERO_ERROR; 49 UErrorCode status = U_ZERO_ERROR;
45 const icu::UnicodeString icu_pattern(pattern.data(), pattern.length()); 50 const icu::UnicodeString icu_pattern(pattern.data(), pattern.length());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // This usually means it's an early shutdown and 83 // This usually means it's an early shutdown and
79 // BrowserProcessImpl::StartTearDown() wasn't invoked. 84 // BrowserProcessImpl::StartTearDown() wasn't invoked.
80 // Cleanup properly in those cases and avoid crashing the ToastCrasher test. 85 // Cleanup properly in those cases and avoid crashing the ToastCrasher test.
81 Shutdown(); 86 Shutdown();
82 } 87 }
83 } 88 }
84 89
85 void BrowserPolicyConnector::Init( 90 void BrowserPolicyConnector::Init(
86 PrefService* local_state, 91 PrefService* local_state,
87 scoped_refptr<net::URLRequestContextGetter> request_context, 92 scoped_refptr<net::URLRequestContextGetter> request_context,
88 scoped_ptr<DeviceManagementService> device_management_service) { 93 ScopedVector<DeviceManagementService> device_management_services) {
89 DCHECK(!is_initialized()); 94 DCHECK(!is_initialized());
90 95
91 device_management_service_ = device_management_service.Pass(); 96 device_management_services_ = device_management_services.Pass();
92 97
93 if (g_testing_provider) 98 if (g_testing_provider)
94 g_testing_provider->Init(GetSchemaRegistry()); 99 g_testing_provider->Init(GetSchemaRegistry());
95 for (size_t i = 0; i < policy_providers_.size(); ++i) 100 for (size_t i = 0; i < policy_providers_.size(); ++i)
96 policy_providers_[i]->Init(GetSchemaRegistry()); 101 policy_providers_[i]->Init(GetSchemaRegistry());
97 102
98 policy_statistics_collector_.reset( 103 policy_statistics_collector_.reset(
99 new policy::PolicyStatisticsCollector( 104 new policy::PolicyStatisticsCollector(
100 base::Bind(&GetChromePolicyDetails), 105 base::Bind(&GetChromePolicyDetails),
101 GetChromeSchema(), 106 GetChromeSchema(),
102 GetPolicyService(), 107 GetPolicyService(),
103 local_state, 108 local_state,
104 base::MessageLoop::current()->message_loop_proxy())); 109 base::MessageLoop::current()->message_loop_proxy()));
105 policy_statistics_collector_->Initialize(); 110 policy_statistics_collector_->Initialize();
106 111
107 is_initialized_ = true; 112 is_initialized_ = true;
108 } 113 }
109 114
110 void BrowserPolicyConnector::Shutdown() { 115 void BrowserPolicyConnector::Shutdown() {
111 is_initialized_ = false; 116 is_initialized_ = false;
112 if (g_testing_provider) 117 if (g_testing_provider)
113 g_testing_provider->Shutdown(); 118 g_testing_provider->Shutdown();
114 for (size_t i = 0; i < policy_providers_.size(); ++i) 119 for (size_t i = 0; i < policy_providers_.size(); ++i)
115 policy_providers_[i]->Shutdown(); 120 policy_providers_[i]->Shutdown();
116 // Drop g_testing_provider so that tests executed with --single_process can 121 // Drop g_testing_provider so that tests executed with --single_process can
117 // call SetPolicyProviderForTesting() again. It is still owned by the test. 122 // call SetPolicyProviderForTesting() again. It is still owned by the test.
118 g_testing_provider = NULL; 123 g_testing_provider = NULL;
119 device_management_service_.reset(); 124 device_management_services_.clear();
120 } 125 }
121 126
122 PolicyService* BrowserPolicyConnector::GetPolicyService() { 127 PolicyService* BrowserPolicyConnector::GetPolicyService() {
123 if (!policy_service_) { 128 if (!policy_service_) {
124 g_created_policy_service = true; 129 g_created_policy_service = true;
125 std::vector<ConfigurationPolicyProvider*> providers; 130 std::vector<ConfigurationPolicyProvider*> providers;
126 if (g_testing_provider) { 131 if (g_testing_provider) {
127 providers.push_back(g_testing_provider); 132 providers.push_back(g_testing_provider);
128 } else { 133 } else {
129 providers.resize(policy_providers_.size()); 134 providers.resize(policy_providers_.size());
(...skipping 15 matching lines...) Expand all
145 const Schema& BrowserPolicyConnector::GetChromeSchema() const { 150 const Schema& BrowserPolicyConnector::GetChromeSchema() const {
146 return chrome_schema_; 151 return chrome_schema_;
147 } 152 }
148 153
149 CombinedSchemaRegistry* BrowserPolicyConnector::GetSchemaRegistry() { 154 CombinedSchemaRegistry* BrowserPolicyConnector::GetSchemaRegistry() {
150 return &schema_registry_; 155 return &schema_registry_;
151 } 156 }
152 157
153 void BrowserPolicyConnector::ScheduleServiceInitialization( 158 void BrowserPolicyConnector::ScheduleServiceInitialization(
154 int64 delay_milliseconds) { 159 int64 delay_milliseconds) {
155 // Skip device initialization if the BrowserPolicyConnector was never 160 // Skip device initialization if the BrowserPolicyConnector was never
bartfab (slow) 2014/04/23 12:17:18 Nit: That comment is no longer necessary. If |devi
davidyu 2014/04/23 12:56:58 Code reverted.
156 // initialized (unit tests). 161 // initialized (unit tests).
157 if (device_management_service_) 162 for (ScopedVector<DeviceManagementService>::const_iterator i =
bartfab (slow) 2014/04/23 12:17:18 Nit: The most common variable name for iterators i
davidyu 2014/04/23 12:56:58 Code removed.
158 device_management_service_->ScheduleInitialization(delay_milliseconds); 163 device_management_services_.begin();
164 i != device_management_services_.end();
165 ++i) {
166 (*i)->ScheduleInitialization(delay_milliseconds);
167 }
159 } 168 }
160 169
161 const ConfigurationPolicyHandlerList* 170 const ConfigurationPolicyHandlerList*
162 BrowserPolicyConnector::GetHandlerList() const { 171 BrowserPolicyConnector::GetHandlerList() const {
163 return handler_list_.get(); 172 return handler_list_.get();
164 } 173 }
165 174
175 DeviceManagementService* BrowserPolicyConnector::GetDeviceManagementService(
176 ManagementMode management_mode) {
177 return device_management_services_[management_mode];
bartfab (slow) 2014/04/23 12:17:18 Nit: Add DCHECKs to verify that we were not given
davidyu 2014/04/23 12:56:58 Done.
178 }
179
166 // static 180 // static
167 void BrowserPolicyConnector::SetPolicyProviderForTesting( 181 void BrowserPolicyConnector::SetPolicyProviderForTesting(
168 ConfigurationPolicyProvider* provider) { 182 ConfigurationPolicyProvider* provider) {
169 // If this function is used by a test then it must be called before the 183 // If this function is used by a test then it must be called before the
170 // browser is created, and GetPolicyService() gets called. 184 // browser is created, and GetPolicyService() gets called.
171 CHECK(!g_created_policy_service); 185 CHECK(!g_created_policy_service);
172 DCHECK(!g_testing_provider); 186 DCHECK(!g_testing_provider);
173 g_testing_provider = provider; 187 g_testing_provider = provider;
174 } 188 }
175 189
(...skipping 25 matching lines...) Expand all
201 gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); 215 gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)));
202 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { 216 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) {
203 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]); 217 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]);
204 if (MatchDomain(domain, pattern)) 218 if (MatchDomain(domain, pattern))
205 return true; 219 return true;
206 } 220 }
207 return false; 221 return false;
208 } 222 }
209 223
210 // static 224 // static
211 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { 225 std::string BrowserPolicyConnector::GetDeviceManagementUrl(
226 ManagementMode management_mode) {
212 CommandLine* command_line = CommandLine::ForCurrentProcess(); 227 CommandLine* command_line = CommandLine::ForCurrentProcess();
213 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) 228 switch (management_mode) {
214 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); 229 case ENTERPRISE_MANAGED:
215 else 230 if (command_line->HasSwitch(switches::kDeviceManagementUrl))
216 return kDefaultDeviceManagementServerUrl; 231 return command_line->GetSwitchValueASCII(
232 switches::kDeviceManagementUrl);
233 else
234 return kDefaultEnterpriseDeviceManagementServerUrl;
235
236 case CONSUMER_MANAGED:
237 if (command_line->HasSwitch(switches::kConsumerDeviceManagementUrl))
238 return command_line->GetSwitchValueASCII(
239 switches::kConsumerDeviceManagementUrl);
240 else
241 return kDefaultConsumerDeviceManagementServerUrl;
242
243 default:
244 return std::string();
bartfab (slow) 2014/04/23 12:17:18 Nit: Add a NOTREACHED().
davidyu 2014/04/23 12:56:58 Done.
245 }
217 } 246 }
218 247
219 // static 248 // static
220 void BrowserPolicyConnector::RegisterPrefs(PrefRegistrySimple* registry) { 249 void BrowserPolicyConnector::RegisterPrefs(PrefRegistrySimple* registry) {
221 registry->RegisterIntegerPref( 250 registry->RegisterIntegerPref(
222 policy_prefs::kUserPolicyRefreshRate, 251 policy_prefs::kUserPolicyRefreshRate,
223 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs); 252 CloudPolicyRefreshScheduler::kDefaultRefreshDelayMs);
224 } 253 }
225 254
226 void BrowserPolicyConnector::AddPolicyProvider( 255 void BrowserPolicyConnector::AddPolicyProvider(
227 scoped_ptr<ConfigurationPolicyProvider> provider) { 256 scoped_ptr<ConfigurationPolicyProvider> provider) {
228 policy_providers_.push_back(provider.release()); 257 policy_providers_.push_back(provider.release());
229 } 258 }
230 259
231 void BrowserPolicyConnector::SetPlatformPolicyProvider( 260 void BrowserPolicyConnector::SetPlatformPolicyProvider(
232 scoped_ptr<ConfigurationPolicyProvider> provider) { 261 scoped_ptr<ConfigurationPolicyProvider> provider) {
233 CHECK(!platform_policy_provider_); 262 CHECK(!platform_policy_provider_);
234 platform_policy_provider_ = provider.get(); 263 platform_policy_provider_ = provider.get();
235 AddPolicyProvider(provider.Pass()); 264 AddPolicyProvider(provider.Pass());
236 } 265 }
237 266
238 } // namespace policy 267 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698