| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 std::string manifest; | 82 std::string manifest; |
| 83 if (!base::ReadFileToString(manifest_path, &manifest)) | 83 if (!base::ReadFileToString(manifest_path, &manifest)) |
| 84 return false; | 84 return false; |
| 85 return LoadManifestFromString(manifest); | 85 return LoadManifestFromString(manifest); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool CustomizationDocument::LoadManifestFromString( | 88 bool CustomizationDocument::LoadManifestFromString( |
| 89 const std::string& manifest) { | 89 const std::string& manifest) { |
| 90 int error_code = 0; | 90 int error_code = 0; |
| 91 std::string error; | 91 std::string error; |
| 92 scoped_ptr<Value> root(base::JSONReader::ReadAndReturnError(manifest, | 92 scoped_ptr<base::Value> root(base::JSONReader::ReadAndReturnError(manifest, |
| 93 base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error)); | 93 base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error)); |
| 94 if (error_code != base::JSONReader::JSON_NO_ERROR) | 94 if (error_code != base::JSONReader::JSON_NO_ERROR) |
| 95 LOG(ERROR) << error; | 95 LOG(ERROR) << error; |
| 96 DCHECK(root.get() != NULL); | 96 DCHECK(root.get() != NULL); |
| 97 if (root.get() == NULL) | 97 if (root.get() == NULL) |
| 98 return false; | 98 return false; |
| 99 DCHECK(root->GetType() == Value::TYPE_DICTIONARY); | 99 DCHECK(root->GetType() == base::Value::TYPE_DICTIONARY); |
| 100 if (root->GetType() == Value::TYPE_DICTIONARY) { | 100 if (root->GetType() == base::Value::TYPE_DICTIONARY) { |
| 101 root_.reset(static_cast<DictionaryValue*>(root.release())); | 101 root_.reset(static_cast<base::DictionaryValue*>(root.release())); |
| 102 std::string result; | 102 std::string result; |
| 103 if (root_->GetString(kVersionAttr, &result) && | 103 if (root_->GetString(kVersionAttr, &result) && |
| 104 result == accepted_version_) | 104 result == accepted_version_) |
| 105 return true; | 105 return true; |
| 106 | 106 |
| 107 LOG(ERROR) << "Wrong customization manifest version"; | 107 LOG(ERROR) << "Wrong customization manifest version"; |
| 108 root_.reset(NULL); | 108 root_.reset(NULL); |
| 109 } | 109 } |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 std::string CustomizationDocument::GetLocaleSpecificString( | 113 std::string CustomizationDocument::GetLocaleSpecificString( |
| 114 const std::string& locale, | 114 const std::string& locale, |
| 115 const std::string& dictionary_name, | 115 const std::string& dictionary_name, |
| 116 const std::string& entry_name) const { | 116 const std::string& entry_name) const { |
| 117 DictionaryValue* dictionary_content = NULL; | 117 base::DictionaryValue* dictionary_content = NULL; |
| 118 if (!root_.get() || | 118 if (!root_.get() || |
| 119 !root_->GetDictionary(dictionary_name, &dictionary_content)) | 119 !root_->GetDictionary(dictionary_name, &dictionary_content)) |
| 120 return std::string(); | 120 return std::string(); |
| 121 | 121 |
| 122 DictionaryValue* locale_dictionary = NULL; | 122 base::DictionaryValue* locale_dictionary = NULL; |
| 123 if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { | 123 if (dictionary_content->GetDictionary(locale, &locale_dictionary)) { |
| 124 std::string result; | 124 std::string result; |
| 125 if (locale_dictionary->GetString(entry_name, &result)) | 125 if (locale_dictionary->GetString(entry_name, &result)) |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 | 128 |
| 129 DictionaryValue* default_dictionary = NULL; | 129 base::DictionaryValue* default_dictionary = NULL; |
| 130 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { | 130 if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) { |
| 131 std::string result; | 131 std::string result; |
| 132 if (default_dictionary->GetString(entry_name, &result)) | 132 if (default_dictionary->GetString(entry_name, &result)) |
| 133 return result; | 133 return result; |
| 134 } | 134 } |
| 135 | 135 |
| 136 return std::string(); | 136 return std::string(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // StartupCustomizationDocument implementation. -------------------------------- | 139 // StartupCustomizationDocument implementation. -------------------------------- |
| (...skipping 28 matching lines...) Expand all Loading... |
| 168 chromeos::system::StatisticsProvider* statistics_provider) { | 168 chromeos::system::StatisticsProvider* statistics_provider) { |
| 169 if (IsReady()) { | 169 if (IsReady()) { |
| 170 root_->GetString(kInitialLocaleAttr, &initial_locale_); | 170 root_->GetString(kInitialLocaleAttr, &initial_locale_); |
| 171 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); | 171 root_->GetString(kInitialTimezoneAttr, &initial_timezone_); |
| 172 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); | 172 root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_); |
| 173 root_->GetString(kRegistrationUrlAttr, ®istration_url_); | 173 root_->GetString(kRegistrationUrlAttr, ®istration_url_); |
| 174 | 174 |
| 175 std::string hwid; | 175 std::string hwid; |
| 176 if (statistics_provider->GetMachineStatistic( | 176 if (statistics_provider->GetMachineStatistic( |
| 177 chromeos::system::kHardwareClassKey, &hwid)) { | 177 chromeos::system::kHardwareClassKey, &hwid)) { |
| 178 ListValue* hwid_list = NULL; | 178 base::ListValue* hwid_list = NULL; |
| 179 if (root_->GetList(kHwidMapAttr, &hwid_list)) { | 179 if (root_->GetList(kHwidMapAttr, &hwid_list)) { |
| 180 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { | 180 for (size_t i = 0; i < hwid_list->GetSize(); ++i) { |
| 181 DictionaryValue* hwid_dictionary = NULL; | 181 base::DictionaryValue* hwid_dictionary = NULL; |
| 182 std::string hwid_mask; | 182 std::string hwid_mask; |
| 183 if (hwid_list->GetDictionary(i, &hwid_dictionary) && | 183 if (hwid_list->GetDictionary(i, &hwid_dictionary) && |
| 184 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { | 184 hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) { |
| 185 if (MatchPattern(hwid, hwid_mask)) { | 185 if (MatchPattern(hwid, hwid_mask)) { |
| 186 // If HWID for this machine matches some mask, use HWID specific | 186 // If HWID for this machine matches some mask, use HWID specific |
| 187 // settings. | 187 // settings. |
| 188 std::string result; | 188 std::string result; |
| 189 if (hwid_dictionary->GetString(kInitialLocaleAttr, &result)) | 189 if (hwid_dictionary->GetString(kInitialLocaleAttr, &result)) |
| 190 initial_locale_ = result; | 190 initial_locale_ = result; |
| 191 | 191 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 locale, kAppContentAttr, kInitialStartPageAttr); | 337 locale, kAppContentAttr, kInitialStartPageAttr); |
| 338 } | 338 } |
| 339 | 339 |
| 340 std::string ServicesCustomizationDocument::GetSupportPage( | 340 std::string ServicesCustomizationDocument::GetSupportPage( |
| 341 const std::string& locale) const { | 341 const std::string& locale) const { |
| 342 return GetLocaleSpecificString( | 342 return GetLocaleSpecificString( |
| 343 locale, kAppContentAttr, kSupportPageAttr); | 343 locale, kAppContentAttr, kSupportPageAttr); |
| 344 } | 344 } |
| 345 | 345 |
| 346 } // namespace chromeos | 346 } // namespace chromeos |
| OLD | NEW |