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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_pump_dispatcher.h" | 14 #include "base/message_loop/message_pump_dispatcher.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "cloud_print/common/win/cloud_print_utils.h" | 19 #include "cloud_print/common/win/cloud_print_utils.h" |
20 #include "cloud_print/service/resources.h" | 20 #include "cloud_print/resources.h" |
21 #include "cloud_print/service/service_state.h" | 21 #include "cloud_print/service/service_state.h" |
22 #include "cloud_print/service/win/chrome_launcher.h" | 22 #include "cloud_print/service/win/chrome_launcher.h" |
23 #include "cloud_print/service/win/service_controller.h" | 23 #include "cloud_print/service/win/service_controller.h" |
24 #include "cloud_print/service/win/service_utils.h" | 24 #include "cloud_print/service/win/service_utils.h" |
25 #include "cloud_print/service/win/setup_listener.h" | 25 #include "cloud_print/service/win/setup_listener.h" |
26 | 26 |
27 using cloud_print::LoadLocalString; | 27 using cloud_print::LoadLocalString; |
28 using cloud_print::GetErrorMessage; | 28 using cloud_print::GetErrorMessage; |
29 | 29 |
30 class SetupDialog : public base::RefCounted<SetupDialog>, | 30 class SetupDialog : public base::RefCounted<SetupDialog>, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 GetDlgItem(IDC_INSTALL).EnableWindow(FALSE); | 290 GetDlgItem(IDC_INSTALL).EnableWindow(FALSE); |
291 GetDlgItem(IDC_USER).EnableWindow(FALSE); | 291 GetDlgItem(IDC_USER).EnableWindow(FALSE); |
292 GetDlgItem(IDC_PASSWORD).EnableWindow(FALSE); | 292 GetDlgItem(IDC_PASSWORD).EnableWindow(FALSE); |
293 GetDlgItem(IDC_LOGGING).EnableWindow(FALSE); | 293 GetDlgItem(IDC_LOGGING).EnableWindow(FALSE); |
294 } | 294 } |
295 | 295 |
296 base::string16 SetupDialog::GetDlgItemText(int id) const { | 296 base::string16 SetupDialog::GetDlgItemText(int id) const { |
297 const ATL::CWindow& item = GetDlgItem(id); | 297 const ATL::CWindow& item = GetDlgItem(id); |
298 size_t length = item.GetWindowTextLength(); | 298 size_t length = item.GetWindowTextLength(); |
299 base::string16 result(length + 1, L'\0'); | 299 base::string16 result(length + 1, L'\0'); |
300 result.resize(item.GetWindowText(&result[0], | 300 result.resize(item.GetWindowText(&result[0], result.size())); |
301 static_cast<int>(result.size()))); | |
302 return result; | 301 return result; |
303 } | 302 } |
304 | 303 |
305 base::string16 SetupDialog::GetUser() const { | 304 base::string16 SetupDialog::GetUser() const { |
306 return GetDlgItemText(IDC_USER); | 305 return GetDlgItemText(IDC_USER); |
307 } | 306 } |
308 | 307 |
309 base::string16 SetupDialog::GetPassword() const { | 308 base::string16 SetupDialog::GetPassword() const { |
310 return GetDlgItemText(IDC_PASSWORD); | 309 return GetDlgItemText(IDC_PASSWORD); |
311 } | 310 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 if (service_state.FromString(contents)) | 389 if (service_state.FromString(contents)) |
391 proxy_id = service_state.proxy_id(); | 390 proxy_id = service_state.proxy_id(); |
392 } | 391 } |
393 PostUITask(base::Bind(&SetupDialog::AskToCloseChrome, this)); | 392 PostUITask(base::Bind(&SetupDialog::AskToCloseChrome, this)); |
394 contents = ChromeLauncher::CreateServiceStateFile(proxy_id, setup.printers()); | 393 contents = ChromeLauncher::CreateServiceStateFile(proxy_id, setup.printers()); |
395 | 394 |
396 if (contents.empty()) | 395 if (contents.empty()) |
397 return ShowError(IDS_ERROR_FAILED_CREATE_CONFIG); | 396 return ShowError(IDS_ERROR_FAILED_CREATE_CONFIG); |
398 | 397 |
399 size_t written = base::WriteFile(file, contents.c_str(), | 398 size_t written = base::WriteFile(file, contents.c_str(), |
400 static_cast<int>(contents.size())); | 399 contents.size()); |
401 if (written != contents.size()) { | 400 if (written != contents.size()) { |
402 DWORD last_error = GetLastError(); | 401 DWORD last_error = GetLastError(); |
403 if (!last_error) | 402 if (!last_error) |
404 return ShowError(IDS_ERROR_FAILED_CREATE_CONFIG); | 403 return ShowError(IDS_ERROR_FAILED_CREATE_CONFIG); |
405 return ShowError(HRESULT_FROM_WIN32(last_error)); | 404 return ShowError(HRESULT_FROM_WIN32(last_error)); |
406 } | 405 } |
407 | 406 |
408 hr = controller_.InstallConnectorService(user, password, base::FilePath(), | 407 hr = controller_.InstallConnectorService(user, password, base::FilePath(), |
409 enable_logging); | 408 enable_logging); |
410 if (FAILED(hr)) | 409 if (FAILED(hr)) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 453 |
455 base::MessageLoopForUI loop; | 454 base::MessageLoopForUI loop; |
456 scoped_refptr<SetupDialog> dialog(new SetupDialog()); | 455 scoped_refptr<SetupDialog> dialog(new SetupDialog()); |
457 dialog->Create(NULL); | 456 dialog->Create(NULL); |
458 dialog->ShowWindow(SW_SHOW); | 457 dialog->ShowWindow(SW_SHOW); |
459 SetupDialog::Dispatcher dispatcher(dialog.get()); | 458 SetupDialog::Dispatcher dispatcher(dialog.get()); |
460 base::RunLoop run_loop(&dispatcher); | 459 base::RunLoop run_loop(&dispatcher); |
461 run_loop.Run(); | 460 run_loop.Run(); |
462 return 0; | 461 return 0; |
463 } | 462 } |
OLD | NEW |