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

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: CR feedback. Created 8 years, 3 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_task_runner.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 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
17 : network_thread_("ChromotingNetworkThread"), 18 : network_thread_("ChromotingNetworkThread"),
18 capture_thread_("ChromotingCaptureThread"), 19 capture_thread_("ChromotingCaptureThread"),
19 encode_thread_("ChromotingEncodeThread"), 20 encode_thread_("ChromotingEncodeThread"),
20 desktop_thread_("ChromotingDesktopThread"), 21 desktop_thread_("ChromotingDesktopThread"),
21 file_thread_("ChromotingFileIOThread"), 22 file_thread_("ChromotingFileIOThread"),
22 ui_task_runner_(ui_task_runner) { 23 ui_task_runner_(ui_task_runner) {
23 } 24 }
24 25
25 ChromotingHostContext::~ChromotingHostContext() { 26 ChromotingHostContext::~ChromotingHostContext() {
26 } 27 }
27 28
28 bool ChromotingHostContext::Start() { 29 bool ChromotingHostContext::Start() {
29 // Start all the threads. 30 // Start all the threads.
30 bool started = capture_thread_.Start() && encode_thread_.Start() && 31 bool started = capture_thread_.Start() && encode_thread_.Start() &&
31 network_thread_.StartWithOptions(base::Thread::Options( 32 network_thread_.StartWithOptions(base::Thread::Options(
32 MessageLoop::TYPE_IO, 0)) && 33 MessageLoop::TYPE_IO, 0)) &&
33 desktop_thread_.Start() && 34 desktop_thread_.Start() &&
34 file_thread_.StartWithOptions( 35 file_thread_.StartWithOptions(
35 base::Thread::Options(MessageLoop::TYPE_IO, 0)); 36 base::Thread::Options(MessageLoop::TYPE_IO, 0));
36 if (!started) 37 if (!started)
37 return false; 38 return false;
38 39
40 // Wrap worker threads to |AutoThreadTaskRunner| two keep the main thread
Wez 2012/08/30 23:56:43 nit: "Wrap worker threads with |AutoThreadTaskRunn
alexeypa (please no reviews) 2012/08/31 19:57:36 Done. I removed the last sentence because it is no
41 // alive until there are references to them.
42 network_task_runner_ =
43 new AutoThreadTaskRunner(network_thread_.message_loop_proxy(),
44 ui_task_runner_);
45 capture_task_runner_ =
46 new AutoThreadTaskRunner(capture_thread_.message_loop_proxy(),
47 ui_task_runner_);
48 encode_task_runner_ =
49 new AutoThreadTaskRunner(encode_thread_.message_loop_proxy(),
50 ui_task_runner_);
51 desktop_task_runner_ =
52 new AutoThreadTaskRunner(desktop_thread_.message_loop_proxy(),
53 ui_task_runner_);
54 file_task_runner_ =
55 new AutoThreadTaskRunner(file_thread_.message_loop_proxy(),
56 ui_task_runner_);
57
39 url_request_context_getter_ = new URLRequestContextGetter( 58 url_request_context_getter_ = new URLRequestContextGetter(
40 ui_task_runner(), network_task_runner(), 59 ui_task_runner(), network_task_runner(),
41 static_cast<MessageLoopForIO*>(file_thread_.message_loop())); 60 static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
42 return true; 61 return true;
43 } 62 }
44 63
64 void ChromotingHostContext::Stop() {
65 url_request_context_getter_ = NULL;
66 network_task_runner_ = NULL;
67 capture_task_runner_ = NULL;
68 encode_task_runner_ = NULL;
69 desktop_task_runner_ = NULL;
70 file_task_runner_ = NULL;
71 ui_task_runner_ = NULL;
72 }
73
45 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() { 74 base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() {
46 return capture_thread_.message_loop_proxy(); 75 return capture_task_runner_;
47 } 76 }
48 77
49 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() { 78 base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
50 return encode_thread_.message_loop_proxy(); 79 return encode_task_runner_;
51 } 80 }
52 81
53 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() { 82 base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
54 return network_thread_.message_loop_proxy(); 83 return network_task_runner_;
55 } 84 }
56 85
57 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() { 86 base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
58 return desktop_thread_.message_loop_proxy(); 87 return desktop_task_runner_;
59 } 88 }
60 89
61 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() { 90 base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
62 return ui_task_runner_; 91 return ui_task_runner_;
63 } 92 }
64 93
65 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() { 94 base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
66 return file_thread_.message_loop_proxy(); 95 return file_task_runner_;
67 } 96 }
68 97
69 const scoped_refptr<net::URLRequestContextGetter>& 98 const scoped_refptr<net::URLRequestContextGetter>&
70 ChromotingHostContext::url_request_context_getter() { 99 ChromotingHostContext::url_request_context_getter() {
71 DCHECK(url_request_context_getter_.get()); 100 DCHECK(url_request_context_getter_.get());
72 return url_request_context_getter_; 101 return url_request_context_getter_;
73 } 102 }
74 103
75 } // namespace remoting 104 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698