Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: remoting/host/setup/daemon_controller_win.cc

Issue 11048029: Allow Thread to initialize COM for Windows consumers who need it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/fake_audio_output_stream.cc ('k') | ui/base/dialogs/base_shell_dialog_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
26 #include "base/win/scoped_comptr.h" 25 #include "base/win/scoped_comptr.h"
27 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
28 #include "remoting/base/scoped_sc_handle_win.h" 27 #include "remoting/base/scoped_sc_handle_win.h"
29 #include "remoting/host/branding.h" 28 #include "remoting/host/branding.h"
30 #include "remoting/host/setup/daemon_installer_win.h" 29 #include "remoting/host/setup/daemon_installer_win.h"
31 #include "remoting/host/usage_stats_consent.h" 30 #include "remoting/host/usage_stats_consent.h"
32 31
33 // MIDL-generated declarations and definitions. 32 // MIDL-generated declarations and definitions.
34 #include "remoting/host/elevated_controller.h" 33 #include "remoting/host/elevated_controller.h"
35 34
(...skipping 21 matching lines...) Expand all
57 // sees. 56 // sees.
58 const int kPrivilegedTimeoutSec = 5 * 60; 57 const int kPrivilegedTimeoutSec = 5 * 60;
59 58
60 // The maximum duration of keeping a reference to an unprivileged instance of 59 // The maximum duration of keeping a reference to an unprivileged instance of
61 // the Daemon Controller. This interval should not be too long. If upgrade 60 // the Daemon Controller. This interval should not be too long. If upgrade
62 // happens while there is a live reference to a Daemon Controller instance 61 // happens while there is a live reference to a Daemon Controller instance
63 // the old binary still can be used. So dropping the references often makes sure 62 // the old binary still can be used. So dropping the references often makes sure
64 // that the old binary will go away sooner. 63 // that the old binary will go away sooner.
65 const int kUnprivilegedTimeoutSec = 60; 64 const int kUnprivilegedTimeoutSec = 60;
66 65
67 // A base::Thread implementation that initializes COM on the new thread.
68 class ComThread : public base::Thread {
69 public:
70 explicit ComThread(const char* name);
71 virtual ~ComThread();
72
73 bool Start();
74
75 private:
76 virtual void Init() OVERRIDE;
77 virtual void CleanUp() OVERRIDE;
78
79 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
80
81 DISALLOW_COPY_AND_ASSIGN(ComThread);
82 };
83
84 class DaemonControllerWin : public remoting::DaemonController { 66 class DaemonControllerWin : public remoting::DaemonController {
85 public: 67 public:
86 DaemonControllerWin(); 68 DaemonControllerWin();
87 virtual ~DaemonControllerWin(); 69 virtual ~DaemonControllerWin();
88 70
89 virtual State GetState() OVERRIDE; 71 virtual State GetState() OVERRIDE;
90 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE; 72 virtual void GetConfig(const GetConfigCallback& callback) OVERRIDE;
91 virtual void SetConfigAndStart( 73 virtual void SetConfigAndStart(
92 scoped_ptr<base::DictionaryValue> config, 74 scoped_ptr<base::DictionaryValue> config,
93 bool consent, 75 bool consent,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // controller. 140 // controller.
159 bool control_is_elevated_; 141 bool control_is_elevated_;
160 142
161 // This timer is used to release |control_| after a timeout. 143 // This timer is used to release |control_| after a timeout.
162 scoped_ptr<base::OneShotTimer<DaemonControllerWin> > release_timer_; 144 scoped_ptr<base::OneShotTimer<DaemonControllerWin> > release_timer_;
163 145
164 // Handle of the plugin window. 146 // Handle of the plugin window.
165 HWND window_handle_; 147 HWND window_handle_;
166 148
167 // The worker thread used for servicing long running operations. 149 // The worker thread used for servicing long running operations.
168 ComThread worker_thread_; 150 base::Thread worker_thread_;
169 151
170 scoped_ptr<DaemonInstallerWin> installer_; 152 scoped_ptr<DaemonInstallerWin> installer_;
171 153
172 DISALLOW_COPY_AND_ASSIGN(DaemonControllerWin); 154 DISALLOW_COPY_AND_ASSIGN(DaemonControllerWin);
173 }; 155 };
174 156
175 ComThread::ComThread(const char* name) : base::Thread(name) {
176 }
177
178 ComThread::~ComThread() {
179 Stop();
180 }
181
182 bool ComThread::Start() {
183 // N.B. The single threaded COM apartment must be run on a UI message loop.
184 base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0);
185 return StartWithOptions(thread_options);
186 }
187
188 void ComThread::Init() {
189 com_initializer_.reset(new base::win::ScopedCOMInitializer());
190 }
191
192 void ComThread::CleanUp() {
193 com_initializer_.reset();
194 }
195
196 DaemonControllerWin::DaemonControllerWin() 157 DaemonControllerWin::DaemonControllerWin()
197 : control_is_elevated_(false), 158 : control_is_elevated_(false),
198 window_handle_(NULL), 159 window_handle_(NULL),
199 worker_thread_(kDaemonControllerThreadName) { 160 worker_thread_(kDaemonControllerThreadName) {
161 worker_thread_.init_com_with_mta(false);
200 if (!worker_thread_.Start()) { 162 if (!worker_thread_.Start()) {
201 LOG(FATAL) << "Failed to start the Daemon Controller worker thread."; 163 LOG(FATAL) << "Failed to start the Daemon Controller worker thread.";
202 } 164 }
203 } 165 }
204 166
205 DaemonControllerWin::~DaemonControllerWin() { 167 DaemonControllerWin::~DaemonControllerWin() {
206 // Clean up resources allocated on the worker thread. 168 // Clean up resources allocated on the worker thread.
207 worker_thread_.message_loop_proxy()->PostTask( 169 worker_thread_.message_loop_proxy()->PostTask(
208 FROM_HERE, 170 FROM_HERE,
209 base::Bind(&DaemonControllerWin::ReleaseController, 171 base::Bind(&DaemonControllerWin::ReleaseController,
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 done.Run(true, !!allowed, !!set_by_policy); 665 done.Run(true, !!allowed, !!set_by_policy);
704 } 666 }
705 667
706 } // namespace 668 } // namespace
707 669
708 scoped_ptr<DaemonController> remoting::DaemonController::Create() { 670 scoped_ptr<DaemonController> remoting::DaemonController::Create() {
709 return scoped_ptr<DaemonController>(new DaemonControllerWin()); 671 return scoped_ptr<DaemonController>(new DaemonControllerWin());
710 } 672 }
711 673
712 } // namespace remoting 674 } // namespace remoting
OLDNEW
« no previous file with comments | « media/audio/fake_audio_output_stream.cc ('k') | ui/base/dialogs/base_shell_dialog_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698