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 "remoting/host/win/elevated_controller.h" | 5 #include "remoting/host/win/elevated_controller.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 HRESULT hr = ReadConfig(config_dir.Append(kUnprivilegedConfigFileName), | 315 HRESULT hr = ReadConfig(config_dir.Append(kUnprivilegedConfigFileName), |
316 &config); | 316 &config); |
317 if (FAILED(hr)) { | 317 if (FAILED(hr)) { |
318 return hr; | 318 return hr; |
319 } | 319 } |
320 | 320 |
321 // Convert the config back to a string and return it to the caller. | 321 // Convert the config back to a string and return it to the caller. |
322 std::string file_content; | 322 std::string file_content; |
323 base::JSONWriter::Write(config.get(), &file_content); | 323 base::JSONWriter::Write(config.get(), &file_content); |
324 | 324 |
325 *config_out = ::SysAllocString(UTF8ToUTF16(file_content).c_str()); | 325 *config_out = ::SysAllocString(base::UTF8ToUTF16(file_content).c_str()); |
326 if (config_out == NULL) { | 326 if (config_out == NULL) { |
327 return E_OUTOFMEMORY; | 327 return E_OUTOFMEMORY; |
328 } | 328 } |
329 | 329 |
330 return S_OK; | 330 return S_OK; |
331 } | 331 } |
332 | 332 |
333 STDMETHODIMP ElevatedController::GetVersion(BSTR* version_out) { | 333 STDMETHODIMP ElevatedController::GetVersion(BSTR* version_out) { |
334 // Report the product version number of the daemon controller binary as | 334 // Report the product version number of the daemon controller binary as |
335 // the host version. | 335 // the host version. |
(...skipping 15 matching lines...) Expand all Loading... |
351 return S_OK; | 351 return S_OK; |
352 } | 352 } |
353 | 353 |
354 STDMETHODIMP ElevatedController::SetConfig(BSTR config) { | 354 STDMETHODIMP ElevatedController::SetConfig(BSTR config) { |
355 // Determine the config directory path and create it if necessary. | 355 // Determine the config directory path and create it if necessary. |
356 base::FilePath config_dir = remoting::GetConfigDir(); | 356 base::FilePath config_dir = remoting::GetConfigDir(); |
357 if (!base::CreateDirectory(config_dir)) { | 357 if (!base::CreateDirectory(config_dir)) { |
358 return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); | 358 return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); |
359 } | 359 } |
360 | 360 |
361 std::string file_content = UTF16ToUTF8( | 361 std::string file_content = base::UTF16ToUTF8( |
362 base::string16(static_cast<base::char16*>(config), ::SysStringLen(config))); | 362 base::string16(static_cast<base::char16*>(config), ::SysStringLen(config))); |
363 | 363 |
364 return WriteConfig(file_content.c_str(), file_content.size(), owner_window_); | 364 return WriteConfig(file_content.c_str(), file_content.size(), owner_window_); |
365 } | 365 } |
366 | 366 |
367 STDMETHODIMP ElevatedController::SetOwnerWindow(LONG_PTR window_handle) { | 367 STDMETHODIMP ElevatedController::SetOwnerWindow(LONG_PTR window_handle) { |
368 owner_window_ = reinterpret_cast<HWND>(window_handle); | 368 owner_window_ = reinterpret_cast<HWND>(window_handle); |
369 return S_OK; | 369 return S_OK; |
370 } | 370 } |
371 | 371 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 << "Failed to stop the '" << kWindowsServiceName << "'service"; | 444 << "Failed to stop the '" << kWindowsServiceName << "'service"; |
445 return HRESULT_FROM_WIN32(error); | 445 return HRESULT_FROM_WIN32(error); |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 return S_OK; | 449 return S_OK; |
450 } | 450 } |
451 | 451 |
452 STDMETHODIMP ElevatedController::UpdateConfig(BSTR config) { | 452 STDMETHODIMP ElevatedController::UpdateConfig(BSTR config) { |
453 // Parse the config. | 453 // Parse the config. |
454 std::string config_str = UTF16ToUTF8( | 454 std::string config_str = base::UTF16ToUTF8( |
455 base::string16(static_cast<base::char16*>(config), ::SysStringLen(config))); | 455 base::string16(static_cast<base::char16*>(config), ::SysStringLen(config))); |
456 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_str)); | 456 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_str)); |
457 if (!config_value.get()) { | 457 if (!config_value.get()) { |
458 return E_FAIL; | 458 return E_FAIL; |
459 } | 459 } |
460 base::DictionaryValue* config_dict = NULL; | 460 base::DictionaryValue* config_dict = NULL; |
461 if (!config_value->GetAsDictionary(&config_dict)) { | 461 if (!config_value->GetAsDictionary(&config_dict)) { |
462 return E_FAIL; | 462 return E_FAIL; |
463 } | 463 } |
464 // Check for bad keys. | 464 // Check for bad keys. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 << "Failed to open to the '" << kWindowsServiceName << "' service"; | 528 << "Failed to open to the '" << kWindowsServiceName << "' service"; |
529 | 529 |
530 return HRESULT_FROM_WIN32(error); | 530 return HRESULT_FROM_WIN32(error); |
531 } | 531 } |
532 | 532 |
533 service_out->Set(service.Take()); | 533 service_out->Set(service.Take()); |
534 return S_OK; | 534 return S_OK; |
535 } | 535 } |
536 | 536 |
537 } // namespace remoting | 537 } // namespace remoting |
OLD | NEW |