OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/customization_document.h" | 5 #include "chrome/browser/chromeos/customization_document.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 // "ServicesCustomization.LoadResult" histogram. | 102 // "ServicesCustomization.LoadResult" histogram. |
103 // It is append-only enum due to use in a histogram! | 103 // It is append-only enum due to use in a histogram! |
104 enum HistogramServicesCustomizationLoadResult { | 104 enum HistogramServicesCustomizationLoadResult { |
105 HISTOGRAM_LOAD_RESULT_SUCCESS = 0, | 105 HISTOGRAM_LOAD_RESULT_SUCCESS = 0, |
106 HISTOGRAM_LOAD_RESULT_FILE_NOT_FOUND = 1, | 106 HISTOGRAM_LOAD_RESULT_FILE_NOT_FOUND = 1, |
107 HISTOGRAM_LOAD_RESULT_PARSING_ERROR = 2, | 107 HISTOGRAM_LOAD_RESULT_PARSING_ERROR = 2, |
108 HISTOGRAM_LOAD_RESULT_RETRIES_FAIL = 3, | 108 HISTOGRAM_LOAD_RESULT_RETRIES_FAIL = 3, |
109 HISTOGRAM_LOAD_RESULT_MAX_VALUE = 4 | 109 HISTOGRAM_LOAD_RESULT_MAX_VALUE = 4 |
110 }; | 110 }; |
111 | 111 |
112 // In tests we need to enforce initial settings. | |
113 const char* enforce_initial_locale = NULL; | |
114 const char* enforce_keyboard_layout = NULL; | |
115 | |
112 void LogManifestLoadResult(HistogramServicesCustomizationLoadResult result) { | 116 void LogManifestLoadResult(HistogramServicesCustomizationLoadResult result) { |
113 UMA_HISTOGRAM_ENUMERATION("ServicesCustomization.LoadResult", | 117 UMA_HISTOGRAM_ENUMERATION("ServicesCustomization.LoadResult", |
114 result, | 118 result, |
115 HISTOGRAM_LOAD_RESULT_MAX_VALUE); | 119 HISTOGRAM_LOAD_RESULT_MAX_VALUE); |
116 } | 120 } |
117 | 121 |
118 std::string GetLocaleSpecificStringImpl( | 122 std::string GetLocaleSpecificStringImpl( |
119 const base::DictionaryValue* root, | 123 const base::DictionaryValue* root, |
120 const std::string& locale, | 124 const std::string& locale, |
121 const std::string& dictionary_name, | 125 const std::string& dictionary_name, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 DefaultSingletonTraits<StartupCustomizationDocument> >::get(); | 283 DefaultSingletonTraits<StartupCustomizationDocument> >::get(); |
280 } | 284 } |
281 | 285 |
282 void StartupCustomizationDocument::Init( | 286 void StartupCustomizationDocument::Init( |
283 system::StatisticsProvider* statistics_provider) { | 287 system::StatisticsProvider* statistics_provider) { |
284 if (IsReady()) { | 288 if (IsReady()) { |
285 root_->GetString(kInitialLocaleAttr, &initial_locale_); | 289 root_->GetString(kInitialLocaleAttr, &initial_locale_); |
286 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); | 290 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); |
287 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); | 291 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); |
288 | 292 |
293 if (enforce_initial_locale) | |
Dmitry Polukhin
2014/09/30 09:29:54
You override before and after checking machine sta
| |
294 initial_locale_ = enforce_initial_locale; | |
295 | |
296 if (enforce_keyboard_layout) | |
297 keyboard_layout_ = enforce_keyboard_layout; | |
298 | |
289 std::string hwid; | 299 std::string hwid; |
290 if (statistics_provider->GetMachineStatistic( | 300 if (statistics_provider->GetMachineStatistic( |
291 system::kHardwareClassKey, &hwid)) { | 301 system::kHardwareClassKey, &hwid)) { |
292 base::ListValue* hwid_list = NULL; | 302 base::ListValue* hwid_list = NULL; |
293 if (root_->GetList(kHwidMapAttr, &hwid_list)) { | 303 if (root_->GetList(kHwidMapAttr, &hwid_list)) { |
294 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { | 304 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { |
295 base::DictionaryValue* hwid_dictionary = NULL; | 305 base::DictionaryValue* hwid_dictionary = NULL; |
296 std::string hwid_mask; | 306 std::string hwid_mask; |
297 if (hwid_list->GetDictionary(i, &hwid_dictionary) && | 307 if (hwid_list->GetDictionary(i, &hwid_dictionary) && |
298 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { | 308 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { |
(...skipping 21 matching lines...) Expand all Loading... | |
320 } | 330 } |
321 } | 331 } |
322 | 332 |
323 // If manifest doesn't exist still apply values from VPD. | 333 // If manifest doesn't exist still apply values from VPD. |
324 statistics_provider->GetMachineStatistic(kInitialLocaleAttr, | 334 statistics_provider->GetMachineStatistic(kInitialLocaleAttr, |
325 &initial_locale_); | 335 &initial_locale_); |
326 statistics_provider->GetMachineStatistic(kInitialTimezoneAttr, | 336 statistics_provider->GetMachineStatistic(kInitialTimezoneAttr, |
327 &initial_timezone_); | 337 &initial_timezone_); |
328 statistics_provider->GetMachineStatistic(kKeyboardLayoutAttr, | 338 statistics_provider->GetMachineStatistic(kKeyboardLayoutAttr, |
329 &keyboard_layout_); | 339 &keyboard_layout_); |
340 if (enforce_initial_locale) | |
341 initial_locale_ = enforce_initial_locale; | |
342 | |
343 if (enforce_keyboard_layout) | |
344 keyboard_layout_ = enforce_keyboard_layout; | |
345 | |
330 configured_locales_.resize(0); | 346 configured_locales_.resize(0); |
331 base::SplitString(initial_locale_, ',', &configured_locales_); | 347 base::SplitString(initial_locale_, ',', &configured_locales_); |
332 | 348 |
333 // Convert ICU locale to chrome ("en_US" to "en-US", etc.). | 349 // Convert ICU locale to chrome ("en_US" to "en-US", etc.). |
334 std::for_each(configured_locales_.begin(), | 350 std::for_each(configured_locales_.begin(), |
335 configured_locales_.end(), | 351 configured_locales_.end(), |
336 l10n_util::GetCanonicalLocale); | 352 l10n_util::GetCanonicalLocale); |
337 | 353 |
338 // Let's always have configured_locales_.front() a valid entry. | 354 // Let's always have configured_locales_.front() a valid entry. |
339 if (configured_locales_.size() == 0) | 355 if (configured_locales_.size() == 0) |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 | 973 |
958 apply_tasks_success_ += success; | 974 apply_tasks_success_ += success; |
959 | 975 |
960 if (apply_tasks_started_ != apply_tasks_finished_) | 976 if (apply_tasks_started_ != apply_tasks_finished_) |
961 return; | 977 return; |
962 | 978 |
963 if (apply_tasks_success_ == apply_tasks_finished_) | 979 if (apply_tasks_success_ == apply_tasks_finished_) |
964 SetApplied(true); | 980 SetApplied(true); |
965 } | 981 } |
966 | 982 |
983 void SetEnforceInitialLocaleForTesting(const char* locale) { | |
984 enforce_initial_locale = locale; | |
985 } | |
986 | |
987 void SetEnforceInitialKeyboardForTesting(const char* keyboard) { | |
988 enforce_keyboard_layout = keyboard; | |
989 } | |
990 | |
967 } // namespace chromeos | 991 } // namespace chromeos |
OLD | NEW |