Chromium Code Reviews| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 LRESULT OnDestroy(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); | 70 LRESULT OnDestroy(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); |
| 71 | 71 |
| 72 void PostUITask(const base::Closure& task); | 72 void PostUITask(const base::Closure& task); |
| 73 void PostIOTask(const base::Closure& task); | 73 void PostIOTask(const base::Closure& task); |
| 74 | 74 |
| 75 // UI Calls. | 75 // UI Calls. |
| 76 | 76 |
| 77 // Disables all controls after users actions. | 77 // Disables all controls after users actions. |
| 78 void DisableControls(); | 78 void DisableControls(); |
| 79 // Updates state of controls after when we received service status. | 79 // Updates state of controls after when we received service status. |
| 80 void SetState(ServiceController::State state, const string16& user, | 80 void SetState(ServiceController::State state, const base::string16& user, |
| 81 bool is_logging_enabled); | 81 bool is_logging_enabled); |
| 82 // Show message box with error. | 82 // Show message box with error. |
| 83 void ShowErrorMessageBox(const string16& error_message); | 83 void ShowErrorMessageBox(const base::string16& error_message); |
| 84 // Show use message box instructions how to deal with opened Chrome window. | 84 // Show use message box instructions how to deal with opened Chrome window. |
| 85 void AskToCloseChrome(); | 85 void AskToCloseChrome(); |
| 86 string16 GetDlgItemText(int id) const; | 86 base::string16 GetDlgItemText(int id) const; |
| 87 string16 GetUser() const; | 87 base::string16 GetUser() const; |
| 88 string16 GetPassword() const; | 88 base::string16 GetPassword() const; |
| 89 bool IsLoggingEnabled() const; | 89 bool IsLoggingEnabled() const; |
| 90 bool IsInstalled() const { | 90 bool IsInstalled() const { |
| 91 return state_ > ServiceController::STATE_NOT_FOUND; | 91 return state_ > ServiceController::STATE_NOT_FOUND; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // IO Calls. | 94 // IO Calls. |
| 95 // Installs service. | 95 // Installs service. |
| 96 void Install(const string16& user, const string16& password, | 96 void Install(const base::string16& user, const base::string16& password, |
| 97 bool enable_logging); | 97 bool enable_logging); |
| 98 // Starts service. | 98 // Starts service. |
| 99 void Start(); | 99 void Start(); |
| 100 // Stops service. | 100 // Stops service. |
| 101 void Stop(); | 101 void Stop(); |
| 102 // Uninstall service. | 102 // Uninstall service. |
| 103 void Uninstall(); | 103 void Uninstall(); |
| 104 // Update service state. | 104 // Update service state. |
| 105 void UpdateState(); | 105 void UpdateState(); |
| 106 // Posts task to UI thread to show error using string id. | 106 // Posts task to UI thread to show error using string id. |
| 107 void ShowError(int string_id); | 107 void ShowError(int string_id); |
| 108 // Posts task to UI thread to show error using string. | 108 // Posts task to UI thread to show error using string. |
| 109 void ShowError(const string16& error_message); | 109 void ShowError(const base::string16& error_message); |
| 110 // Posts task to UI thread to show error using error code. | 110 // Posts task to UI thread to show error using error code. |
| 111 void ShowError(HRESULT hr); | 111 void ShowError(HRESULT hr); |
| 112 | 112 |
| 113 ServiceController::State state_; | 113 ServiceController::State state_; |
| 114 base::Thread worker_; | 114 base::Thread worker_; |
| 115 | 115 |
| 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_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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 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::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); |
| 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::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); |
| 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 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::MessageLoop::current()->IsType(base::MessageLoop::TYPE_UI)); |
| 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: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 275 } |
| 276 | 276 |
| 277 void SetupDialog::DisableControls() { | 277 void SetupDialog::DisableControls() { |
| 278 GetDlgItem(IDC_START).EnableWindow(FALSE); | 278 GetDlgItem(IDC_START).EnableWindow(FALSE); |
| 279 GetDlgItem(IDC_INSTALL).EnableWindow(FALSE); | 279 GetDlgItem(IDC_INSTALL).EnableWindow(FALSE); |
| 280 GetDlgItem(IDC_USER).EnableWindow(FALSE); | 280 GetDlgItem(IDC_USER).EnableWindow(FALSE); |
| 281 GetDlgItem(IDC_PASSWORD).EnableWindow(FALSE); | 281 GetDlgItem(IDC_PASSWORD).EnableWindow(FALSE); |
| 282 GetDlgItem(IDC_LOGGING).EnableWindow(FALSE); | 282 GetDlgItem(IDC_LOGGING).EnableWindow(FALSE); |
| 283 } | 283 } |
| 284 | 284 |
| 285 string16 SetupDialog::GetDlgItemText(int id) const { | 285 base::string16 SetupDialog::GetDlgItemText(int id) const { |
| 286 const ATL::CWindow& item = GetDlgItem(id); | 286 const ATL::CWindow& item = GetDlgItem(id); |
| 287 size_t length = item.GetWindowTextLength(); | 287 size_t length = item.GetWindowTextLength(); |
| 288 string16 result(length + 1, L'\0'); | 288 base::string16 result(length + 1, L'\0'); |
| 289 result.resize(item.GetWindowText(&result[0], result.size())); | 289 result.resize(item.GetWindowText(&result[0], result.size())); |
| 290 return result; | 290 return result; |
| 291 } | 291 } |
| 292 | 292 |
| 293 string16 SetupDialog::GetUser() const { | 293 base::string16 SetupDialog::GetUser() const { |
| 294 return GetDlgItemText(IDC_USER); | 294 return GetDlgItemText(IDC_USER); |
| 295 } | 295 } |
| 296 | 296 |
| 297 string16 SetupDialog::GetPassword() const{ | 297 base::string16 SetupDialog::GetPassword() const{ |
|
Scott Byer
2013/12/06 17:28:06
nit: space before {
| |
| 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::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); |
| 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 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::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); |
| 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 string16& user, const string16& password, | 332 void SetupDialog::Install(const base::string16& user, |
| 333 const base::string16& password, | |
| 333 bool enable_logging) { | 334 bool enable_logging) { |
| 334 // Don't forget to update state on exit. | 335 // Don't forget to update state on exit. |
| 335 base::ScopedClosureRunner scoped_update_status( | 336 base::ScopedClosureRunner scoped_update_status( |
| 336 base::Bind(&SetupDialog::UpdateState, this)); | 337 base::Bind(&SetupDialog::UpdateState, this)); |
| 337 | 338 |
| 338 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); | 339 DCHECK(base::MessageLoop::current()->IsType(base::MessageLoop::TYPE_IO)); |
| 339 | 340 |
| 340 SetupListener setup(GetUser()); | 341 SetupListener setup(GetUser()); |
| 341 HRESULT hr = controller_.InstallCheckService(user, password, | 342 HRESULT hr = controller_.InstallCheckService(user, password, |
| 342 base::FilePath()); | 343 base::FilePath()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 scoped_refptr<SetupDialog> dialog(new SetupDialog()); | 444 scoped_refptr<SetupDialog> dialog(new SetupDialog()); |
| 444 dialog->Create(NULL); | 445 dialog->Create(NULL); |
| 445 dialog->ShowWindow(SW_SHOW); | 446 dialog->ShowWindow(SW_SHOW); |
| 446 scoped_ptr<SetupDialog::MessageFilter> filter( | 447 scoped_ptr<SetupDialog::MessageFilter> filter( |
| 447 new SetupDialog::MessageFilter(dialog)); | 448 new SetupDialog::MessageFilter(dialog)); |
| 448 loop.SetMessageFilter(filter.Pass()); | 449 loop.SetMessageFilter(filter.Pass()); |
| 449 | 450 |
| 450 loop.Run(); | 451 loop.Run(); |
| 451 return 0; | 452 return 0; |
| 452 } | 453 } |
| OLD | NEW |