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

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

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
16 #include "base/prefs/pref_registry_simple.h" 16 #include "base/prefs/pref_registry_simple.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" 19 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
20 #include "components/policy/core/common/cloud/device_management_service.h" 20 #include "components/policy/core/common/cloud/device_management_service.h"
21 #include "components/policy/core/common/configuration_policy_provider.h" 21 #include "components/policy/core/common/configuration_policy_provider.h"
22 #include "components/policy/core/common/policy_namespace.h" 22 #include "components/policy/core/common/policy_namespace.h"
23 #include "components/policy/core/common/policy_pref_names.h" 23 #include "components/policy/core/common/policy_pref_names.h"
24 #include "components/policy/core/common/policy_service_impl.h" 24 #include "components/policy/core/common/policy_service_impl.h"
25 #include "components/policy/core/common/policy_statistics_collector.h" 25 #include "components/policy/core/common/policy_statistics_collector.h"
26 #include "components/policy/core/common/policy_switches.h" 26 #include "components/policy/core/common/policy_switches.h"
27 #include "components/user_manager/user_id.h"
27 #include "google_apis/gaia/gaia_auth_util.h" 28 #include "google_apis/gaia/gaia_auth_util.h"
28 #include "net/url_request/url_request_context_getter.h" 29 #include "net/url_request/url_request_context_getter.h"
29 #include "policy/policy_constants.h" 30 #include "policy/policy_constants.h"
30 #include "third_party/icu/source/i18n/unicode/regex.h" 31 #include "third_party/icu/source/i18n/unicode/regex.h"
31 32
32 namespace policy { 33 namespace policy {
33 34
34 namespace { 35 namespace {
35 36
36 // The URL for the device management server. 37 // The URL for the device management server.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void BrowserPolicyConnector::SetPolicyProviderForTesting( 208 void BrowserPolicyConnector::SetPolicyProviderForTesting(
208 ConfigurationPolicyProvider* provider) { 209 ConfigurationPolicyProvider* provider) {
209 // If this function is used by a test then it must be called before the 210 // If this function is used by a test then it must be called before the
210 // browser is created, and GetPolicyService() gets called. 211 // browser is created, and GetPolicyService() gets called.
211 CHECK(!g_created_policy_service); 212 CHECK(!g_created_policy_service);
212 DCHECK(!g_testing_provider); 213 DCHECK(!g_testing_provider);
213 g_testing_provider = provider; 214 g_testing_provider = provider;
214 } 215 }
215 216
216 // static 217 // static
217 bool BrowserPolicyConnector::IsNonEnterpriseUser(const std::string& username) { 218 bool BrowserPolicyConnector::IsNonEnterpriseUser(const user_manager::UserID& use r_id) {
218 if (username.empty() || username.find('@') == std::string::npos) { 219 const std::string& email = user_id.GetUserEmail();
219 // An empty username means incognito user in case of ChromiumOS and 220 if (email.empty() || email.find('@') == std::string::npos) {
221 // An empty email means incognito user in case of ChromiumOS and
220 // no logged-in user in case of Chromium (SigninService). Many tests use 222 // no logged-in user in case of Chromium (SigninService). Many tests use
221 // nonsense email addresses (e.g. 'test') so treat those as non-enterprise 223 // nonsense email addresses (e.g. 'test') so treat those as non-enterprise
222 // users. 224 // users.
223 return true; 225 return true;
224 } 226 }
225 const base::string16 domain = base::UTF8ToUTF16( 227 const base::string16 domain = base::UTF8ToUTF16(
226 gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); 228 gaia::ExtractDomainName(gaia::CanonicalizeEmail(email)));
227 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { 229 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) {
228 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]); 230 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]);
229 if (MatchDomain(domain, pattern, i)) 231 if (MatchDomain(domain, pattern, i))
230 return true; 232 return true;
231 } 233 }
232 return false; 234 return false;
233 } 235 }
234 236
235 // static 237 // static
236 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { 238 std::string BrowserPolicyConnector::GetDeviceManagementUrl() {
(...skipping 17 matching lines...) Expand all
254 } 256 }
255 257
256 void BrowserPolicyConnector::SetPlatformPolicyProvider( 258 void BrowserPolicyConnector::SetPlatformPolicyProvider(
257 scoped_ptr<ConfigurationPolicyProvider> provider) { 259 scoped_ptr<ConfigurationPolicyProvider> provider) {
258 CHECK(!platform_policy_provider_); 260 CHECK(!platform_policy_provider_);
259 platform_policy_provider_ = provider.get(); 261 platform_policy_provider_ = provider.get();
260 AddPolicyProvider(provider.Pass()); 262 AddPolicyProvider(provider.Pass());
261 } 263 }
262 264
263 } // namespace policy 265 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698