| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <security.h> | 6 #include <security.h> |
| 7 | 7 |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <iostream> | 9 #include <iostream> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 for (size_t i = 0; i < arraysize(kSwitchHelp); ++i) { | 74 for (size_t i = 0; i < arraysize(kSwitchHelp); ++i) { |
| 75 std::cout << std::setiosflags(std::ios::left); | 75 std::cout << std::setiosflags(std::ios::left); |
| 76 std::cout << " -" << std::setw(16) << kSwitchHelp[i].name; | 76 std::cout << " -" << std::setw(16) << kSwitchHelp[i].name; |
| 77 std::cout << cloud_print::LoadLocalString(kSwitchHelp[i].description); | 77 std::cout << cloud_print::LoadLocalString(kSwitchHelp[i].description); |
| 78 std::cout << "\n"; | 78 std::cout << "\n"; |
| 79 } | 79 } |
| 80 std::cout << "\n"; | 80 std::cout << "\n"; |
| 81 } | 81 } |
| 82 | 82 |
| 83 string16 GetOption(int string_id, const string16& default, | 83 base::string16 GetOption(int string_id, const base::string16& default, |
| 84 bool secure) { | 84 bool secure) { |
| 85 string16 prompt_format = cloud_print::LoadLocalString(string_id) ; | 85 base::string16 prompt_format = cloud_print::LoadLocalString(string_id); |
| 86 std::vector<string16> substitutions(1, default); | 86 std::vector<base::string16> substitutions(1, default); |
| 87 std::cout << ReplaceStringPlaceholders(prompt_format, substitutions, NULL); | 87 std::cout << ReplaceStringPlaceholders(prompt_format, substitutions, NULL); |
| 88 string16 tmp; | 88 base::string16 tmp; |
| 89 if (secure) { | 89 if (secure) { |
| 90 DWORD saved_mode = 0; | 90 DWORD saved_mode = 0; |
| 91 // Don't close. | 91 // Don't close. |
| 92 HANDLE stdin_handle = ::GetStdHandle(STD_INPUT_HANDLE); | 92 HANDLE stdin_handle = ::GetStdHandle(STD_INPUT_HANDLE); |
| 93 ::GetConsoleMode(stdin_handle, &saved_mode); | 93 ::GetConsoleMode(stdin_handle, &saved_mode); |
| 94 ::SetConsoleMode(stdin_handle, saved_mode & ~ENABLE_ECHO_INPUT); | 94 ::SetConsoleMode(stdin_handle, saved_mode & ~ENABLE_ECHO_INPUT); |
| 95 std::getline(std::wcin, tmp); | 95 std::getline(std::wcin, tmp); |
| 96 ::SetConsoleMode(stdin_handle, saved_mode); | 96 ::SetConsoleMode(stdin_handle, saved_mode); |
| 97 std::cout << "\n"; | 97 std::cout << "\n"; |
| 98 } else { | 98 } else { |
| 99 std::getline(std::wcin, tmp); | 99 std::getline(std::wcin, tmp); |
| 100 } | 100 } |
| 101 if (tmp.empty()) | 101 if (tmp.empty()) |
| 102 return default; | 102 return default; |
| 103 return tmp; | 103 return tmp; |
| 104 } | 104 } |
| 105 | 105 |
| 106 HRESULT ReportError(HRESULT hr, int string_id) { | 106 HRESULT ReportError(HRESULT hr, int string_id) { |
| 107 LOG(ERROR) << cloud_print::GetErrorMessage(hr); | 107 LOG(ERROR) << cloud_print::GetErrorMessage(hr); |
| 108 std::cerr << cloud_print::LoadLocalString(string_id); | 108 std::cerr << cloud_print::LoadLocalString(string_id); |
| 109 std::cerr << "\n"; | 109 std::cerr << "\n"; |
| 110 return hr; | 110 return hr; |
| 111 } | 111 } |
| 112 | 112 |
| 113 string16 StateAsString(ServiceController::State state) { | 113 base::string16 StateAsString(ServiceController::State state) { |
| 114 DWORD string_id = 0; | 114 DWORD string_id = 0; |
| 115 switch(state) { | 115 switch(state) { |
| 116 case ServiceController::STATE_NOT_FOUND: | 116 case ServiceController::STATE_NOT_FOUND: |
| 117 string_id = IDS_SERVICE_NOT_FOUND; | 117 string_id = IDS_SERVICE_NOT_FOUND; |
| 118 break; | 118 break; |
| 119 case ServiceController::STATE_STOPPED: | 119 case ServiceController::STATE_STOPPED: |
| 120 string_id = IDS_SERVICE_STOPPED; | 120 string_id = IDS_SERVICE_STOPPED; |
| 121 break; | 121 break; |
| 122 case ServiceController::STATE_RUNNING: | 122 case ServiceController::STATE_RUNNING: |
| 123 string_id = IDS_SERVICE_RUNNING; | 123 string_id = IDS_SERVICE_RUNNING; |
| 124 break; | 124 break; |
| 125 } | 125 } |
| 126 return string_id ? cloud_print::LoadLocalString(string_id) : string16(); | 126 return string_id ? cloud_print::LoadLocalString(string_id) : base::string16(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 | 131 |
| 132 class CloudPrintServiceModule | 132 class CloudPrintServiceModule |
| 133 : public ATL::CAtlServiceModuleT<CloudPrintServiceModule, | 133 : public ATL::CAtlServiceModuleT<CloudPrintServiceModule, |
| 134 IDS_SERVICE_NAME> { | 134 IDS_SERVICE_NAME> { |
| 135 public: | 135 public: |
| 136 typedef ATL::CAtlServiceModuleT<CloudPrintServiceModule, | 136 typedef ATL::CAtlServiceModuleT<CloudPrintServiceModule, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (!user_data_dir_switch_.empty()) | 207 if (!user_data_dir_switch_.empty()) |
| 208 user_data_dir_switch_ = base::MakeAbsoluteFilePath(user_data_dir_switch_); | 208 user_data_dir_switch_ = base::MakeAbsoluteFilePath(user_data_dir_switch_); |
| 209 | 209 |
| 210 if (command_line.HasSwitch(kStopSwitch)) | 210 if (command_line.HasSwitch(kStopSwitch)) |
| 211 return controller_->StopService(); | 211 return controller_->StopService(); |
| 212 | 212 |
| 213 if (command_line.HasSwitch(kUninstallSwitch)) | 213 if (command_line.HasSwitch(kUninstallSwitch)) |
| 214 return controller_->UninstallService(); | 214 return controller_->UninstallService(); |
| 215 | 215 |
| 216 if (command_line.HasSwitch(kInstallSwitch)) { | 216 if (command_line.HasSwitch(kInstallSwitch)) { |
| 217 string16 run_as_user; | 217 base::string16 run_as_user; |
| 218 string16 run_as_password; | 218 base::string16 run_as_password; |
| 219 base::FilePath user_data_dir; | 219 base::FilePath user_data_dir; |
| 220 std::vector<std::string> printers; | 220 std::vector<std::string> printers; |
| 221 HRESULT hr = SelectWindowsAccount(&run_as_user, &run_as_password, | 221 HRESULT hr = SelectWindowsAccount(&run_as_user, &run_as_password, |
| 222 &user_data_dir, &printers); | 222 &user_data_dir, &printers); |
| 223 if (FAILED(hr)) | 223 if (FAILED(hr)) |
| 224 return hr; | 224 return hr; |
| 225 | 225 |
| 226 DCHECK(user_data_dir_switch_.empty() || | 226 DCHECK(user_data_dir_switch_.empty() || |
| 227 user_data_dir_switch_ == user_data_dir); | 227 user_data_dir_switch_ == user_data_dir); |
| 228 | 228 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 255 *is_service = true; | 255 *is_service = true; |
| 256 check_requirements_ = command_line.HasSwitch(kRequirementsSwitch); | 256 check_requirements_ = command_line.HasSwitch(kRequirementsSwitch); |
| 257 return S_OK; | 257 return S_OK; |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 InvalidUsage(); | 261 InvalidUsage(); |
| 262 return S_FALSE; | 262 return S_FALSE; |
| 263 } | 263 } |
| 264 | 264 |
| 265 HRESULT SelectWindowsAccount(string16* run_as_user, string16* run_as_password, | 265 HRESULT SelectWindowsAccount(base::string16* run_as_user, |
| 266 base::string16* run_as_password, |
| 266 base::FilePath* user_data_dir, | 267 base::FilePath* user_data_dir, |
| 267 std::vector<std::string>* printers) { | 268 std::vector<std::string>* printers) { |
| 268 *run_as_user = GetCurrentUserName(); | 269 *run_as_user = GetCurrentUserName(); |
| 269 std::cout << cloud_print::LoadLocalString(IDS_WINDOWS_USER_PROMPT1) << "\n"; | 270 std::cout << cloud_print::LoadLocalString(IDS_WINDOWS_USER_PROMPT1) << "\n"; |
| 270 *run_as_user = GetOption(IDS_WINDOWS_USER_PROMPT2, *run_as_user, false); | 271 *run_as_user = GetOption(IDS_WINDOWS_USER_PROMPT2, *run_as_user, false); |
| 271 *run_as_user = ReplaceLocalHostInName(*run_as_user); | 272 *run_as_user = ReplaceLocalHostInName(*run_as_user); |
| 272 *run_as_password = GetOption(IDS_WINDOWS_PASSWORD_PROMPT, L"", true); | 273 *run_as_password = GetOption(IDS_WINDOWS_PASSWORD_PROMPT, L"", true); |
| 273 SetupListener setup(*run_as_user); | 274 SetupListener setup(*run_as_user); |
| 274 HRESULT hr = controller_->InstallCheckService(*run_as_user, | 275 HRESULT hr = controller_->InstallCheckService(*run_as_user, |
| 275 *run_as_password, | 276 *run_as_password, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 333 |
| 333 std::string contents; | 334 std::string contents; |
| 334 ServiceState service_state; | 335 ServiceState service_state; |
| 335 | 336 |
| 336 bool is_valid = base::ReadFileToString(file, &contents) && | 337 bool is_valid = base::ReadFileToString(file, &contents) && |
| 337 service_state.FromString(contents); | 338 service_state.FromString(contents); |
| 338 std::string proxy_id = service_state.proxy_id(); | 339 std::string proxy_id = service_state.proxy_id(); |
| 339 | 340 |
| 340 LOG(INFO) << file.value() << ": " << contents; | 341 LOG(INFO) << file.value() << ": " << contents; |
| 341 | 342 |
| 342 string16 message = | 343 base::string16 message = |
| 343 cloud_print::LoadLocalString(IDS_ADD_PRINTERS_USING_CHROME); | 344 cloud_print::LoadLocalString(IDS_ADD_PRINTERS_USING_CHROME); |
| 344 std::cout << "\n" << message.c_str() << "\n" ; | 345 std::cout << "\n" << message.c_str() << "\n" ; |
| 345 std::string new_contents = | 346 std::string new_contents = |
| 346 ChromeLauncher::CreateServiceStateFile(proxy_id, printers); | 347 ChromeLauncher::CreateServiceStateFile(proxy_id, printers); |
| 347 | 348 |
| 348 if (new_contents.empty()) { | 349 if (new_contents.empty()) { |
| 349 return ReportError(E_FAIL, IDS_ERROR_FAILED_CREATE_CONFIG); | 350 return ReportError(E_FAIL, IDS_ERROR_FAILED_CREATE_CONFIG); |
| 350 } | 351 } |
| 351 | 352 |
| 352 if (new_contents != contents) { | 353 if (new_contents != contents) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 410 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 410 logging::InitLogging(settings); | 411 logging::InitLogging(settings); |
| 411 | 412 |
| 412 logging::SetMinLogLevel( | 413 logging::SetMinLogLevel( |
| 413 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableLogging) ? | 414 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableLogging) ? |
| 414 logging::LOG_INFO : logging::LOG_FATAL); | 415 logging::LOG_INFO : logging::LOG_FATAL); |
| 415 | 416 |
| 416 return _AtlModule.WinMain(0); | 417 return _AtlModule.WinMain(0); |
| 417 } | 418 } |
| 418 | 419 |
| OLD | NEW |