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/setup/daemon_controller.h" | 5 #include "remoting/host/setup/daemon_controller.h" |
6 | 6 |
7 #include <objbase.h> | 7 #include <objbase.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "base/timer.h" | 21 #include "base/timer.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "base/win/scoped_bstr.h" | 24 #include "base/win/scoped_bstr.h" |
| 25 #include "base/win/scoped_com_initializer.h" |
25 #include "base/win/scoped_comptr.h" | 26 #include "base/win/scoped_comptr.h" |
26 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
27 #include "remoting/base/scoped_sc_handle_win.h" | 28 #include "remoting/base/scoped_sc_handle_win.h" |
28 #include "remoting/host/branding.h" | 29 #include "remoting/host/branding.h" |
29 #include "remoting/host/setup/daemon_installer_win.h" | 30 #include "remoting/host/setup/daemon_installer_win.h" |
30 #include "remoting/host/usage_stats_consent.h" | 31 #include "remoting/host/usage_stats_consent.h" |
31 | 32 |
32 // MIDL-generated declarations and definitions. | 33 // MIDL-generated declarations and definitions. |
33 #include "remoting/host/elevated_controller.h" | 34 #include "remoting/host/elevated_controller.h" |
34 | 35 |
(...skipping 29 matching lines...) Expand all Loading... |
64 const int kUnprivilegedTimeoutSec = 60; | 65 const int kUnprivilegedTimeoutSec = 60; |
65 | 66 |
66 // A base::Thread implementation that initializes COM on the new thread. | 67 // A base::Thread implementation that initializes COM on the new thread. |
67 class ComThread : public base::Thread { | 68 class ComThread : public base::Thread { |
68 public: | 69 public: |
69 explicit ComThread(const char* name); | 70 explicit ComThread(const char* name); |
70 virtual ~ComThread(); | 71 virtual ~ComThread(); |
71 | 72 |
72 bool Start(); | 73 bool Start(); |
73 | 74 |
74 protected: | 75 private: |
75 virtual void Init() OVERRIDE; | 76 virtual void Init() OVERRIDE; |
76 virtual void CleanUp() OVERRIDE; | 77 virtual void CleanUp() OVERRIDE; |
77 | 78 |
| 79 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; |
| 80 |
78 DISALLOW_COPY_AND_ASSIGN(ComThread); | 81 DISALLOW_COPY_AND_ASSIGN(ComThread); |
79 }; | 82 }; |
80 | 83 |
81 class DaemonControllerWin : public remoting::DaemonController { | 84 class DaemonControllerWin : public remoting::DaemonController { |
82 public: | 85 public: |
83 DaemonControllerWin(); | 86 DaemonControllerWin(); |
84 virtual ~DaemonControllerWin(); | 87 virtual ~DaemonControllerWin(); |
85 | 88 |
86 virtual State GetState() OVERRIDE; | 89 virtual State GetState() OVERRIDE; |
87 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE; | 90 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 Stop(); | 179 Stop(); |
177 } | 180 } |
178 | 181 |
179 bool ComThread::Start() { | 182 bool ComThread::Start() { |
180 // N.B. The single threaded COM apartment must be run on a UI message loop. | 183 // N.B. The single threaded COM apartment must be run on a UI message loop. |
181 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); | 184 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); |
182 return StartWithOptions(thread_options); | 185 return StartWithOptions(thread_options); |
183 } | 186 } |
184 | 187 |
185 void ComThread::Init() { | 188 void ComThread::Init() { |
186 CoInitialize(NULL); | 189 com_initializer_.reset(new base::win::ScopedCOMInitializer()); |
187 } | 190 } |
188 | 191 |
189 void ComThread::CleanUp() { | 192 void ComThread::CleanUp() { |
190 CoUninitialize(); | 193 com_initializer_.reset(); |
191 } | 194 } |
192 | 195 |
193 DaemonControllerWin::DaemonControllerWin() | 196 DaemonControllerWin::DaemonControllerWin() |
194 : control_is_elevated_(false), | 197 : control_is_elevated_(false), |
195 window_handle_(NULL), | 198 window_handle_(NULL), |
196 worker_thread_(kDaemonControllerThreadName) { | 199 worker_thread_(kDaemonControllerThreadName) { |
197 if (!worker_thread_.Start()) { | 200 if (!worker_thread_.Start()) { |
198 LOG(FATAL) << "Failed to start the Daemon Controller worker thread."; | 201 LOG(FATAL) << "Failed to start the Daemon Controller worker thread."; |
199 } | 202 } |
200 } | 203 } |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 done.Run(true, !!allowed, !!set_by_policy); | 697 done.Run(true, !!allowed, !!set_by_policy); |
695 } | 698 } |
696 | 699 |
697 } // namespace | 700 } // namespace |
698 | 701 |
699 scoped_ptr<DaemonController> remoting::DaemonController::Create() { | 702 scoped_ptr<DaemonController> remoting::DaemonController::Create() { |
700 return scoped_ptr<DaemonController>(new DaemonControllerWin()); | 703 return scoped_ptr<DaemonController>(new DaemonControllerWin()); |
701 } | 704 } |
702 | 705 |
703 } // namespace remoting | 706 } // namespace remoting |
OLD | NEW |