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

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

Issue 7736014: [cros] Process proper notification in SIM dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: js focus fix Created 9 years, 3 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
« no previous file with comments | « chrome/browser/resources/chromeos/sim_unlock.js ('k') | 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/sim_unlock_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 virtual ~SimUnlockHandler(); 90 virtual ~SimUnlockHandler();
91 91
92 // Init work after Attach. 92 // Init work after Attach.
93 void Init(TabContents* contents); 93 void Init(TabContents* contents);
94 94
95 // WebUIMessageHandler implementation. 95 // WebUIMessageHandler implementation.
96 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; 96 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE;
97 virtual void RegisterMessages() OVERRIDE; 97 virtual void RegisterMessages() OVERRIDE;
98 98
99 // NetworkLibrary::NetworkDeviceObserver implementation. 99 // NetworkLibrary::NetworkDeviceObserver implementation.
100 virtual void OnNetworkDeviceChanged(NetworkLibrary* cros, 100 virtual void OnNetworkDeviceSimLockChanged(
101 const NetworkDevice* device) OVERRIDE; 101 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE;
102 102
103 // NetworkLibrary::PinOperationObserver implementation. 103 // NetworkLibrary::PinOperationObserver implementation.
104 virtual void OnPinOperationCompleted(NetworkLibrary* cros, 104 virtual void OnPinOperationCompleted(NetworkLibrary* cros,
105 PinOperationError error) OVERRIDE; 105 PinOperationError error) OVERRIDE;
106 106
107 private: 107 private:
108 // Should keep this state enum in sync with similar one in JS code. 108 // Should keep this state enum in sync with similar one in JS code.
109 // SIM_NOT_LOCKED_ASK_PIN - SIM card is not locked but we ask user 109 // SIM_NOT_LOCKED_ASK_PIN - SIM card is not locked but we ask user
110 // for PIN input because PinRequired preference change was requested. 110 // for PIN input because PinRequired preference change was requested.
111 // SIM_NOT_LOCKED_CHANGE_PIN - SIM card is not locked, ask user for old PIN 111 // SIM_NOT_LOCKED_CHANGE_PIN - SIM card is not locked, ask user for old PIN
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void ProceedToPukInput(); 206 void ProceedToPukInput();
207 207
208 // Processes current SIM card state and update internal state/page. 208 // Processes current SIM card state and update internal state/page.
209 void ProcessSimCardState(const chromeos::NetworkDevice* cellular); 209 void ProcessSimCardState(const chromeos::NetworkDevice* cellular);
210 210
211 // Updates page with the current state/SIM card info/error. 211 // Updates page with the current state/SIM card info/error.
212 void UpdatePage(const chromeos::NetworkDevice* cellular, 212 void UpdatePage(const chromeos::NetworkDevice* cellular,
213 const std::string& error_msg); 213 const std::string& error_msg);
214 214
215 TabContents* tab_contents_; 215 TabContents* tab_contents_;
216
217 // Dialog internal state.
216 SimUnlockState state_; 218 SimUnlockState state_;
217 219
218 // Path of the Cellular device that we monitor property updates from. 220 // Path of the Cellular device that we monitor property updates from.
219 std::string cellular_device_path_; 221 std::string cellular_device_path_;
220 222
221 // Type of the dialog: generic unlock/change pin/change PinRequire. 223 // Type of the dialog: generic unlock/change pin/change PinRequire.
222 SimDialogDelegate::SimDialogMode dialog_mode_; 224 SimDialogDelegate::SimDialogMode dialog_mode_;
223 225
224 // New PIN value for the case when we unblock SIM card or change PIN. 226 // New PIN value for the case when we unblock SIM card or change PIN.
225 std::string new_pin_; 227 std::string new_pin_;
226 228
229 // True if there's a pending PIN operation.
230 // That means that SIM lock state change will be received 2 times:
231 // OnNetworkDeviceSimLockChanged and OnPinOperationCompleted.
232 // First one should be ignored.
233 bool pending_pin_operation_;
234
227 DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler); 235 DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler);
228 }; 236 };
229 237
230 // SimUnlockUIHTMLSource ------------------------------------------------------- 238 // SimUnlockUIHTMLSource -------------------------------------------------------
231 239
232 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource() 240 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource()
233 : DataSource(chrome::kChromeUISimUnlockHost, MessageLoop::current()) { 241 : DataSource(chrome::kChromeUISimUnlockHost, MessageLoop::current()) {
234 } 242 }
235 243
236 void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, 244 void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 &strings); 307 &strings);
300 308
301 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); 309 SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
302 } 310 }
303 311
304 // SimUnlockHandler ------------------------------------------------------------ 312 // SimUnlockHandler ------------------------------------------------------------
305 313
306 SimUnlockHandler::SimUnlockHandler() 314 SimUnlockHandler::SimUnlockHandler()
307 : tab_contents_(NULL), 315 : tab_contents_(NULL),
308 state_(SIM_UNLOCK_LOADING), 316 state_(SIM_UNLOCK_LOADING),
309 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK) { 317 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK),
318 pending_pin_operation_(false) {
310 const chromeos::NetworkDevice* cellular = GetCellularDevice(); 319 const chromeos::NetworkDevice* cellular = GetCellularDevice();
311 // One could just call us directly via chrome://sim-unlock. 320 // One could just call us directly via chrome://sim-unlock.
312 if (cellular) { 321 if (cellular) {
313 cellular_device_path_ = cellular->device_path(); 322 cellular_device_path_ = cellular->device_path();
314 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkDeviceObserver( 323 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkDeviceObserver(
315 cellular_device_path_, this); 324 cellular_device_path_, this);
316 CrosLibrary::Get()->GetNetworkLibrary()->AddPinOperationObserver(this); 325 CrosLibrary::Get()->GetNetworkLibrary()->AddPinOperationObserver(this);
317 } 326 }
318 } 327 }
319 328
(...skipping 21 matching lines...) Expand all
341 web_ui_->RegisterMessageCallback(kJsApiEnterPinCode, 350 web_ui_->RegisterMessageCallback(kJsApiEnterPinCode,
342 NewCallback(this, &SimUnlockHandler::HandleEnterPinCode)); 351 NewCallback(this, &SimUnlockHandler::HandleEnterPinCode));
343 web_ui_->RegisterMessageCallback(kJsApiEnterPukCode, 352 web_ui_->RegisterMessageCallback(kJsApiEnterPukCode,
344 NewCallback(this, &SimUnlockHandler::HandleEnterPukCode)); 353 NewCallback(this, &SimUnlockHandler::HandleEnterPukCode));
345 web_ui_->RegisterMessageCallback(kJsApiProceedToPukInput, 354 web_ui_->RegisterMessageCallback(kJsApiProceedToPukInput,
346 NewCallback(this, &SimUnlockHandler::HandleProceedToPukInput)); 355 NewCallback(this, &SimUnlockHandler::HandleProceedToPukInput));
347 web_ui_->RegisterMessageCallback(kJsApiSimStatusInitialize, 356 web_ui_->RegisterMessageCallback(kJsApiSimStatusInitialize,
348 NewCallback(this, &SimUnlockHandler::HandleSimStatusInitialize)); 357 NewCallback(this, &SimUnlockHandler::HandleSimStatusInitialize));
349 } 358 }
350 359
351 void SimUnlockHandler::OnNetworkDeviceChanged(NetworkLibrary* cros, 360 void SimUnlockHandler::OnNetworkDeviceSimLockChanged(
352 const NetworkDevice* device) { 361 NetworkLibrary* cros, const NetworkDevice* device) {
353 chromeos::SimLockState lock_state = device->sim_lock_state(); 362 chromeos::SimLockState lock_state = device->sim_lock_state();
354 int retries_left = device->sim_retries_left(); 363 int retries_left = device->sim_retries_left();
355 VLOG(1) << "OnNetworkDeviceChanged, lock: " << lock_state 364 VLOG(1) << "OnNetworkDeviceSimLockChanged, lock: " << lock_state
356 << ", retries: " << retries_left; 365 << ", retries: " << retries_left;
357 ProcessSimCardState(GetCellularDevice()); 366 // There's a pending PIN operation.
367 // Wait for it to finish and refresh state then.
368 if (!pending_pin_operation_)
369 ProcessSimCardState(GetCellularDevice());
358 } 370 }
359 371
360 void SimUnlockHandler::OnPinOperationCompleted(NetworkLibrary* cros, 372 void SimUnlockHandler::OnPinOperationCompleted(NetworkLibrary* cros,
361 PinOperationError error) { 373 PinOperationError error) {
374 pending_pin_operation_ = false;
362 DCHECK(cros); 375 DCHECK(cros);
363 const NetworkDevice* cellular = cros->FindCellularDevice(); 376 const NetworkDevice* cellular = cros->FindCellularDevice();
364 DCHECK(cellular); 377 DCHECK(cellular);
365 VLOG(1) << "OnPinOperationCompleted, error: " << error; 378 VLOG(1) << "OnPinOperationCompleted, error: " << error;
366 if (state_ == SIM_NOT_LOCKED_ASK_PIN && error == PIN_ERROR_NONE) { 379 if (state_ == SIM_NOT_LOCKED_ASK_PIN && error == PIN_ERROR_NONE) {
367 CHECK(dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON || 380 CHECK(dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON ||
368 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF); 381 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF);
369 // Async change RequirePin operation has finished OK. 382 // Async change RequirePin operation has finished OK.
370 NotifyOnRequirePinChangeEnded( 383 NotifyOnRequirePinChangeEnded(
371 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON); 384 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON);
(...skipping 29 matching lines...) Expand all
401 } 414 }
402 415
403 void SimUnlockHandler::EnterCode(const std::string& code, 416 void SimUnlockHandler::EnterCode(const std::string& code,
404 SimUnlockCode code_type) { 417 SimUnlockCode code_type) {
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
406 NetworkLibrary* lib = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 419 NetworkLibrary* lib = chromeos::CrosLibrary::Get()->GetNetworkLibrary();
407 CHECK(lib); 420 CHECK(lib);
408 421
409 const NetworkDevice* cellular = GetCellularDevice(); 422 const NetworkDevice* cellular = GetCellularDevice();
410 chromeos::SimLockState lock_state = cellular->sim_lock_state(); 423 chromeos::SimLockState lock_state = cellular->sim_lock_state();
424 pending_pin_operation_ = true;
411 425
412 switch (code_type) { 426 switch (code_type) {
413 case CODE_PIN: 427 case CODE_PIN:
414 if (dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON || 428 if (dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON ||
415 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF) { 429 dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF) {
416 if (lock_state != chromeos::SIM_UNLOCKED) { 430 if (lock_state != chromeos::SIM_UNLOCKED) {
417 // If SIM is locked/absent, change RequirePin UI is not accessible. 431 // If SIM is locked/absent, change RequirePin UI is not accessible.
418 NOTREACHED() << 432 NOTREACHED() <<
419 "Changing RequirePin pref on locked / uninitialized SIM."; 433 "Changing RequirePin pref on locked / uninitialized SIM.";
420 } 434 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 AddMessageHandler((handler)->Attach(this)); 668 AddMessageHandler((handler)->Attach(this));
655 handler->Init(contents); 669 handler->Init(contents);
656 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource(); 670 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource();
657 671
658 // Set up the chrome://sim-unlock/ source. 672 // Set up the chrome://sim-unlock/ source.
659 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 673 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
660 profile->GetChromeURLDataManager()->AddDataSource(html_source); 674 profile->GetChromeURLDataManager()->AddDataSource(html_source);
661 } 675 }
662 676
663 } // namespace chromeos 677 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/sim_unlock.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698