OLD | NEW |
---|---|
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/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 18 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
18 #include "components/policy/core/common/cloud/device_management_service.h" | 19 #include "components/policy/core/common/cloud/device_management_service.h" |
19 #include "components/policy/core/common/configuration_policy_provider.h" | 20 #include "components/policy/core/common/configuration_policy_provider.h" |
20 #include "components/policy/core/common/policy_namespace.h" | 21 #include "components/policy/core/common/policy_namespace.h" |
21 #include "components/policy/core/common/policy_pref_names.h" | 22 #include "components/policy/core/common/policy_pref_names.h" |
22 #include "components/policy/core/common/policy_service_impl.h" | 23 #include "components/policy/core/common/policy_service_impl.h" |
23 #include "components/policy/core/common/policy_statistics_collector.h" | 24 #include "components/policy/core/common/policy_statistics_collector.h" |
24 #include "components/policy/core/common/policy_switches.h" | 25 #include "components/policy/core/common/policy_switches.h" |
25 #include "google_apis/gaia/gaia_auth_util.h" | 26 #include "google_apis/gaia/gaia_auth_util.h" |
26 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
27 #include "policy/policy_constants.h" | 28 #include "policy/policy_constants.h" |
28 #include "third_party/icu/source/i18n/unicode/regex.h" | 29 #include "third_party/icu/source/i18n/unicode/regex.h" |
29 | 30 |
30 namespace policy { | 31 namespace policy { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // The URL for the device management server. | 35 // The URL for the device management server. |
35 const char kDefaultDeviceManagementServerUrl[] = | 36 const char kDefaultDeviceManagementServerUrl[] = |
36 "https://m.google.com/devicemanagement/data/api"; | 37 "https://m.google.com/devicemanagement/data/api"; |
37 | 38 |
38 // Used in BrowserPolicyConnector::SetPolicyProviderForTesting. | 39 // Used in BrowserPolicyConnector::SetPolicyProviderForTesting. |
39 bool g_created_policy_service = false; | 40 bool g_created_policy_service = false; |
40 ConfigurationPolicyProvider* g_testing_provider = NULL; | 41 ConfigurationPolicyProvider* g_testing_provider = NULL; |
41 | 42 |
42 // Returns true if |domain| matches the regex |pattern|. | 43 // Returns true if |domain| matches the regex |pattern|. |
43 bool MatchDomain(const base::string16& domain, const base::string16& pattern) { | 44 bool MatchDomain(const base::string16& domain, const base::string16& pattern, |
45 size_t index, size_t max) { | |
44 UErrorCode status = U_ZERO_ERROR; | 46 UErrorCode status = U_ZERO_ERROR; |
45 const icu::UnicodeString icu_pattern(pattern.data(), pattern.length()); | 47 const icu::UnicodeString icu_pattern(pattern.data(), pattern.length()); |
46 icu::RegexMatcher matcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status); | 48 icu::RegexMatcher matcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status); |
47 if (!U_SUCCESS(status)) { | 49 if (!U_SUCCESS(status)) { |
48 // http://crbug.com/365351 - if for some reason the matcher creation fails | 50 // http://crbug.com/365351 - if for some reason the matcher creation fails |
49 // just return that the pattern doesn't match the domain. This is safe | 51 // just return that the pattern doesn't match the domain. This is safe |
50 // because the calling method (IsNonEnterpriseUser()) is just used to enable | 52 // because the calling method (IsNonEnterpriseUser()) is just used to enable |
51 // an optimization for non-enterprise users - better to skip the | 53 // an optimization for non-enterprise users - better to skip the |
52 // optimization than crash. | 54 // optimization than crash. |
53 DLOG(ERROR) << "Possible invalid domain pattern: " << pattern | 55 DLOG(ERROR) << "Possible invalid domain pattern: " << pattern |
54 << " - Error: " << status; | 56 << " - Error: " << status; |
57 UMA_HISTOGRAM_BOOLEAN("Enterprise.DomainWhitelistRegexSuccess", false); | |
58 UMA_HISTOGRAM_ENUMERATION("Enterprise.DomainWhitelistRegexFailureIndex", | |
59 index, max); | |
Joao da Silva
2014/07/11 15:13:47
WDYT of sampling the UErrorCode in "status" with U
Andrew T Wilson (Slow)
2014/07/11 15:46:21
I considered that, but I don't know what UMA_HISTO
Ilya Sherman
2014/07/11 22:54:12
UMA_HISTOGRAM_SPARSE_SLOWLY just uses a map rather
Ilya Sherman
2014/07/11 22:54:12
Hmm, I'm concerned that |max| is being passed in a
Andrew T Wilson (Slow)
2014/07/24 15:25:56
So, what's the right way to use UMA_HISTOGRAM_SPAR
Andrew T Wilson (Slow)
2014/07/24 15:25:56
Done.
Ilya Sherman
2014/07/24 17:29:32
It's up to you what values you list in histograms.
| |
55 return false; | 60 return false; |
56 } | 61 } |
62 UMA_HISTOGRAM_BOOLEAN("Enterprise.DomainWhitelistRegexSuccess", true); | |
Ilya Sherman
2014/07/11 22:54:12
Please define a wrapper method around emitting to
Andrew T Wilson (Slow)
2014/07/24 15:25:56
Done.
| |
57 icu::UnicodeString icu_input(domain.data(), domain.length()); | 63 icu::UnicodeString icu_input(domain.data(), domain.length()); |
58 matcher.reset(icu_input); | 64 matcher.reset(icu_input); |
59 status = U_ZERO_ERROR; | 65 status = U_ZERO_ERROR; |
60 UBool match = matcher.matches(status); | 66 UBool match = matcher.matches(status); |
61 DCHECK(U_SUCCESS(status)); | 67 DCHECK(U_SUCCESS(status)); |
62 return !!match; // !! == convert from UBool to bool. | 68 return !!match; // !! == convert from UBool to bool. |
63 } | 69 } |
64 | 70 |
65 } // namespace | 71 } // namespace |
66 | 72 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 L"mail\\.ru", | 210 L"mail\\.ru", |
205 L"msn\\.com", | 211 L"msn\\.com", |
206 L"qq\\.com", | 212 L"qq\\.com", |
207 L"yahoo(\\.co|\\.com|)\\.[^.]+", // yahoo.com, yahoo.co.uk, yahoo.com.tw | 213 L"yahoo(\\.co|\\.com|)\\.[^.]+", // yahoo.com, yahoo.co.uk, yahoo.com.tw |
208 L"yandex\\.ru", | 214 L"yandex\\.ru", |
209 }; | 215 }; |
210 const base::string16 domain = base::UTF8ToUTF16( | 216 const base::string16 domain = base::UTF8ToUTF16( |
211 gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); | 217 gaia::ExtractDomainName(gaia::CanonicalizeEmail(username))); |
212 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { | 218 for (size_t i = 0; i < arraysize(kNonManagedDomainPatterns); i++) { |
213 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]); | 219 base::string16 pattern = base::WideToUTF16(kNonManagedDomainPatterns[i]); |
214 if (MatchDomain(domain, pattern)) | 220 if (MatchDomain(domain, pattern, i, arraysize(kNonManagedDomainPatterns))) |
Ilya Sherman
2014/07/11 22:54:12
Hmm, UMA is not intended to be used to track user
Andrew T Wilson (Slow)
2014/07/24 15:25:56
I'm not tracking user navigation. During signin, w
Ilya Sherman
2014/07/24 17:29:32
I'm confused -- the failure is independent of the
| |
215 return true; | 221 return true; |
216 } | 222 } |
217 return false; | 223 return false; |
218 } | 224 } |
219 | 225 |
220 // static | 226 // static |
221 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { | 227 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { |
222 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 228 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
223 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) | 229 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) |
224 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); | 230 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); |
(...skipping 14 matching lines...) Expand all Loading... | |
239 } | 245 } |
240 | 246 |
241 void BrowserPolicyConnector::SetPlatformPolicyProvider( | 247 void BrowserPolicyConnector::SetPlatformPolicyProvider( |
242 scoped_ptr<ConfigurationPolicyProvider> provider) { | 248 scoped_ptr<ConfigurationPolicyProvider> provider) { |
243 CHECK(!platform_policy_provider_); | 249 CHECK(!platform_policy_provider_); |
244 platform_policy_provider_ = provider.get(); | 250 platform_policy_provider_ = provider.get(); |
245 AddPolicyProvider(provider.Pass()); | 251 AddPolicyProvider(provider.Pass()); |
246 } | 252 } |
247 | 253 |
248 } // namespace policy | 254 } // namespace policy |
OLD | NEW |