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/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 namespace chromeos { | 84 namespace chromeos { |
85 | 85 |
86 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
87 // | 87 // |
88 // CellularConfigDocument | 88 // CellularConfigDocument |
89 // | 89 // |
90 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
91 CellularConfigDocument::CellularConfigDocument() { | 91 CellularConfigDocument::CellularConfigDocument() {} |
92 } | |
93 | |
94 CellularConfigDocument::~CellularConfigDocument() { | |
95 } | |
96 | 92 |
97 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { | 93 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { |
98 base::AutoLock create(config_lock_); | 94 base::AutoLock create(config_lock_); |
99 ErrorMap::iterator iter = error_map_.find(code); | 95 ErrorMap::iterator iter = error_map_.find(code); |
100 if (iter == error_map_.end()) | 96 if (iter == error_map_.end()) |
101 return code; | 97 return code; |
102 return iter->second; | 98 return iter->second; |
103 } | 99 } |
104 | 100 |
105 void CellularConfigDocument::LoadCellularConfigFile() { | 101 void CellularConfigDocument::LoadCellularConfigFile() { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
107 // Load partner customization startup manifest if it is available. | 103 // Load partner customization startup manifest if it is available. |
108 FilePath config_path(kCellularConfigPath); | 104 FilePath config_path(kCellularConfigPath); |
109 if (!file_util::PathExists(config_path)) | 105 if (!file_util::PathExists(config_path)) |
110 return; | 106 return; |
111 | 107 |
112 if (LoadFromFile(config_path)) { | 108 if (LoadFromFile(config_path)) { |
113 DVLOG(1) << "Cellular config file loaded: " << kCellularConfigPath; | 109 DVLOG(1) << "Cellular config file loaded: " << kCellularConfigPath; |
114 } else { | 110 } else { |
115 LOG(ERROR) << "Error loading cellular config file: " << | 111 LOG(ERROR) << "Error loading cellular config file: " << |
116 kCellularConfigPath; | 112 kCellularConfigPath; |
117 } | 113 } |
118 } | 114 } |
119 | 115 |
| 116 CellularConfigDocument::~CellularConfigDocument() {} |
| 117 |
| 118 void CellularConfigDocument::SetErrorMap( |
| 119 const ErrorMap& map) { |
| 120 base::AutoLock create(config_lock_); |
| 121 error_map_.clear(); |
| 122 error_map_.insert(map.begin(), map.end()); |
| 123 } |
| 124 |
120 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) { | 125 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) { |
121 std::string config; | 126 std::string config; |
122 if (!file_util::ReadFileToString(config_path, &config)) | 127 if (!file_util::ReadFileToString(config_path, &config)) |
123 return false; | 128 return false; |
124 | 129 |
125 scoped_ptr<Value> root( | 130 scoped_ptr<Value> root( |
126 base::JSONReader::Read(config, base::JSON_ALLOW_TRAILING_COMMAS)); | 131 base::JSONReader::Read(config, base::JSON_ALLOW_TRAILING_COMMAS)); |
127 DCHECK(root.get() != NULL); | 132 DCHECK(root.get() != NULL); |
128 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { | 133 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
129 LOG(WARNING) << "Bad cellular config file"; | 134 LOG(WARNING) << "Bad cellular config file"; |
(...skipping 16 matching lines...) Expand all Loading... |
146 if (!errors->GetString(*keys, &value)) { | 151 if (!errors->GetString(*keys, &value)) { |
147 LOG(WARNING) << "Bad cellular config error value"; | 152 LOG(WARNING) << "Bad cellular config error value"; |
148 return false; | 153 return false; |
149 } | 154 } |
150 error_map.insert(ErrorMap::value_type(*keys, value)); | 155 error_map.insert(ErrorMap::value_type(*keys, value)); |
151 } | 156 } |
152 SetErrorMap(error_map); | 157 SetErrorMap(error_map); |
153 return true; | 158 return true; |
154 } | 159 } |
155 | 160 |
156 void CellularConfigDocument::SetErrorMap( | |
157 const ErrorMap& map) { | |
158 base::AutoLock create(config_lock_); | |
159 error_map_.clear(); | |
160 error_map_.insert(map.begin(), map.end()); | |
161 } | |
162 | |
163 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
164 // | 162 // |
165 // MobileActivator | 163 // MobileActivator |
166 // | 164 // |
167 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
168 MobileActivator::MobileActivator() | 166 MobileActivator::MobileActivator() |
169 : cellular_config_(new CellularConfigDocument()), | 167 : cellular_config_(new CellularConfigDocument()), |
170 state_(PLAN_ACTIVATION_PAGE_LOADING), | 168 state_(PLAN_ACTIVATION_PAGE_LOADING), |
171 reenable_cert_check_(false), | 169 reenable_cert_check_(false), |
172 evaluating_(false), | 170 evaluating_(false), |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 value->SetString("IMEI", device->imei()); | 1052 value->SetString("IMEI", device->imei()); |
1055 value->SetString("MDN", device->mdn()); | 1053 value->SetString("MDN", device->mdn()); |
1056 } | 1054 } |
1057 } | 1055 } |
1058 | 1056 |
1059 std::string MobileActivator::GetErrorMessage(const std::string& code) { | 1057 std::string MobileActivator::GetErrorMessage(const std::string& code) { |
1060 return cellular_config_->GetErrorMessage(code); | 1058 return cellular_config_->GetErrorMessage(code); |
1061 } | 1059 } |
1062 | 1060 |
1063 } // namespace chromeos | 1061 } // namespace chromeos |
OLD | NEW |