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

Side by Side Diff: chrome/browser/ui/webui/chromeos/mobile_setup_ui.cc

Issue 8414039: Removed file access from UI thread for mobile config file loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/webui/chromeos/mobile_setup_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/string_piece.h" 19 #include "base/string_piece.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/threading/thread_restrictions.h"
22 #include "base/timer.h" 21 #include "base/timer.h"
23 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
24 #include "base/values.h" 23 #include "base/values.h"
25 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chromeos/cros/cros_library.h" 25 #include "chrome/browser/chromeos/cros/cros_library.h"
27 #include "chrome/browser/chromeos/cros/network_library.h" 26 #include "chrome/browser/chromeos/cros/network_library.h"
28 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 155 }
157 156
158 void OnFrameLoadCompleted() { 157 void OnFrameLoadCompleted() {
159 webui_->CallJavascriptFunction(kJsPortalFrameLoadCompletedCallback); 158 webui_->CallJavascriptFunction(kJsPortalFrameLoadCompletedCallback);
160 } 159 }
161 160
162 WebUI* webui_; 161 WebUI* webui_;
163 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver); 162 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver);
164 }; 163 };
165 164
166 class CellularConfigDocument { 165 class CellularConfigDocument
166 : public base::RefCountedThreadSafe<CellularConfigDocument> {
167 public: 167 public:
168 CellularConfigDocument() {} 168 CellularConfigDocument() {}
169 169
170 // Return error message for a given code. 170 // Return error message for a given code.
171 std::string GetErrorMessage(const std::string& code); 171 std::string GetErrorMessage(const std::string& code);
172 void LoadCellularConfigFile();
172 const std::string& version() { return version_; } 173 const std::string& version() { return version_; }
173 174
175 private:
176 typedef std::map<std::string, std::string> ErrorMap;
177
178 void SetErrorMap(const ErrorMap& map);
174 bool LoadFromFile(const FilePath& config_path); 179 bool LoadFromFile(const FilePath& config_path);
175 180
176 private:
177 std::string version_; 181 std::string version_;
178 std::map<std::string, std::string> error_map_; 182 ErrorMap error_map_;
183 base::Lock config_lock_;
179 184
180 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); 185 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument);
181 }; 186 };
182 187
183 static std::map<std::string, std::string> error_messages_;
184
185 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { 188 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource {
186 public: 189 public:
187 explicit MobileSetupUIHTMLSource(const std::string& service_path); 190 explicit MobileSetupUIHTMLSource(const std::string& service_path);
188 191
189 // Called when the network layer has requested a resource underneath 192 // Called when the network layer has requested a resource underneath
190 // the path we registered. 193 // the path we registered.
191 virtual void StartDataRequest(const std::string& path, 194 virtual void StartDataRequest(const std::string& path,
192 bool is_incognito, 195 bool is_incognito,
193 int request_id); 196 int request_id);
194 virtual std::string GetMimeType(const std::string&) const { 197 virtual std::string GetMimeType(const std::string&) const {
(...skipping 12 matching lines...) Expand all
207 : public WebUIMessageHandler, 210 : public WebUIMessageHandler,
208 public chromeos::NetworkLibrary::NetworkManagerObserver, 211 public chromeos::NetworkLibrary::NetworkManagerObserver,
209 public chromeos::NetworkLibrary::NetworkObserver, 212 public chromeos::NetworkLibrary::NetworkObserver,
210 public base::SupportsWeakPtr<MobileSetupHandler> { 213 public base::SupportsWeakPtr<MobileSetupHandler> {
211 public: 214 public:
212 explicit MobileSetupHandler(const std::string& service_path); 215 explicit MobileSetupHandler(const std::string& service_path);
213 virtual ~MobileSetupHandler(); 216 virtual ~MobileSetupHandler();
214 217
215 // Init work after Attach. 218 // Init work after Attach.
216 void Init(TabContents* contents); 219 void Init(TabContents* contents);
220 void StartActivationOnUIThread();
217 221
218 // WebUIMessageHandler implementation. 222 // WebUIMessageHandler implementation.
219 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; 223 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE;
220 virtual void RegisterMessages() OVERRIDE; 224 virtual void RegisterMessages() OVERRIDE;
221 225
222 // NetworkLibrary::NetworkManagerObserver implementation. 226 // NetworkLibrary::NetworkManagerObserver implementation.
223 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj) OVERRIDE; 227 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* obj) OVERRIDE;
224 // NetworkLibrary::NetworkObserver implementation. 228 // NetworkLibrary::NetworkObserver implementation.
225 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj, 229 virtual void OnNetworkChanged(chromeos::NetworkLibrary* obj,
226 const chromeos::Network* network) OVERRIDE; 230 const chromeos::Network* network) OVERRIDE;
(...skipping 10 matching lines...) Expand all
237 PLAN_ACTIVATION_SHOWING_PAYMENT = 6, 241 PLAN_ACTIVATION_SHOWING_PAYMENT = 6,
238 PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7, 242 PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7,
239 PLAN_ACTIVATION_DELAY_OTASP = 8, 243 PLAN_ACTIVATION_DELAY_OTASP = 8,
240 PLAN_ACTIVATION_START_OTASP = 9, 244 PLAN_ACTIVATION_START_OTASP = 9,
241 PLAN_ACTIVATION_OTASP = 10, 245 PLAN_ACTIVATION_OTASP = 10,
242 PLAN_ACTIVATION_RECONNECTING_OTASP = 11, 246 PLAN_ACTIVATION_RECONNECTING_OTASP = 11,
243 PLAN_ACTIVATION_DONE = 12, 247 PLAN_ACTIVATION_DONE = 12,
244 PLAN_ACTIVATION_ERROR = 0xFF, 248 PLAN_ACTIVATION_ERROR = 0xFF,
245 } PlanActivationState; 249 } PlanActivationState;
246 250
247 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> {
248 public:
249 TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler, int delay)
250 : handler_(handler), delay_(delay) {
251 }
252 TaskProxy(const base::WeakPtr<MobileSetupHandler>& handler,
253 const std::string& status)
254 : handler_(handler), status_(status) {
255 }
256 void HandleStartActivation() {
257 if (handler_)
258 handler_->StartActivation();
259 }
260 void HandleSetTransactionStatus() {
261 if (handler_)
262 handler_->SetTransactionStatus(status_);
263 }
264 void ContinueConnecting() {
265 if (handler_)
266 handler_->ContinueConnecting(delay_);
267 }
268 void RetryOTASP() {
269 if (handler_)
270 handler_->RetryOTASP();
271 }
272 private:
273 base::WeakPtr<MobileSetupHandler> handler_;
274 std::string status_;
275 int delay_;
276 DISALLOW_COPY_AND_ASSIGN(TaskProxy);
277 };
278
279 // Handlers for JS WebUI messages. 251 // Handlers for JS WebUI messages.
280 void HandleSetTransactionStatus(const ListValue* args); 252 void HandleSetTransactionStatus(const ListValue* args);
281 void HandleStartActivation(const ListValue* args); 253 void HandleStartActivation(const ListValue* args);
282 void HandlePaymentPortalLoad(const ListValue* args); 254 void HandlePaymentPortalLoad(const ListValue* args);
283 void SetTransactionStatus(const std::string& status); 255 void SetTransactionStatus(const std::string& status);
284 // Schedules activation process via task proxy.
285 void InitiateActivation();
286 // Starts activation. 256 // Starts activation.
287 void StartActivation(); 257 void StartActivation();
288 // Retried OTASP. 258 // Retried OTASP.
289 void RetryOTASP(); 259 void RetryOTASP();
290 // Continues activation process. This method is called after we disconnect 260 // Continues activation process. This method is called after we disconnect
291 // due to detected connectivity issue to kick off reconnection. 261 // due to detected connectivity issue to kick off reconnection.
292 void ContinueConnecting(int delay); 262 void ContinueConnecting(int delay);
293 263
294 // Sends message to host registration page with system/user info data. 264 // Sends message to host registration page with system/user info data.
295 void SendDeviceInfo(); 265 void SendDeviceInfo();
(...skipping 30 matching lines...) Expand all
326 void SetupActivationProcess(chromeos::CellularNetwork* network); 296 void SetupActivationProcess(chromeos::CellularNetwork* network);
327 // Disables ethernet and wifi newtorks since they interefere with 297 // Disables ethernet and wifi newtorks since they interefere with
328 // detection of restricted pool on cellular side. 298 // detection of restricted pool on cellular side.
329 void DisableOtherNetworks(); 299 void DisableOtherNetworks();
330 // Resets network devices after cellular activation process. 300 // Resets network devices after cellular activation process.
331 // |network| should be NULL if the activation process failed. 301 // |network| should be NULL if the activation process failed.
332 void CompleteActivation(chromeos::CellularNetwork* network); 302 void CompleteActivation(chromeos::CellularNetwork* network);
333 // Control routines for handling other types of connections during 303 // Control routines for handling other types of connections during
334 // cellular activation. 304 // cellular activation.
335 void ReEnableOtherConnections(); 305 void ReEnableOtherConnections();
306 // Return error message for a given code.
307 std::string GetErrorMessage(const std::string& code);
336 308
337 // Converts the currently active CellularNetwork device into a JS object. 309 // Converts the currently active CellularNetwork device into a JS object.
338 static void GetDeviceInfo(chromeos::CellularNetwork* network, 310 static void GetDeviceInfo(chromeos::CellularNetwork* network,
339 DictionaryValue* value); 311 DictionaryValue* value);
340 static bool ShouldReportDeviceState(std::string* state, std::string* error); 312 static bool ShouldReportDeviceState(std::string* state, std::string* error);
341 313
342 // Performs activation state cellular device evaluation. 314 // Performs activation state cellular device evaluation.
343 // Returns false if device activation failed. In this case |error| 315 // Returns false if device activation failed. In this case |error|
344 // will contain error message to be reported to Web UI. 316 // will contain error message to be reported to Web UI.
345 static bool EvaluateCellularDeviceState(bool* report_status, 317 static bool EvaluateCellularDeviceState(bool* report_status,
346 std::string* state, 318 std::string* state,
347 std::string* error); 319 std::string* error);
348 320
349 // Return error message for a given code.
350 static std::string GetErrorMessage(const std::string& code);
351 static void LoadCellularConfig();
352
353 // Returns next reconnection state based on the current activation phase. 321 // Returns next reconnection state based on the current activation phase.
354 static PlanActivationState GetNextReconnectState(PlanActivationState state); 322 static PlanActivationState GetNextReconnectState(PlanActivationState state);
355 static const char* GetStateDescription(PlanActivationState state); 323 static const char* GetStateDescription(PlanActivationState state);
356 324
357 static scoped_ptr<CellularConfigDocument> cellular_config_; 325 scoped_refptr<CellularConfigDocument> cellular_config_;
358
359 TabContents* tab_contents_; 326 TabContents* tab_contents_;
360 // Internal handler state. 327 // Internal handler state.
361 PlanActivationState state_; 328 PlanActivationState state_;
362 std::string service_path_; 329 std::string service_path_;
363 // Flags that control if wifi and ethernet connection needs to be restored 330 // Flags that control if wifi and ethernet connection needs to be restored
364 // after the activation of cellular network. 331 // after the activation of cellular network.
365 bool reenable_wifi_; 332 bool reenable_wifi_;
366 bool reenable_ethernet_; 333 bool reenable_ethernet_;
367 bool reenable_cert_check_; 334 bool reenable_cert_check_;
368 bool evaluating_; 335 bool evaluating_;
369 // True if we think that another tab is already running activation. 336 // True if we think that another tab is already running activation.
370 bool already_running_; 337 bool already_running_;
371 // Connection retry counter. 338 // Connection retry counter.
372 int connection_retry_count_; 339 int connection_retry_count_;
373 // Post payment reconnect wait counters. 340 // Post payment reconnect wait counters.
374 int reconnect_wait_count_; 341 int reconnect_wait_count_;
375 // Payment portal reload/reconnect attempt count. 342 // Payment portal reload/reconnect attempt count.
376 int payment_reconnect_count_; 343 int payment_reconnect_count_;
377 // Activation retry attempt count; 344 // Activation retry attempt count;
378 int activation_attempt_; 345 int activation_attempt_;
379 // Connection start time. 346 // Connection start time.
380 base::Time connection_start_time_; 347 base::Time connection_start_time_;
381 // Timer that monitors reconnection timeouts. 348 // Timer that monitors reconnection timeouts.
382 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_; 349 base::RepeatingTimer<MobileSetupHandler> reconnect_timer_;
383 350
384 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); 351 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler);
385 }; 352 };
386 353
387 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_;
388
389 //////////////////////////////////////////////////////////////////////////////// 354 ////////////////////////////////////////////////////////////////////////////////
390 // 355 //
391 // CellularConfigDocument 356 // CellularConfigDocument
392 // 357 //
393 //////////////////////////////////////////////////////////////////////////////// 358 ////////////////////////////////////////////////////////////////////////////////
394 359
395 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { 360 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) {
396 std::map<std::string, std::string>::iterator iter = error_map_.find(code); 361 base::AutoLock create(config_lock_);
362 ErrorMap::iterator iter = error_map_.find(code);
397 if (iter == error_map_.end()) 363 if (iter == error_map_.end())
398 return code; 364 return code;
399 return iter->second; 365 return iter->second;
400 } 366 }
401 367
368 void CellularConfigDocument::LoadCellularConfigFile() {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
370 // Load partner customization startup manifest if it is available.
371 FilePath config_path(kCellularConfigPath);
372 if (!file_util::PathExists(config_path))
373 return;
374
375 if (LoadFromFile(config_path)) {
376 DVLOG(1) << "Cellular config file loaded: " << kCellularConfigPath;
377 } else {
378 LOG(ERROR) << "Error loading cellular config file: " <<
379 kCellularConfigPath;
380 }
381 }
382
402 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) { 383 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) {
403 error_map_.clear();
404
405 std::string config; 384 std::string config;
406 { 385 if (!file_util::ReadFileToString(config_path, &config))
407 // Reading config file causes us to do blocking IO on UI thread. 386 return false;
408 // Temporarily allow it until we fix http://crosbug.com/11535
409 base::ThreadRestrictions::ScopedAllowIO allow_io;
410 if (!file_util::ReadFileToString(config_path, &config))
411 return false;
412 }
413 387
414 scoped_ptr<Value> root(base::JSONReader::Read(config, true)); 388 scoped_ptr<Value> root(base::JSONReader::Read(config, true));
415 DCHECK(root.get() != NULL); 389 DCHECK(root.get() != NULL);
416 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { 390 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) {
417 LOG(WARNING) << "Bad cellular config file"; 391 LOG(WARNING) << "Bad cellular config file";
418 return false; 392 return false;
419 } 393 }
420 394
421 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); 395 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get());
422 if (!root_dict->GetString(kVersionField, &version_)) { 396 if (!root_dict->GetString(kVersionField, &version_)) {
423 LOG(WARNING) << "Cellular config file missing version"; 397 LOG(WARNING) << "Cellular config file missing version";
424 return false; 398 return false;
425 } 399 }
400 ErrorMap error_map;
426 DictionaryValue* errors = NULL; 401 DictionaryValue* errors = NULL;
427 if (!root_dict->GetDictionary(kErrorsField, &errors)) 402 if (!root_dict->GetDictionary(kErrorsField, &errors))
428 return false; 403 return false;
429 for (DictionaryValue::key_iterator keys = errors->begin_keys(); 404 for (DictionaryValue::key_iterator keys = errors->begin_keys();
430 keys != errors->end_keys(); 405 keys != errors->end_keys();
431 ++keys) { 406 ++keys) {
432 std::string value; 407 std::string value;
433 if (!errors->GetString(*keys, &value)) { 408 if (!errors->GetString(*keys, &value)) {
434 LOG(WARNING) << "Bad cellular config error value"; 409 LOG(WARNING) << "Bad cellular config error value";
435 error_map_.clear();
436 return false; 410 return false;
437 } 411 }
412 error_map.insert(ErrorMap::value_type(*keys, value));
413 }
414 SetErrorMap(error_map);
415 return true;
416 }
438 417
439 error_map_.insert(std::pair<std::string, std::string>(*keys, value)); 418 void CellularConfigDocument::SetErrorMap(
440 } 419 const ErrorMap& map) {
441 return true; 420 base::AutoLock create(config_lock_);
421 error_map_.clear();
422 error_map_.insert(map.begin(), map.end());
442 } 423 }
443 424
444 //////////////////////////////////////////////////////////////////////////////// 425 ////////////////////////////////////////////////////////////////////////////////
445 // 426 //
446 // MobileSetupUIHTMLSource 427 // MobileSetupUIHTMLSource
447 // 428 //
448 //////////////////////////////////////////////////////////////////////////////// 429 ////////////////////////////////////////////////////////////////////////////////
449 430
450 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource( 431 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource(
451 const std::string& service_path) 432 const std::string& service_path)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 479
499 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); 480 SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
500 } 481 }
501 482
502 //////////////////////////////////////////////////////////////////////////////// 483 ////////////////////////////////////////////////////////////////////////////////
503 // 484 //
504 // MobileSetupHandler 485 // MobileSetupHandler
505 // 486 //
506 //////////////////////////////////////////////////////////////////////////////// 487 ////////////////////////////////////////////////////////////////////////////////
507 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) 488 MobileSetupHandler::MobileSetupHandler(const std::string& service_path)
508 : tab_contents_(NULL), 489 : cellular_config_(new CellularConfigDocument()),
490 tab_contents_(NULL),
509 state_(PLAN_ACTIVATION_PAGE_LOADING), 491 state_(PLAN_ACTIVATION_PAGE_LOADING),
510 service_path_(service_path), 492 service_path_(service_path),
511 reenable_wifi_(false), 493 reenable_wifi_(false),
512 reenable_ethernet_(false), 494 reenable_ethernet_(false),
513 reenable_cert_check_(false), 495 reenable_cert_check_(false),
514 evaluating_(false), 496 evaluating_(false),
515 already_running_(false), 497 already_running_(false),
516 connection_retry_count_(0), 498 connection_retry_count_(0),
517 reconnect_wait_count_(0), 499 reconnect_wait_count_(0),
518 payment_reconnect_count_(0), 500 payment_reconnect_count_(0),
(...skipping 10 matching lines...) Expand all
529 lib->Unlock(); 511 lib->Unlock();
530 ReEnableOtherConnections(); 512 ReEnableOtherConnections();
531 } 513 }
532 514
533 WebUIMessageHandler* MobileSetupHandler::Attach(WebUI* web_ui) { 515 WebUIMessageHandler* MobileSetupHandler::Attach(WebUI* web_ui) {
534 return WebUIMessageHandler::Attach(web_ui); 516 return WebUIMessageHandler::Attach(web_ui);
535 } 517 }
536 518
537 void MobileSetupHandler::Init(TabContents* contents) { 519 void MobileSetupHandler::Init(TabContents* contents) {
538 tab_contents_ = contents; 520 tab_contents_ = contents;
539 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
540 if (!network || !network->SupportsActivation())
541 return;
542 LoadCellularConfig();
543 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked())
544 SetupActivationProcess(network);
545 else
546 already_running_ = true;
547 } 521 }
548 522
549 void MobileSetupHandler::RegisterMessages() { 523 void MobileSetupHandler::RegisterMessages() {
550 web_ui_->RegisterMessageCallback(kJsApiStartActivation, 524 web_ui_->RegisterMessageCallback(kJsApiStartActivation,
551 base::Bind(&MobileSetupHandler::HandleStartActivation, 525 base::Bind(&MobileSetupHandler::HandleStartActivation,
552 base::Unretained(this))); 526 base::Unretained(this)));
553 web_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, 527 web_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus,
554 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus, 528 base::Bind(&MobileSetupHandler::HandleSetTransactionStatus,
555 base::Unretained(this))); 529 base::Unretained(this)));
556 web_ui_->RegisterMessageCallback(kJsApiPaymentPortalLoad, 530 web_ui_->RegisterMessageCallback(kJsApiPaymentPortalLoad,
(...skipping 14 matching lines...) Expand all
571 545
572 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros, 546 void MobileSetupHandler::OnNetworkChanged(chromeos::NetworkLibrary* cros,
573 const chromeos::Network* network) { 547 const chromeos::Network* network) {
574 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) 548 if (state_ == PLAN_ACTIVATION_PAGE_LOADING)
575 return; 549 return;
576 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR); 550 DCHECK(network && network->type() == chromeos::TYPE_CELLULAR);
577 EvaluateCellularNetwork(GetCellularNetwork(network->service_path())); 551 EvaluateCellularNetwork(GetCellularNetwork(network->service_path()));
578 } 552 }
579 553
580 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { 554 void MobileSetupHandler::HandleStartActivation(const ListValue* args) {
581 InitiateActivation(); 555 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
582 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); 556 base::Bind(&CellularConfigDocument::LoadCellularConfigFile,
557 cellular_config_.get()),
558 base::Bind(&MobileSetupHandler::StartActivationOnUIThread, AsWeakPtr()));
583 } 559 }
584 560
585 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { 561 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
586 const size_t kSetTransactionStatusParamCount = 1; 562 const size_t kSetTransactionStatusParamCount = 1;
587 if (args->GetSize() != kSetTransactionStatusParamCount) 563 if (args->GetSize() != kSetTransactionStatusParamCount)
588 return; 564 return;
589 // Get change callback function name. 565 // Get change callback function name.
590 std::string status; 566 std::string status;
591 if (!args->GetString(0, &status)) 567 if (!args->GetString(0, &status))
592 return; 568 return;
593 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), status);
594 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 569 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
595 base::Bind(&TaskProxy::HandleSetTransactionStatus, task.get())); 570 base::Bind(&MobileSetupHandler::SetTransactionStatus, AsWeakPtr(),
571 status));
596 } 572 }
597 573
598 void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) { 574 void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
599 const size_t kPaymentPortalLoadParamCount = 1; 575 const size_t kPaymentPortalLoadParamCount = 1;
600 if (args->GetSize() != kPaymentPortalLoadParamCount) 576 if (args->GetSize() != kPaymentPortalLoadParamCount)
601 return; 577 return;
602 // Get change callback function name. 578 // Get change callback function name.
603 std::string result; 579 std::string result;
604 if (!args->GetString(0, &result)) 580 if (!args->GetString(0, &result))
605 return; 581 return;
(...skipping 18 matching lines...) Expand all
624 // Disconnect now, this should force reconnection and we will retry to 600 // Disconnect now, this should force reconnection and we will retry to
625 // load the frame containing payment portal again. 601 // load the frame containing payment portal again.
626 DisconnectFromNetwork(network); 602 DisconnectFromNetwork(network);
627 } 603 }
628 } else { 604 } else {
629 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " 605 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: "
630 << GetStateDescription(state_); 606 << GetStateDescription(state_);
631 } 607 }
632 } 608 }
633 609
634 void MobileSetupHandler::InitiateActivation() {
635 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0);
636 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
637 base::Bind(&TaskProxy::HandleStartActivation, task.get()));
638 }
639
640 void MobileSetupHandler::StartActivation() { 610 void MobileSetupHandler::StartActivation() {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
612 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1);
642 chromeos::NetworkLibrary* lib = 613 chromeos::NetworkLibrary* lib =
643 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 614 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
644 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); 615 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
645 // Check if we can start activation process. 616 // Check if we can start activation process.
646 if (!network || already_running_) { 617 if (!network || already_running_) {
647 std::string error; 618 std::string error;
648 if (already_running_) 619 if (already_running_)
649 error = kErrorAlreadyRunning; 620 error = kErrorAlreadyRunning;
650 else if (!lib->cellular_available()) 621 else if (!lib->cellular_available())
651 error = kErrorNoDevice; 622 error = kErrorNoDevice;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 return false; 748 return false;
778 if (network) 749 if (network)
779 LOG(INFO) << "Connecting to: " << network->service_path(); 750 LOG(INFO) << "Connecting to: " << network->service_path();
780 connection_retry_count_++; 751 connection_retry_count_++;
781 connection_start_time_ = base::Time::Now(); 752 connection_start_time_ = base::Time::Now();
782 if (!network) { 753 if (!network) {
783 LOG(WARNING) << "Connect failed." 754 LOG(WARNING) << "Connect failed."
784 << (network ? network->service_path().c_str() : "no service"); 755 << (network ? network->service_path().c_str() : "no service");
785 // If we coudn't connect during reconnection phase, try to reconnect 756 // If we coudn't connect during reconnection phase, try to reconnect
786 // with a delay (and try to reconnect if needed). 757 // with a delay (and try to reconnect if needed).
787 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
788 delay);
789 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 758 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
790 base::Bind(&TaskProxy::ContinueConnecting, task.get()), delay); 759 base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay),
760 delay);
791 return false; 761 return false;
792 } 762 }
793 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 763 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
794 ConnectToCellularNetwork(network); 764 ConnectToCellularNetwork(network);
795 return true; 765 return true;
796 } 766 }
797 767
798 void MobileSetupHandler::ForceReconnect( 768 void MobileSetupHandler::ForceReconnect(
799 chromeos::CellularNetwork* network, 769 chromeos::CellularNetwork* network,
800 int delay) { 770 int delay) {
801 DCHECK(network); 771 DCHECK(network);
802 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); 772 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1);
803 // Reset reconnect metrics. 773 // Reset reconnect metrics.
804 connection_retry_count_ = 0; 774 connection_retry_count_ = 0;
805 connection_start_time_ = base::Time(); 775 connection_start_time_ = base::Time();
806 // First, disconnect... 776 // First, disconnect...
807 LOG(INFO) << "Disconnecting from " << network->service_path(); 777 LOG(INFO) << "Disconnecting from " << network->service_path();
808 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> 778 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
809 DisconnectFromNetwork(network); 779 DisconnectFromNetwork(network);
810 // Check the network state 3s after we disconnect to make sure. 780 // Check the network state 3s after we disconnect to make sure.
811 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(),
812 delay);
813 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 781 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
814 base::Bind(&TaskProxy::ContinueConnecting, task.get()), delay); 782 base::Bind(&MobileSetupHandler::ContinueConnecting, AsWeakPtr(), delay),
783 delay);
815 } 784 }
816 785
817 bool MobileSetupHandler::ConnectionTimeout() { 786 bool MobileSetupHandler::ConnectionTimeout() {
818 return (base::Time::Now() - 787 return (base::Time::Now() -
819 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds; 788 connection_start_time_).InSeconds() > kConnectionTimeoutSeconds;
820 } 789 }
821 790
822 void MobileSetupHandler::EvaluateCellularNetwork( 791 void MobileSetupHandler::EvaluateCellularNetwork(
823 chromeos::CellularNetwork* network) { 792 chromeos::CellularNetwork* network) {
824 if (!web_ui_) 793 if (!web_ui_)
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 1176
1208 // Signal to JS layer that the state is changing. 1177 // Signal to JS layer that the state is changing.
1209 UpdatePage(network, error_description); 1178 UpdatePage(network, error_description);
1210 1179
1211 // Pick action that should happen on entering the new state. 1180 // Pick action that should happen on entering the new state.
1212 switch (new_state) { 1181 switch (new_state) {
1213 case PLAN_ACTIVATION_START: 1182 case PLAN_ACTIVATION_START:
1214 break; 1183 break;
1215 case PLAN_ACTIVATION_DELAY_OTASP: { 1184 case PLAN_ACTIVATION_DELAY_OTASP: {
1216 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); 1185 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1);
1217 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), 0);
1218 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 1186 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
1219 base::Bind(&TaskProxy::RetryOTASP, task.get()), kOTASPRetryDelay); 1187 base::Bind(&MobileSetupHandler::RetryOTASP, AsWeakPtr()),
1188 kOTASPRetryDelay);
1220 break; 1189 break;
1221 } 1190 }
1222 case PLAN_ACTIVATION_INITIATING_ACTIVATION: 1191 case PLAN_ACTIVATION_INITIATING_ACTIVATION:
1223 case PLAN_ACTIVATION_TRYING_OTASP: 1192 case PLAN_ACTIVATION_TRYING_OTASP:
1224 case PLAN_ACTIVATION_OTASP: 1193 case PLAN_ACTIVATION_OTASP:
1225 DCHECK(network); 1194 DCHECK(network);
1226 LOG(WARNING) << "Activating service " << network->service_path().c_str(); 1195 LOG(WARNING) << "Activating service " << network->service_path().c_str();
1227 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); 1196 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1);
1228 if (!network->StartActivation()) { 1197 if (!network->StartActivation()) {
1229 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); 1198 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 const chromeos::NetworkDevice* device = 1362 const chromeos::NetworkDevice* device =
1394 cros->FindNetworkDeviceByPath(network->device_path()); 1363 cros->FindNetworkDeviceByPath(network->device_path());
1395 if (device) { 1364 if (device) {
1396 value->SetString("MEID", device->meid()); 1365 value->SetString("MEID", device->meid());
1397 value->SetString("IMEI", device->imei()); 1366 value->SetString("IMEI", device->imei());
1398 value->SetString("MDN", device->mdn()); 1367 value->SetString("MDN", device->mdn());
1399 } 1368 }
1400 } 1369 }
1401 1370
1402 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) { 1371 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) {
1403 if (!cellular_config_.get())
1404 return "";
1405 return cellular_config_->GetErrorMessage(code); 1372 return cellular_config_->GetErrorMessage(code);
1406 } 1373 }
1407 1374
1408 void MobileSetupHandler::LoadCellularConfig() { 1375 void MobileSetupHandler::StartActivationOnUIThread() {
1409 static bool config_loaded = false; 1376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1410 if (config_loaded) 1377 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_);
1378 if (!network || !network->SupportsActivation())
1411 return; 1379 return;
1412 config_loaded = true; 1380
1413 // Load partner customization startup manifest if it is available. 1381 if (!chromeos::CrosLibrary::Get()->GetNetworkLibrary()->IsLocked())
1414 FilePath config_path(kCellularConfigPath); 1382 SetupActivationProcess(network);
1415 bool config_exists = false; 1383 else
1416 { 1384 already_running_ = true;
1417 // Reading config file causes us to do blocking IO on UI thread. 1385
1418 // Temporarily allow it until we fix http://crosbug.com/11535 1386 StartActivation();
1419 base::ThreadRestrictions::ScopedAllowIO allow_io;
1420 config_exists = file_util::PathExists(config_path);
1421 }
1422 if (config_exists) {
1423 scoped_ptr<CellularConfigDocument> config(new CellularConfigDocument());
1424 bool config_loaded = config->LoadFromFile(config_path);
1425 if (config_loaded) {
1426 LOG(INFO) << "Cellular config file loaded: " << kCellularConfigPath;
1427 // lock
1428 cellular_config_.reset(config.release());
1429 } else {
1430 LOG(ERROR) << "Error loading cellular config file: " <<
1431 kCellularConfigPath;
1432 }
1433 }
1434 } 1387 }
1435 1388
1436
1437 //////////////////////////////////////////////////////////////////////////////// 1389 ////////////////////////////////////////////////////////////////////////////////
1438 // 1390 //
1439 // MobileSetupUI 1391 // MobileSetupUI
1440 // 1392 //
1441 //////////////////////////////////////////////////////////////////////////////// 1393 ////////////////////////////////////////////////////////////////////////////////
1442 1394
1443 MobileSetupUI::MobileSetupUI(TabContents* contents) : ChromeWebUI(contents) { 1395 MobileSetupUI::MobileSetupUI(TabContents* contents) : ChromeWebUI(contents) {
1444 chromeos::CellularNetwork* network = GetCellularNetwork(); 1396 chromeos::CellularNetwork* network = GetCellularNetwork();
1445 std::string service_path = network ? network->service_path() : std::string(); 1397 std::string service_path = network ? network->service_path() : std::string();
1446 MobileSetupHandler* handler = new MobileSetupHandler(service_path); 1398 MobileSetupHandler* handler = new MobileSetupHandler(service_path);
1447 AddMessageHandler((handler)->Attach(this)); 1399 AddMessageHandler((handler)->Attach(this));
1448 handler->Init(contents); 1400 handler->Init(contents);
1449 MobileSetupUIHTMLSource* html_source = 1401 MobileSetupUIHTMLSource* html_source =
1450 new MobileSetupUIHTMLSource(service_path); 1402 new MobileSetupUIHTMLSource(service_path);
1451 1403
1452 // Set up the chrome://mobilesetup/ source. 1404 // Set up the chrome://mobilesetup/ source.
1453 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 1405 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
1454 profile->GetChromeURLDataManager()->AddDataSource(html_source); 1406 profile->GetChromeURLDataManager()->AddDataSource(html_source);
1455 } 1407 }
1456 1408
1457 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { 1409 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) {
1458 ChromeWebUI::RenderViewCreated(host); 1410 ChromeWebUI::RenderViewCreated(host);
1459 // Destroyed by the corresponding RenderViewHost. 1411 // Destroyed by the corresponding RenderViewHost.
1460 new PortalFrameLoadObserver(host, tab_contents()->web_ui()); 1412 new PortalFrameLoadObserver(host, tab_contents()->web_ui());
1461 } 1413 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698