| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <atlbase.h> | 5 #include <atlbase.h> |
| 6 #include <atlapp.h> // NOLINT | 6 #include <atlapp.h> // NOLINT |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 base::MessageLoop* ui_loop_; | 116 base::MessageLoop* ui_loop_; |
| 117 base::MessageLoop* io_loop_; | 117 base::MessageLoop* io_loop_; |
| 118 | 118 |
| 119 ServiceController controller_; | 119 ServiceController controller_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 SetupDialog::SetupDialog() | 122 SetupDialog::SetupDialog() |
| 123 : state_(ServiceController::STATE_NOT_FOUND), | 123 : state_(ServiceController::STATE_NOT_FOUND), |
| 124 worker_("worker") { | 124 worker_("worker") { |
| 125 ui_loop_ = base::MessageLoop::current(); | 125 ui_loop_ = base::MessageLoop::current(); |
| 126 DCHECK(ui_loop_->IsType(base::MessageLoop::TYPE_UI)); | 126 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 127 | 127 |
| 128 worker_.StartWithOptions( | 128 worker_.StartWithOptions( |
| 129 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 129 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 130 io_loop_ = worker_.message_loop(); | 130 io_loop_ = worker_.message_loop(); |
| 131 DCHECK(io_loop_->IsType(base::MessageLoop::TYPE_IO)); | 131 DCHECK(io_loop_->IsType(base::MessageLoop::TYPE_IO)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void SetupDialog::PostUITask(const base::Closure& task) { | 134 void SetupDialog::PostUITask(const base::Closure& task) { |
| 135 ui_loop_->PostTask(FROM_HERE, task); | 135 ui_loop_->PostTask(FROM_HERE, task); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SetupDialog::PostIOTask(const base::Closure& task) { | 138 void SetupDialog::PostIOTask(const base::Closure& task) { |
| 139 io_loop_->PostTask(FROM_HERE, task); | 139 io_loop_->PostTask(FROM_HERE, task); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SetupDialog::ShowErrorMessageBox(const base::string16& error_message) { | 142 void SetupDialog::ShowErrorMessageBox(const base::string16& error_message) { |
| 143 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); | 143 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 144 MessageBox(error_message.c_str(), | 144 MessageBox(error_message.c_str(), |
| 145 LoadLocalString(IDS_OPERATION_FAILED_TITLE).c_str(), | 145 LoadLocalString(IDS_OPERATION_FAILED_TITLE).c_str(), |
| 146 MB_ICONERROR | MB_OK); | 146 MB_ICONERROR | MB_OK); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void SetupDialog::AskToCloseChrome() { | 149 void SetupDialog::AskToCloseChrome() { |
| 150 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); | 150 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 151 MessageBox(LoadLocalString(IDS_ADD_PRINTERS_USING_CHROME).c_str(), | 151 MessageBox(LoadLocalString(IDS_ADD_PRINTERS_USING_CHROME).c_str(), |
| 152 LoadLocalString(IDS_CONTINUE_IN_CHROME_TITLE).c_str(), | 152 LoadLocalString(IDS_CONTINUE_IN_CHROME_TITLE).c_str(), |
| 153 MB_OK); | 153 MB_OK); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void SetupDialog::SetState(ServiceController::State status, | 156 void SetupDialog::SetState(ServiceController::State status, |
| 157 const base::string16& user, | 157 const base::string16& user, |
| 158 bool is_logging_enabled) { | 158 bool is_logging_enabled) { |
| 159 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); | 159 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 160 state_ = status; | 160 state_ = status; |
| 161 | 161 |
| 162 DWORD status_string = 0; | 162 DWORD status_string = 0; |
| 163 switch(status) { | 163 switch(status) { |
| 164 case ServiceController::STATE_NOT_FOUND: | 164 case ServiceController::STATE_NOT_FOUND: |
| 165 status_string = IDS_SERVICE_NOT_FOUND; | 165 status_string = IDS_SERVICE_NOT_FOUND; |
| 166 break; | 166 break; |
| 167 case ServiceController::STATE_STOPPED: | 167 case ServiceController::STATE_STOPPED: |
| 168 status_string = IDS_SERVICE_STOPPED; | 168 status_string = IDS_SERVICE_STOPPED; |
| 169 break; | 169 break; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 base::string16 SetupDialog::GetPassword() const { | 297 base::string16 SetupDialog::GetPassword() const { |
| 298 return GetDlgItemText(IDC_PASSWORD); | 298 return GetDlgItemText(IDC_PASSWORD); |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool SetupDialog::IsLoggingEnabled() const{ | 301 bool SetupDialog::IsLoggingEnabled() const{ |
| 302 return IsDlgButtonChecked(IDC_LOGGING) == BST_CHECKED; | 302 return IsDlgButtonChecked(IDC_LOGGING) == BST_CHECKED; |
| 303 } | 303 } |
| 304 | 304 |
| 305 void SetupDialog::UpdateState() { | 305 void SetupDialog::UpdateState() { |
| 306 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 306 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 307 controller_.UpdateState(); | 307 controller_.UpdateState(); |
| 308 PostUITask(base::Bind(&SetupDialog::SetState, this, controller_.state(), | 308 PostUITask(base::Bind(&SetupDialog::SetState, this, controller_.state(), |
| 309 controller_.user(), controller_.is_logging_enabled())); | 309 controller_.user(), controller_.is_logging_enabled())); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void SetupDialog::ShowError(const base::string16& error_message) { | 312 void SetupDialog::ShowError(const base::string16& error_message) { |
| 313 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 313 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 314 PostUITask(base::Bind(&SetupDialog::SetState, | 314 PostUITask(base::Bind(&SetupDialog::SetState, |
| 315 this, | 315 this, |
| 316 ServiceController::STATE_UNKNOWN, | 316 ServiceController::STATE_UNKNOWN, |
| 317 L"", | 317 L"", |
| 318 false)); | 318 false)); |
| 319 PostUITask(base::Bind(&SetupDialog::ShowErrorMessageBox, this, | 319 PostUITask(base::Bind(&SetupDialog::ShowErrorMessageBox, this, |
| 320 error_message)); | 320 error_message)); |
| 321 LOG(ERROR) << error_message; | 321 LOG(ERROR) << error_message; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void SetupDialog::ShowError(int string_id) { | 324 void SetupDialog::ShowError(int string_id) { |
| 325 ShowError(cloud_print::LoadLocalString(string_id)); | 325 ShowError(cloud_print::LoadLocalString(string_id)); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void SetupDialog::ShowError(HRESULT hr) { | 328 void SetupDialog::ShowError(HRESULT hr) { |
| 329 ShowError(GetErrorMessage(hr)); | 329 ShowError(GetErrorMessage(hr)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void SetupDialog::Install(const base::string16& user, | 332 void SetupDialog::Install(const base::string16& user, |
| 333 const base::string16& password, | 333 const base::string16& password, |
| 334 bool enable_logging) { | 334 bool enable_logging) { |
| 335 // Don't forget to update state on exit. | 335 // Don't forget to update state on exit. |
| 336 base::ScopedClosureRunner scoped_update_status( | 336 base::ScopedClosureRunner scoped_update_status( |
| 337 base::Bind(&SetupDialog::UpdateState, this)); | 337 base::Bind(&SetupDialog::UpdateState, this)); |
| 338 | 338 |
| 339 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 339 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 340 | 340 |
| 341 SetupListener setup(GetUser()); | 341 SetupListener setup(GetUser()); |
| 342 HRESULT hr = controller_.InstallCheckService(user, password, | 342 HRESULT hr = controller_.InstallCheckService(user, password, |
| 343 base::FilePath()); | 343 base::FilePath()); |
| 344 if (FAILED(hr)) | 344 if (FAILED(hr)) |
| 345 return ShowError(hr); | 345 return ShowError(hr); |
| 346 | 346 |
| 347 { | 347 { |
| 348 // Always uninstall service after requirements check. | 348 // Always uninstall service after requirements check. |
| 349 base::ScopedClosureRunner scoped_uninstall( | 349 base::ScopedClosureRunner scoped_uninstall( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 enable_logging); | 397 enable_logging); |
| 398 if (FAILED(hr)) | 398 if (FAILED(hr)) |
| 399 return ShowError(hr); | 399 return ShowError(hr); |
| 400 | 400 |
| 401 hr = controller_.StartService(); | 401 hr = controller_.StartService(); |
| 402 if (FAILED(hr)) | 402 if (FAILED(hr)) |
| 403 return ShowError(hr); | 403 return ShowError(hr); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void SetupDialog::Start() { | 406 void SetupDialog::Start() { |
| 407 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 407 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 408 HRESULT hr = controller_.StartService(); | 408 HRESULT hr = controller_.StartService(); |
| 409 if (FAILED(hr)) | 409 if (FAILED(hr)) |
| 410 ShowError(hr); | 410 ShowError(hr); |
| 411 UpdateState(); | 411 UpdateState(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void SetupDialog::Stop() { | 414 void SetupDialog::Stop() { |
| 415 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 415 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 416 HRESULT hr = controller_.StopService(); | 416 HRESULT hr = controller_.StopService(); |
| 417 if (FAILED(hr)) | 417 if (FAILED(hr)) |
| 418 ShowError(hr); | 418 ShowError(hr); |
| 419 UpdateState(); | 419 UpdateState(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 void SetupDialog::Uninstall() { | 422 void SetupDialog::Uninstall() { |
| 423 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 423 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 424 HRESULT hr = controller_.UninstallService(); | 424 HRESULT hr = controller_.UninstallService(); |
| 425 if (FAILED(hr)) | 425 if (FAILED(hr)) |
| 426 ShowError(hr); | 426 ShowError(hr); |
| 427 UpdateState(); | 427 UpdateState(); |
| 428 } | 428 } |
| 429 | 429 |
| 430 class CloudPrintServiceConfigModule | 430 class CloudPrintServiceConfigModule |
| 431 : public ATL::CAtlExeModuleT<CloudPrintServiceConfigModule> { | 431 : public ATL::CAtlExeModuleT<CloudPrintServiceConfigModule> { |
| 432 }; | 432 }; |
| 433 | 433 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 444 scoped_refptr<SetupDialog> dialog(new SetupDialog()); | 444 scoped_refptr<SetupDialog> dialog(new SetupDialog()); |
| 445 dialog->Create(NULL); | 445 dialog->Create(NULL); |
| 446 dialog->ShowWindow(SW_SHOW); | 446 dialog->ShowWindow(SW_SHOW); |
| 447 scoped_ptr<SetupDialog::MessageFilter> filter( | 447 scoped_ptr<SetupDialog::MessageFilter> filter( |
| 448 new SetupDialog::MessageFilter(dialog)); | 448 new SetupDialog::MessageFilter(dialog)); |
| 449 loop.SetMessageFilter(filter.Pass()); | 449 loop.SetMessageFilter(filter.Pass()); |
| 450 | 450 |
| 451 loop.Run(); | 451 loop.Run(); |
| 452 return 0; | 452 return 0; |
| 453 } | 453 } |
| OLD | NEW |