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

Side by Side Diff: remoting/host/chromoting_host_context.cc

Issue 10829467: [Chromoting] Introducing refcount-based life time management of the message loops in the service (d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Destructors of ref-counted objects should not be public. Created 8 years, 4 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
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/chromoting_host_context.h" 5 #include "remoting/host/chromoting_host_context.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "remoting/base//auto_thread.h"
11 #include "remoting/host/url_request_context.h" 12 #include "remoting/host/url_request_context.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 ChromotingHostContext::ChromotingHostContext( 16 ChromotingHostContext::ChromotingHostContext(
16 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) 17 base::SingleThreadTaskRunner* ui_task_runner)
17 : network_thread_("ChromotingNetworkThread"), 18 : ui_task_runner_(ui_task_runner) {
18 capture_thread_("ChromotingCaptureThread"),
19 encode_thread_("ChromotingEncodeThread"),
20 desktop_thread_("ChromotingDesktopThread"),
21 file_thread_("ChromotingFileIOThread"),
22 ui_task_runner_(ui_task_runner) {
23 } 19 }
24 20
25 ChromotingHostContext::~ChromotingHostContext() { 21 ChromotingHostContext::~ChromotingHostContext() {
26 } 22 }
27 23
28 bool ChromotingHostContext::Start() { 24 bool ChromotingHostContext::Start() {
25 network_thread_ = new AutoThread("ChromotingNetworkThread", ui_task_runner_);
26 capture_thread_ = new AutoThread("ChromotingCaptureThread", ui_task_runner_);
27 encode_thread_ = new AutoThread("ChromotingEncodeThread", ui_task_runner_);
28 desktop_thread_ = new AutoThread("ChromotingDesktopThread", ui_task_runner_);
29 file_thread_ = new AutoThread("ChromotingFileIOThread", ui_task_runner_);
30
29 // Start all the threads. 31 // Start all the threads.
30 bool started = capture_thread_.Start() && encode_thread_.Start() && 32 bool started = capture_thread_->Start() && encode_thread_->Start() &&
31 network_thread_.StartWithOptions(base::Thread::Options( 33 network_thread_->StartWithOptions(base::Thread::Options(
32 MessageLoop::TYPE_IO, 0)) && 34 MessageLoop::TYPE_IO, 0)) &&
33 desktop_thread_.Start() && 35 desktop_thread_->Start() &&
34 file_thread_.StartWithOptions( 36 file_thread_->StartWithOptions(
35 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 37 base::Thread::Options(MessageLoop::TYPE_IO, 0));
36 if (!started) 38 if (!started)
37 return false; 39 return false;
38 40
39 url_request_context_getter_ = new URLRequestContextGetter( 41 url_request_context_getter_ = new URLRequestContextGetter(
40 ui_task_runner(), network_task_runner(), 42 ui_task_runner(), network_task_runner(),
41 static_cast<MessageLoopForIO*>(file_thread_.message_loop())); 43 static_cast<MessageLoopForIO*>(file_thread_->message_loop()));
42 return true; 44 return true;
43 } 45 }
44 46
45 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() { 47 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() {
46 return capture_thread_.message_loop_proxy(); 48 return capture_thread_;
47 } 49 }
48 50
49 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() { 51 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
50 return encode_thread_.message_loop_proxy(); 52 return encode_thread_;
51 } 53 }
52 54
53 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() { 55 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
54 return network_thread_.message_loop_proxy(); 56 return network_thread_;
55 } 57 }
56 58
57 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() { 59 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
58 return desktop_thread_.message_loop_proxy(); 60 return desktop_thread_;
59 } 61 }
60 62
61 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() { 63 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
62 return ui_task_runner_; 64 return ui_task_runner_;
63 } 65 }
64 66
65 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() { 67 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
66 return file_thread_.message_loop_proxy(); 68 return file_thread_;
67 } 69 }
68 70
69 const scoped_refptr<net::URLRequestContextGetter>& 71 const scoped_refptr<net::URLRequestContextGetter>&
70 ChromotingHostContext::url_request_context_getter() { 72 ChromotingHostContext::url_request_context_getter() {
71 DCHECK(url_request_context_getter_.get()); 73 DCHECK(url_request_context_getter_.get());
72 return url_request_context_getter_; 74 return url_request_context_getter_;
73 } 75 }
74 76
75 } // namespace remoting 77 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698