| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 StartupCustomizationDocument::~StartupCustomizationDocument() {} | 160 StartupCustomizationDocument::~StartupCustomizationDocument() {} |
| 161 | 161 |
| 162 StartupCustomizationDocument* StartupCustomizationDocument::GetInstance() { | 162 StartupCustomizationDocument* StartupCustomizationDocument::GetInstance() { |
| 163 return Singleton<StartupCustomizationDocument, | 163 return Singleton<StartupCustomizationDocument, |
| 164 DefaultSingletonTraits<StartupCustomizationDocument> >::get(); | 164 DefaultSingletonTraits<StartupCustomizationDocument> >::get(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void StartupCustomizationDocument::Init( | 167 void StartupCustomizationDocument::Init( |
| 168 chromeos::system::StatisticsProvider* statistics_provider) { | 168 chromeos::system::StatisticsProvider* statistics_provider) { |
| 169 if (!IsReady()) | 169 if (IsReady()) { |
| 170 return; | 170 root_->GetString(kInitialLocaleAttr, &initial_locale_); |
| 171 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); |
| 172 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); |
| 173 root_->GetString(kRegistrationUrlAttr, ®istration_url_); |
| 171 | 174 |
| 172 root_->GetString(kInitialLocaleAttr, &initial_locale_); | 175 std::string hwid; |
| 173 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); | 176 if (statistics_provider->GetMachineStatistic(kHardwareClass, &hwid)) { |
| 174 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); | 177 ListValue* hwid_list = NULL; |
| 175 root_->GetString(kRegistrationUrlAttr, ®istration_url_); | 178 if (root_->GetList(kHwidMapAttr, &hwid_list)) { |
| 179 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { |
| 180 DictionaryValue* hwid_dictionary = NULL; |
| 181 std::string hwid_mask; |
| 182 if (hwid_list->GetDictionary(i, &hwid_dictionary) && |
| 183 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { |
| 184 if (MatchPattern(hwid, hwid_mask)) { |
| 185 // If HWID for this machine matches some mask, use HWID specific |
| 186 // settings. |
| 187 std::string result; |
| 188 if (hwid_dictionary->GetString(kInitialLocaleAttr, &result)) |
| 189 initial_locale_ = result; |
| 176 | 190 |
| 177 std::string hwid; | 191 if (hwid_dictionary->GetString(kInitialTimezoneAttr, &result)) |
| 178 if (statistics_provider->GetMachineStatistic(kHardwareClass, &hwid)) { | 192 initial_timezone_ = result; |
| 179 ListValue* hwid_list = NULL; | |
| 180 if (root_->GetList(kHwidMapAttr, &hwid_list)) { | |
| 181 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { | |
| 182 DictionaryValue* hwid_dictionary = NULL; | |
| 183 std::string hwid_mask; | |
| 184 if (hwid_list->GetDictionary(i, &hwid_dictionary) && | |
| 185 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { | |
| 186 if (MatchPattern(hwid, hwid_mask)) { | |
| 187 // If HWID for this machine matches some mask, use HWID specific | |
| 188 // settings. | |
| 189 std::string result; | |
| 190 if (hwid_dictionary->GetString(kInitialLocaleAttr, &result)) | |
| 191 initial_locale_ = result; | |
| 192 | 193 |
| 193 if (hwid_dictionary->GetString(kInitialTimezoneAttr, &result)) | 194 if (hwid_dictionary->GetString(kKeyboardLayoutAttr, &result)) |
| 194 initial_timezone_ = result; | 195 keyboard_layout_ = result; |
| 195 | 196 } |
| 196 if (hwid_dictionary->GetString(kKeyboardLayoutAttr, &result)) | 197 // Don't break here to allow other entires to be applied if match. |
| 197 keyboard_layout_ = result; | 198 } else { |
| 199 LOG(ERROR) << "Syntax error in customization manifest"; |
| 198 } | 200 } |
| 199 // Don't break here to allow other entires to be applied if match. | |
| 200 } else { | |
| 201 LOG(ERROR) << "Syntax error in customization manifest"; | |
| 202 } | 201 } |
| 203 } | 202 } |
| 203 } else { |
| 204 LOG(ERROR) << "HWID is missing in machine statistics"; |
| 204 } | 205 } |
| 205 } else { | |
| 206 LOG(ERROR) << "HWID is missing in machine statistics"; | |
| 207 } | 206 } |
| 208 | 207 |
| 208 // If manifest doesn't exist still apply values from VPD. |
| 209 statistics_provider->GetMachineStatistic(kInitialLocaleAttr, | 209 statistics_provider->GetMachineStatistic(kInitialLocaleAttr, |
| 210 &initial_locale_); | 210 &initial_locale_); |
| 211 statistics_provider->GetMachineStatistic(kInitialTimezoneAttr, | 211 statistics_provider->GetMachineStatistic(kInitialTimezoneAttr, |
| 212 &initial_timezone_); | 212 &initial_timezone_); |
| 213 statistics_provider->GetMachineStatistic(kKeyboardLayoutAttr, | 213 statistics_provider->GetMachineStatistic(kKeyboardLayoutAttr, |
| 214 &keyboard_layout_); | 214 &keyboard_layout_); |
| 215 } | 215 } |
| 216 | 216 |
| 217 std::string StartupCustomizationDocument::GetHelpPage( | 217 std::string StartupCustomizationDocument::GetHelpPage( |
| 218 const std::string& locale) const { | 218 const std::string& locale) const { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 DictionaryValue* carrier_deal = NULL; | 409 DictionaryValue* carrier_deal = NULL; |
| 410 if (carriers->GetDictionary(*iter, &carrier_deal)) { | 410 if (carriers->GetDictionary(*iter, &carrier_deal)) { |
| 411 carrier_deals_[*iter] = new CarrierDeal(carrier_deal); | 411 carrier_deals_[*iter] = new CarrierDeal(carrier_deal); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 return true; | 415 return true; |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace chromeos | 418 } // namespace chromeos |
| OLD | NEW |