Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc

Issue 3606005: Hooked mobile activation UI with the new libcros additions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/mobile_setup_ui.h" 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h"
6 6
7 #include <map>
7 #include <string> 8 #include <string>
8 9
9 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/file_util.h"
14 #include "base/json/json_reader.h"
12 #include "base/logging.h" 15 #include "base/logging.h"
13 #include "base/string_piece.h" 16 #include "base/string_piece.h"
14 #include "base/string_util.h" 17 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 19 #include "base/values.h"
17 #include "base/weak_ptr.h" 20 #include "base/weak_ptr.h"
21 #include "chrome/browser/browser.h"
22 #include "chrome/browser/browser_list.h"
18 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/chromeos/cros/cros_library.h"
25 #include "chrome/browser/chromeos/cros/network_library.h"
26 #include "chrome/browser/chromeos/cros/system_library.h"
19 #include "chrome/browser/chrome_thread.h" 27 #include "chrome/browser/chrome_thread.h"
20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 28 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
21 #include "chrome/browser/tab_contents/tab_contents.h" 29 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/common/jstemplate_builder.h" 30 #include "chrome/common/jstemplate_builder.h"
23 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
24 #include "googleurl/src/gurl.h" 32 #include "googleurl/src/gurl.h"
25 #include "grit/browser_resources.h" 33 #include "grit/browser_resources.h"
26 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
28 #include "grit/locale_settings.h" 36 #include "grit/locale_settings.h"
29 37
30 #include "chrome/browser/chromeos/cros/cros_library.h"
31 #include "chrome/browser/chromeos/cros/network_library.h"
32 #include "chrome/browser/chromeos/cros/system_library.h"
33
34 namespace { 38 namespace {
35 39
36 // Host page JS API function names. 40 // Host page JS API function names.
37 const char kJsApiGetDeviceInfo[] = "getDeviceInfo"; 41 const char kJsApiCloseTab[] = "closeTab";
38 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; 42 const char kJsApiSetTransactionStatus[] = "setTransactionStatus";
39 43
40 const wchar_t kJsDeviceStatusChangedHandler[] = 44 const wchar_t kJsDeviceStatusChangedHandler[] =
41 L"mobile.MobileSetup.onDeviceStatusChanged"; 45 L"handler.MobileSetup.deviceStateChanged";
46
47 // Collular device states that are reported to DOM UI layer.
48 const char kStateUnknown[] = "unknown";
49 const char kStateConnecting[] = "connecting";
50 const char kStateError[] = "error";
51 const char kStateNeedsPayment[] = "payment";
52 const char kStateActivating[] = "activating";
53 const char kStateDisconnected[] = "disconnected";
54 const char kStateConnected[] = "connected";
55 const char kFailedPayment[] = "failed_payment";
56
57 // Error codes matching codes defined in the cellular config file.
58 const char kErrorDefault[] = "default";
59 const char kErrorBadConnectionPartial[] = "bad_connection_partial";
60 const char kErrorBadConnectionActivated[] = "bad_connection_activated";
61 const char kErrorRoamingOnConnection[] = "roaming_connection";
62 const char kErrorNoEVDO[] = "no_evdo";
63 const char kErrorRoamingActivation[] = "roaming_activation";
64 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated";
65 const char kErrorNoService[] = "no_service";
66 const char kFailedPaymentError[] = "failed_payment";
67
68 // Cellular configuration file path.
69 const char kCellularConfigPath[] =
70 "/usr/share/chromeos-assets/mobile/mobile_config.json";
71
72 // Cellular config file field names.
73 const char kVersionField[] = "version";
74 const char kErrorsField[] = "errors";
42 75
43 } // namespace 76 } // namespace
44 77
78 class CellularConfigDocument {
79 public:
80 CellularConfigDocument() {}
81
82 // Return error message for a given code.
83 std::string GetErrorMessage(const std::string& code);
84 const std::string& version() { return version_; }
85
86 bool LoadFromFile(const FilePath& config_path);
87
88 private:
89 std::string version_;
90 std::map<std::string, std::string> error_map_;
91
92 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument);
93 };
94
95 static std::map<std::string, std::string> error_messages_;
96
45 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { 97 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource {
46 public: 98 public:
47 MobileSetupUIHTMLSource(); 99 MobileSetupUIHTMLSource();
48 100
49 // Called when the network layer has requested a resource underneath 101 // Called when the network layer has requested a resource underneath
50 // the path we registered. 102 // the path we registered.
51 virtual void StartDataRequest(const std::string& path, 103 virtual void StartDataRequest(const std::string& path,
52 bool is_off_the_record, 104 bool is_off_the_record,
53 int request_id); 105 int request_id);
54 virtual std::string GetMimeType(const std::string&) const { 106 virtual std::string GetMimeType(const std::string&) const {
55 return "text/html"; 107 return "text/html";
56 } 108 }
57 109
58 private: 110 private:
59 ~MobileSetupUIHTMLSource() {} 111 ~MobileSetupUIHTMLSource() {}
60 112
61 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); 113 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
62 }; 114 };
63 115
64 // The handler for Javascript messages related to the "register" view. 116 // The handler for Javascript messages related to the "register" view.
65 class MobileSetupHandler : public DOMMessageHandler, 117 class MobileSetupHandler : public DOMMessageHandler,
118 public chromeos::NetworkLibrary::Observer,
66 public base::SupportsWeakPtr<MobileSetupHandler> { 119 public base::SupportsWeakPtr<MobileSetupHandler> {
67 public: 120 public:
68 MobileSetupHandler(); 121 MobileSetupHandler();
69 virtual ~MobileSetupHandler(); 122 virtual ~MobileSetupHandler();
70 123
71 // Init work after Attach. 124 // Init work after Attach.
72 void Init(); 125 void Init(TabContents* contents);
73 126
74 // DOMMessageHandler implementation. 127 // DOMMessageHandler implementation.
75 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); 128 virtual DOMMessageHandler* Attach(DOMUI* dom_ui);
76 virtual void RegisterMessages(); 129 virtual void RegisterMessages();
77 130
131 // NetworkLibrary::Observer implementation.
132 virtual void NetworkChanged(chromeos::NetworkLibrary* obj);
133
78 private: 134 private:
79 // Handlers for JS DOMUI messages. 135 // Handlers for JS DOMUI messages.
80 void HandleGetDeviceInfo(const ListValue* args); 136 void HandleCloseTab(const ListValue* args);
81 void HandleSetTransactionStatus(const ListValue* args); 137 void HandleSetTransactionStatus(const ListValue* args);
82 138
83 // Sends message to host registration page with system/user info data. 139 // Sends message to host registration page with system/user info data.
84 void SendDeviceInfo(); 140 void SendDeviceInfo();
85 141
86 // Converts device the current CelularNetork into JS object. 142 // Converts the currently active CellularNetwork device into a JS object.
87 bool GetDeviceInfo(DictionaryValue* value); 143 static bool GetDeviceInfo(DictionaryValue* value);
144 static bool ShouldReportDeviceState(std::string* state, std::string* error);
88 145
146 // Performs activation state cellular device evaluation.
147 // Returns false if device activation failed. In this case |error|
148 // will contain error message to be reported to DOM UI.
149 static bool CheckForActivationError(chromeos::CellularNetwork network,
150 std::string* error);
151
152 // Return error message for a given code.
153 static std::string GetErrorMessage(const std::string& code);
154 static void LoadCellularConfig();
155
156 static scoped_ptr<CellularConfigDocument> cellular_config_;
157
158 TabContents* tab_contents_;
89 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); 159 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
90 }; 160 };
91 161
162 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_;
163
164 ////////////////////////////////////////////////////////////////////////////////
165 //
166 // CellularConfigDocument
167 //
168 ////////////////////////////////////////////////////////////////////////////////
169
170 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) {
171 std::map<std::string, std::string>::iterator iter = error_map_.find(code);
172 if (iter == error_map_.end())
173 return code;
174 return iter->second;
175 }
176
177 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) {
178 error_map_.clear();
179
180 std::string config;
181 if (!file_util::ReadFileToString(config_path, &config))
182 return false;
183
184 scoped_ptr<Value> root(base::JSONReader::Read(config, true));
185 DCHECK(root.get() != NULL);
186 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) {
187 LOG(INFO) << "Bad cellular config file";
188 return false;
189 }
190
191 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get());
192 if (!root_dict->GetString(kVersionField, &version_)) {
193 LOG(INFO) << "Cellular config file missing version";
194 return false;
195 }
196 DictionaryValue* errors = NULL;
197 if (!root_dict->GetDictionary(kErrorsField, &errors))
198 return false;
199 for (DictionaryValue::key_iterator keys = errors->begin_keys();
200 keys != errors->end_keys();
201 ++keys) {
202 std::string value;
203 if (!errors->GetString(*keys, &value)) {
204 LOG(INFO) << "Bad cellular config error value";
205 error_map_.clear();
206 return false;
207 }
208
209 error_map_.insert(std::pair<std::string, std::string>(*keys, value));
210 }
211 return true;
212 }
213
92 //////////////////////////////////////////////////////////////////////////////// 214 ////////////////////////////////////////////////////////////////////////////////
93 // 215 //
94 // MobileSetupUIHTMLSource 216 // MobileSetupUIHTMLSource
95 // 217 //
96 //////////////////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////////////////
97 219
98 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() 220 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource()
99 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()) { 221 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()) {
100 } 222 }
101 223
102 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, 224 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path,
103 bool is_off_the_record, 225 bool is_off_the_record,
104 int request_id) { 226 int request_id) {
105 DictionaryValue strings; 227 DictionaryValue strings;
106 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); 228 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
107 strings.SetString("header", 229 strings.SetString("connecting_header",
108 l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_HEADER)); 230 l10n_util::GetStringUTF16(IDS_MOBILE_CONNECTING_HEADER));
231 strings.SetString("error_header",
232 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
233 strings.SetString("activating_header",
234 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
235 strings.SetString("completed_header",
236 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
237 strings.SetString("completed_text",
238 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
109 SetFontAndTextDirection(&strings); 239 SetFontAndTextDirection(&strings);
110 240
111 static const base::StringPiece html( 241 static const base::StringPiece html(
112 ResourceBundle::GetSharedInstance().GetRawDataResource( 242 ResourceBundle::GetSharedInstance().GetRawDataResource(
113 IDR_MOBILE_SETUP_PAGE_HTML)); 243 IDR_MOBILE_SETUP_PAGE_HTML));
114 const std::string full_html = jstemplate_builder::GetTemplatesHtml( 244 const std::string full_html = jstemplate_builder::GetTemplatesHtml(
115 html, &strings, "t" /* template root node id */); 245 html, &strings, "t" /* template root node id */);
116 246
117 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 247 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
118 html_bytes->data.resize(full_html.size()); 248 html_bytes->data.resize(full_html.size());
119 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); 249 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
120 250
121 SendResponse(request_id, html_bytes); 251 SendResponse(request_id, html_bytes);
122 } 252 }
123 253
124 //////////////////////////////////////////////////////////////////////////////// 254 ////////////////////////////////////////////////////////////////////////////////
125 // 255 //
126 // MobileSetupHandler 256 // MobileSetupHandler
127 // 257 //
128 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
129 MobileSetupHandler::MobileSetupHandler() { 259 MobileSetupHandler::MobileSetupHandler() : tab_contents_(NULL) {
130 } 260 }
131 261
132 MobileSetupHandler::~MobileSetupHandler() { 262 MobileSetupHandler::~MobileSetupHandler() {
263 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
133 } 264 }
134 265
135 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { 266 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) {
136 return DOMMessageHandler::Attach(dom_ui); 267 return DOMMessageHandler::Attach(dom_ui);
137 } 268 }
138 269
139 void MobileSetupHandler::Init() { 270 void MobileSetupHandler::Init(TabContents* contents) {
140 // TODO(zelidag): Register for network change notification to make sure 271 tab_contents_ = contents;
141 // that the status of the cellular network does not flip to something we 272 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
142 // can't handle (disabled, suddenly activated by divine intervention...). 273
274 // TODO(zelidrag): We might want to move this to another thread.
275 LoadCellularConfig();
143 } 276 }
144 277
145 void MobileSetupHandler::RegisterMessages() { 278 void MobileSetupHandler::RegisterMessages() {
146 dom_ui_->RegisterMessageCallback(kJsApiGetDeviceInfo, 279 dom_ui_->RegisterMessageCallback(kJsApiCloseTab,
147 NewCallback(this, &MobileSetupHandler::HandleGetDeviceInfo)); 280 NewCallback(this, &MobileSetupHandler::HandleCloseTab));
148 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, 281 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus,
149 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); 282 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus));
150 } 283 }
151 284
152 void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) { 285 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* cros) {
153 const size_t kGetDeviceInfoParamCount = 1; 286 if (!dom_ui_)
154 if (args->GetSize() != kGetDeviceInfoParamCount) 287 return;
288 DictionaryValue device;
289 GetDeviceInfo(&device);
290 std::string state, error;
291 if (!ShouldReportDeviceState(&state, &error))
155 return; 292 return;
156 293
157 // Get change callback function name. 294 device.SetString("state", state);
158 string16 callback_func_name; 295 if (error.length())
159 if (!args->GetString(0, &callback_func_name)) 296 device.SetString("error", error);
160 return; 297 dom_ui_->CallJavascriptFunction(
298 kJsDeviceStatusChangedHandler, device);
299 }
161 300
162 DictionaryValue value; 301 void MobileSetupHandler::HandleCloseTab(const ListValue* args) {
163 if (GetDeviceInfo(&value)) 302 Browser* browser = BrowserList::GetLastActive();
164 dom_ui_->CallJavascriptFunction(UTF16ToWide(callback_func_name), value); 303 if (browser)
304 browser->CloseTabContents(tab_contents_);
165 } 305 }
166 306
167 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { 307 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
168 const size_t kSetTransactionStatusParamCount = 1; 308 const size_t kSetTransactionStatusParamCount = 1;
169 if (args->GetSize() != kSetTransactionStatusParamCount) 309 if (args->GetSize() != kSetTransactionStatusParamCount)
170 return; 310 return;
171 311
172 // Get change callback function name. 312 // Get change callback function name.
173 std::string status; 313 std::string status;
174 if (!args->GetString(0, &status)) 314 if (!args->GetString(0, &status))
175 return; 315 return;
176 316
177 chromeos::NetworkLibrary* network_lib = 317 chromeos::NetworkLibrary* network_lib =
178 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 318 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
179 const chromeos::CellularNetworkVector& cell_networks = 319 const chromeos::CellularNetworkVector& cell_networks =
180 network_lib->cellular_networks(); 320 network_lib->cellular_networks();
181 if (!cell_networks.size()) 321 if (!cell_networks.size())
182 return; 322 return;
323
324 // We assume only one cellular network will come from flimflam for now.
183 const chromeos::CellularNetwork& network = *(cell_networks.begin()); 325 const chromeos::CellularNetwork& network = *(cell_networks.begin());
184 326
185 if (LowerCaseEqualsASCII(status, "OK") && network.StartActivation()) { 327 if (LowerCaseEqualsASCII(status, "OK")) {
328 network.StartActivation();
329 } else {
186 DictionaryValue value; 330 DictionaryValue value;
187 if (GetDeviceInfo(&value)) 331 value.SetString("state", kFailedPaymentError);
188 dom_ui_->CallJavascriptFunction(kJsDeviceStatusChangedHandler, value); 332 dom_ui_->CallJavascriptFunction(kJsDeviceStatusChangedHandler, value);
189 } 333 }
190 // TODO(zelidrag): Close the setup tab automatically when payment fails?
191 // Pending UX decision on this one.
192 } 334 }
193 335
336 bool MobileSetupHandler::ShouldReportDeviceState(std::string* state,
337 std::string* error) {
338 DCHECK(state);
339 DCHECK(error);
340 chromeos::NetworkLibrary* network_lib =
341 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
342
343 const chromeos::CellularNetworkVector& cell_networks =
344 network_lib->cellular_networks();
345 // No cellular network present? Treat as network is disconnected.
346 // This could be transient state that is the result of activation process.
347 if (!cell_networks.size()) {
348 *state = kStateDisconnected;
349 return true;
350 }
351 const chromeos::CellularNetwork& network = cell_networks.at(0);
352
353 // First, check if device activation / plan payment failed.
354 // It's slightly more complex than just single state check
355 // that we are doing for other states below.
356 if (!CheckForActivationError(network, error)) {
357 *state = kStateError;
358 return true;
359 }
360
361 switch (network.activation_state()) {
362 case chromeos::ACTIVATION_STATE_UNKNOWN:
363 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED:
364 // If this page is shown, I assume that we have already kicked off the
365 // process of starting the activation even though the device status
366 // reporting might not have caught up with us yet.
367 *state = kStateConnecting;
368 return true;
369 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED:
370 case chromeos::ACTIVATION_STATE_ACTIVATING:
371 *state = kStateActivating;
372 return true;
373 case chromeos::ACTIVATION_STATE_ACTIVATED:
374 *state = kStateConnected;
375 return true;
376 }
377
378 // We don't report states that we don't understand to DOM UI.
379 *state = kStateUnknown;
380 return false;
381 }
382
383
384 bool MobileSetupHandler::CheckForActivationError(
385 chromeos::CellularNetwork network, std::string* error) {
386 bool got_error = false;
387 const char* error_code = kErrorDefault;
388
389 // This is the magic of error selecting based
390 if (network.connection_state() == chromeos::STATE_FAILURE &&
391 network.error() == chromeos::ERROR_AAA_FAILED ) {
392 if (network.activation_state() ==
393 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
394 error_code = kErrorBadConnectionPartial;
395 } else if (network.activation_state() ==
396 chromeos::ACTIVATION_STATE_ACTIVATED) {
397 if (network.roaming_state() == chromeos::ROAMING_STATE_HOME) {
398 error_code = kErrorBadConnectionActivated;
399 } else if (network.roaming_state() == chromeos::ROAMING_STATE_ROAMING) {
400 error_code = kErrorRoamingOnConnection;
401 }
402 }
403 got_error = true;
404 } else if (network.connection_state() ==
405 chromeos::STATE_ACTIVATION_FAILURE) {
406 if (network.error() == chromeos::ERROR_NEED_EVDO) {
407 if (network.activation_state() ==
408 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED)
409 error_code = kErrorNoEVDO;
410 } else if (network.error() == chromeos::ERROR_NEED_HOME_NETWORK) {
411 if (network.activation_state() ==
412 chromeos::ACTIVATION_STATE_NOT_ACTIVATED) {
413 error_code = kErrorRoamingActivation;
414 } else if (network.activation_state() ==
415 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) {
416 error_code = kErrorRoamingPartiallyActivated;
417 }
418 }
419 got_error = true;
420 }
421
422 if (got_error)
423 *error = GetErrorMessage(error_code);
424
425 return !got_error;
426 }
194 427
195 bool MobileSetupHandler::GetDeviceInfo(DictionaryValue* value) { 428 bool MobileSetupHandler::GetDeviceInfo(DictionaryValue* value) {
196 DCHECK(value); 429 DCHECK(value);
197 chromeos::NetworkLibrary* network_lib = 430 chromeos::NetworkLibrary* network_lib =
198 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 431 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
199 432
200 const chromeos::CellularNetworkVector& cell_networks = 433 const chromeos::CellularNetworkVector& cell_networks =
201 network_lib->cellular_networks(); 434 network_lib->cellular_networks();
202 if (!cell_networks.size()) 435 if (!cell_networks.size()) {
203 return false; 436 return false;
437 }
204 438
205 const chromeos::CellularNetwork& network = *(cell_networks.begin()); 439 const chromeos::CellularNetwork& network = *(cell_networks.begin());
206
207 value->SetString("carrier", UTF8ToUTF16(network.name())); 440 value->SetString("carrier", UTF8ToUTF16(network.name()));
208 value->SetString("payment_url", UTF8ToUTF16(network.payment_url())); 441 value->SetString("payment_url", UTF8ToUTF16(network.payment_url()));
209 value->SetInteger("activation_state", network.activation_state());
210 value->SetString("MEID", UTF8ToUTF16(network.meid())); 442 value->SetString("MEID", UTF8ToUTF16(network.meid()));
211 value->SetString("IMEI", UTF8ToUTF16(network.imei())); 443 value->SetString("IMEI", UTF8ToUTF16(network.imei()));
212 value->SetString("IMSI", UTF8ToUTF16(network.imsi())); 444 value->SetString("IMSI", UTF8ToUTF16(network.imsi()));
213 value->SetString("ESN", UTF8ToUTF16(network.esn())); 445 value->SetString("ESN", UTF8ToUTF16(network.esn()));
214 value->SetString("MDN", UTF8ToUTF16(network.mdn())); 446 value->SetString("MDN", UTF8ToUTF16(network.mdn()));
215 return true; 447 return true;
216 } 448 }
217 449
450 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) {
451 if (!cellular_config_.get())
452 return "";
453 return cellular_config_->GetErrorMessage(code);
454 }
455
456 void MobileSetupHandler::LoadCellularConfig() {
457 static bool config_loaded = false;
458 if (config_loaded)
459 return;
460 config_loaded = true;
461 // Load partner customization startup manifest if it is available.
462 FilePath config_path(kCellularConfigPath);
463 if (file_util::PathExists(config_path)) {
464 scoped_ptr<CellularConfigDocument> config(new CellularConfigDocument());
465 bool config_loaded = config->LoadFromFile(config_path);
466 if (config_loaded) {
467 LOG(INFO) << "Cellular config file loaded: " << kCellularConfigPath;
468 // lock
469 cellular_config_.reset(config.release());
470 } else {
471 LOG(ERROR) << "Error loading cellular config file: " <<
472 kCellularConfigPath;
473 }
474 }
475 }
476
477
218 //////////////////////////////////////////////////////////////////////////////// 478 ////////////////////////////////////////////////////////////////////////////////
219 // 479 //
220 // MobileSetupUI 480 // MobileSetupUI
221 // 481 //
222 //////////////////////////////////////////////////////////////////////////////// 482 ////////////////////////////////////////////////////////////////////////////////
223 483
224 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents){ 484 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents){
225 MobileSetupHandler* handler = new MobileSetupHandler(); 485 MobileSetupHandler* handler = new MobileSetupHandler();
226 AddMessageHandler((handler)->Attach(this)); 486 AddMessageHandler((handler)->Attach(this));
227 handler->Init(); 487 handler->Init(contents);
228 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource(); 488 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource();
229 489
230 // Set up the chrome://mobilesetup/ source. 490 // Set up the chrome://mobilesetup/ source.
231 ChromeThread::PostTask( 491 ChromeThread::PostTask(
232 ChromeThread::IO, FROM_HERE, 492 ChromeThread::IO, FROM_HERE,
233 NewRunnableMethod( 493 NewRunnableMethod(
234 Singleton<ChromeURLDataManager>::get(), 494 Singleton<ChromeURLDataManager>::get(),
235 &ChromeURLDataManager::AddDataSource, 495 &ChromeURLDataManager::AddDataSource,
236 make_scoped_refptr(html_source))); 496 make_scoped_refptr(html_source)));
237 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698