diff options
author | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 19:21:39 +0000 |
---|---|---|
committer | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-27 19:21:39 +0000 |
commit | 3cb0d65cee30073d9978cb94787ab49897843dd3 (patch) | |
tree | a78444c6332f15488efbd4eb17f10e6a197f7e83 /remoting/host | |
parent | 29f18454253c0ca692ec46d86e6780f07154b87a (diff) | |
download | chromium_src-3cb0d65cee30073d9978cb94787ab49897843dd3.zip chromium_src-3cb0d65cee30073d9978cb94787ab49897843dd3.tar.gz chromium_src-3cb0d65cee30073d9978cb94787ab49897843dd3.tar.bz2 |
[Chromoting] Factor duplicated code out of the Windows daemon controller.
Review URL: http://codereview.chromium.org/10228019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/plugin/daemon_controller_win.cc | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/remoting/host/plugin/daemon_controller_win.cc b/remoting/host/plugin/daemon_controller_win.cc index 7f3a8f5..49b1809 100644 --- a/remoting/host/plugin/daemon_controller_win.cc +++ b/remoting/host/plugin/daemon_controller_win.cc @@ -108,6 +108,10 @@ class DaemonControllerWin : public remoting::DaemonController { // Opens the Chromoting service returning its handle in |service_out|. DWORD OpenService(ScopedScHandle* service_out); + // Converts a config dictionary to a scoped BSTR. + static void ConfigToString(const base::DictionaryValue& config, + ScopedBstr* out); + // The functions that actually do the work. They should be called in // the context of |worker_thread_|; void DoGetConfig(const GetConfigCallback& callback); @@ -342,6 +346,14 @@ DWORD DaemonControllerWin::OpenService(ScopedScHandle* service_out) { return ERROR_SUCCESS; } +void DaemonControllerWin::ConfigToString(const base::DictionaryValue& config, + ScopedBstr* out) { + std::string config_str; + base::JSONWriter::Write(&config, &config_str); + ScopedBstr config_scoped_bstr(UTF8ToUTF16(config_str).c_str()); + out->Swap(config_scoped_bstr); +} + void DaemonControllerWin::DoGetConfig(const GetConfigCallback& callback) { DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); @@ -443,17 +455,15 @@ void DaemonControllerWin::DoSetConfigAndStart( return; } - // Store the configuration. - std::string file_content; - base::JSONWriter::Write(config.get(), &file_content); - - ScopedBstr host_config(UTF8ToUTF16(file_content).c_str()); - if (host_config == NULL) { + // Set the configuration. + ScopedBstr config_str(NULL); + ConfigToString(*config, &config_str); + if (config_str == NULL) { done_callback.Run(HResultToAsyncResult(E_OUTOFMEMORY)); return; } - hr = control->SetConfig(host_config); + hr = control->SetConfig(config_str); if (FAILED(hr)) { done_callback.Run(HResultToAsyncResult(hr)); return; @@ -467,8 +477,6 @@ void DaemonControllerWin::DoSetConfigAndStart( void DaemonControllerWin::DoUpdateConfig( scoped_ptr<base::DictionaryValue> config, const CompletionCallback& done_callback) { - // TODO(simonmorris): Much of this code was copied from DoSetConfigAndStart(). - // Refactor. DCHECK(worker_thread_.message_loop_proxy()->BelongsToCurrentThread()); IDaemonControl* control = NULL; @@ -479,17 +487,15 @@ void DaemonControllerWin::DoUpdateConfig( return; } - // Store the configuration. - std::string file_content; - base::JSONWriter::Write(config.get(), &file_content); - - ScopedBstr host_config(UTF8ToUTF16(file_content).c_str()); - if (host_config == NULL) { + // Update the configuration. + ScopedBstr config_str(NULL); + ConfigToString(*config, &config_str); + if (config_str == NULL) { done_callback.Run(HResultToAsyncResult(E_OUTOFMEMORY)); return; } - hr = control->UpdateConfig(host_config); + hr = control->UpdateConfig(config_str); done_callback.Run(HResultToAsyncResult(hr)); } |