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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "remoting/base/auto_thread.h" 11 #include "remoting/base/auto_thread.h"
11 #include "remoting/base/url_request_context_getter.h" 12 #include "remoting/base/url_request_context_getter.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 namespace { 16 namespace {
16 17
17 void DisallowBlockingOperations() { 18 void DisallowBlockingOperations() {
(...skipping 18 matching lines...) Expand all
36 input_task_runner_(input_task_runner), 37 input_task_runner_(input_task_runner),
37 network_task_runner_(network_task_runner), 38 network_task_runner_(network_task_runner),
38 video_capture_task_runner_(video_capture_task_runner), 39 video_capture_task_runner_(video_capture_task_runner),
39 video_encode_task_runner_(video_encode_task_runner), 40 video_encode_task_runner_(video_encode_task_runner),
40 url_request_context_getter_(url_request_context_getter) { 41 url_request_context_getter_(url_request_context_getter) {
41 } 42 }
42 43
43 ChromotingHostContext::~ChromotingHostContext() { 44 ChromotingHostContext::~ChromotingHostContext() {
44 } 45 }
45 46
46 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Copy() { 47 std::unique_ptr<ChromotingHostContext> ChromotingHostContext::Copy() {
47 return make_scoped_ptr(new ChromotingHostContext( 48 return base::WrapUnique(new ChromotingHostContext(
48 ui_task_runner_, audio_task_runner_, file_task_runner_, 49 ui_task_runner_, audio_task_runner_, file_task_runner_,
49 input_task_runner_, network_task_runner_, video_capture_task_runner_, 50 input_task_runner_, network_task_runner_, video_capture_task_runner_,
50 video_encode_task_runner_, url_request_context_getter_)); 51 video_encode_task_runner_, url_request_context_getter_));
51 } 52 }
52 53
53 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::audio_task_runner() 54 scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::audio_task_runner()
54 const { 55 const {
55 return audio_task_runner_; 56 return audio_task_runner_;
56 } 57 }
57 58
(...skipping 25 matching lines...) Expand all
83 scoped_refptr<AutoThreadTaskRunner> 84 scoped_refptr<AutoThreadTaskRunner>
84 ChromotingHostContext::video_encode_task_runner() const { 85 ChromotingHostContext::video_encode_task_runner() const {
85 return video_encode_task_runner_; 86 return video_encode_task_runner_;
86 } 87 }
87 88
88 scoped_refptr<net::URLRequestContextGetter> 89 scoped_refptr<net::URLRequestContextGetter>
89 ChromotingHostContext::url_request_context_getter() const { 90 ChromotingHostContext::url_request_context_getter() const {
90 return url_request_context_getter_; 91 return url_request_context_getter_;
91 } 92 }
92 93
93 scoped_ptr<ChromotingHostContext> ChromotingHostContext::Create( 94 std::unique_ptr<ChromotingHostContext> ChromotingHostContext::Create(
94 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { 95 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) {
95 #if defined(OS_WIN) 96 #if defined(OS_WIN)
96 // On Windows the AudioCapturer requires COM, so we run a single-threaded 97 // On Windows the AudioCapturer requires COM, so we run a single-threaded
97 // apartment, which requires a UI thread. 98 // apartment, which requires a UI thread.
98 scoped_refptr<AutoThreadTaskRunner> audio_task_runner = 99 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
99 AutoThread::CreateWithLoopAndComInitTypes( 100 AutoThread::CreateWithLoopAndComInitTypes(
100 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_UI, 101 "ChromotingAudioThread", ui_task_runner, base::MessageLoop::TYPE_UI,
101 AutoThread::COM_INIT_STA); 102 AutoThread::COM_INIT_STA);
102 #else // !defined(OS_WIN) 103 #else // !defined(OS_WIN)
103 scoped_refptr<AutoThreadTaskRunner> audio_task_runner = 104 scoped_refptr<AutoThreadTaskRunner> audio_task_runner =
104 AutoThread::CreateWithType("ChromotingAudioThread", ui_task_runner, 105 AutoThread::CreateWithType("ChromotingAudioThread", ui_task_runner,
105 base::MessageLoop::TYPE_IO); 106 base::MessageLoop::TYPE_IO);
106 #endif // !defined(OS_WIN) 107 #endif // !defined(OS_WIN)
107 scoped_refptr<AutoThreadTaskRunner> file_task_runner = 108 scoped_refptr<AutoThreadTaskRunner> file_task_runner =
108 AutoThread::CreateWithType("ChromotingFileThread", ui_task_runner, 109 AutoThread::CreateWithType("ChromotingFileThread", ui_task_runner,
109 base::MessageLoop::TYPE_IO); 110 base::MessageLoop::TYPE_IO);
110 111
111 scoped_refptr<AutoThreadTaskRunner> network_task_runner = 112 scoped_refptr<AutoThreadTaskRunner> network_task_runner =
112 AutoThread::CreateWithType("ChromotingNetworkThread", ui_task_runner, 113 AutoThread::CreateWithType("ChromotingNetworkThread", ui_task_runner,
113 base::MessageLoop::TYPE_IO); 114 base::MessageLoop::TYPE_IO);
114 network_task_runner->PostTask(FROM_HERE, 115 network_task_runner->PostTask(FROM_HERE,
115 base::Bind(&DisallowBlockingOperations)); 116 base::Bind(&DisallowBlockingOperations));
116 117
117 return make_scoped_ptr(new ChromotingHostContext( 118 return base::WrapUnique(new ChromotingHostContext(
118 ui_task_runner, 119 ui_task_runner, audio_task_runner, file_task_runner,
119 audio_task_runner,
120 file_task_runner,
121 AutoThread::CreateWithType("ChromotingInputThread", ui_task_runner, 120 AutoThread::CreateWithType("ChromotingInputThread", ui_task_runner,
122 base::MessageLoop::TYPE_IO), 121 base::MessageLoop::TYPE_IO),
123 network_task_runner, 122 network_task_runner,
124 AutoThread::Create("ChromotingCaptureThread", ui_task_runner), 123 AutoThread::Create("ChromotingCaptureThread", ui_task_runner),
125 AutoThread::Create("ChromotingEncodeThread", ui_task_runner), 124 AutoThread::Create("ChromotingEncodeThread", ui_task_runner),
126 make_scoped_refptr( 125 make_scoped_refptr(
127 new URLRequestContextGetter(network_task_runner, file_task_runner)))); 126 new URLRequestContextGetter(network_task_runner, file_task_runner))));
128 } 127 }
129 128
130 #if defined(OS_CHROMEOS) 129 #if defined(OS_CHROMEOS)
131 130
132 // static 131 // static
133 scoped_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS( 132 std::unique_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
134 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 133 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
135 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 134 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
136 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 135 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
137 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { 136 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
138 DCHECK(url_request_context_getter.get()); 137 DCHECK(url_request_context_getter.get());
139 138
140 139
141 // AutoThreadTaskRunner is a TaskRunner with the special property that it will 140 // AutoThreadTaskRunner is a TaskRunner with the special property that it will
142 // continue to process tasks until no references remain, at least. The 141 // continue to process tasks until no references remain, at least. The
143 // QuitClosure we usually pass does the simple thing of stopping the 142 // QuitClosure we usually pass does the simple thing of stopping the
144 // underlying TaskRunner. Since we are re-using browser's threads, we cannot 143 // underlying TaskRunner. Since we are re-using browser's threads, we cannot
145 // stop them explicitly. Therefore, base::DoNothing is passed in as the quit 144 // stop them explicitly. Therefore, base::DoNothing is passed in as the quit
146 // closure. 145 // closure.
147 scoped_refptr<AutoThreadTaskRunner> io_auto_task_runner = 146 scoped_refptr<AutoThreadTaskRunner> io_auto_task_runner =
148 new AutoThreadTaskRunner(io_task_runner, base::Bind(&base::DoNothing)); 147 new AutoThreadTaskRunner(io_task_runner, base::Bind(&base::DoNothing));
149 scoped_refptr<AutoThreadTaskRunner> file_auto_task_runner = 148 scoped_refptr<AutoThreadTaskRunner> file_auto_task_runner =
150 new AutoThreadTaskRunner(file_task_runner, base::Bind(&base::DoNothing)); 149 new AutoThreadTaskRunner(file_task_runner, base::Bind(&base::DoNothing));
151 scoped_refptr<AutoThreadTaskRunner> ui_auto_task_runner = 150 scoped_refptr<AutoThreadTaskRunner> ui_auto_task_runner =
152 new AutoThreadTaskRunner(ui_task_runner, base::Bind(&base::DoNothing)); 151 new AutoThreadTaskRunner(ui_task_runner, base::Bind(&base::DoNothing));
153 152
154 // Use browser's file thread as the joiner as it is the only browser-thread 153 // Use browser's file thread as the joiner as it is the only browser-thread
155 // that allows blocking I/O, which is required by thread joining. 154 // that allows blocking I/O, which is required by thread joining.
156 return make_scoped_ptr(new ChromotingHostContext( 155 return base::WrapUnique(new ChromotingHostContext(
157 ui_auto_task_runner, 156 ui_auto_task_runner,
158 AutoThread::Create("ChromotingAudioThread", file_auto_task_runner), 157 AutoThread::Create("ChromotingAudioThread", file_auto_task_runner),
159 file_auto_task_runner, 158 file_auto_task_runner,
160 ui_auto_task_runner, // input_task_runner 159 ui_auto_task_runner, // input_task_runner
161 io_auto_task_runner, // network_task_runner 160 io_auto_task_runner, // network_task_runner
162 ui_auto_task_runner, // video_capture_task_runner 161 ui_auto_task_runner, // video_capture_task_runner
163 AutoThread::Create("ChromotingEncodeThread", file_auto_task_runner), 162 AutoThread::Create("ChromotingEncodeThread", file_auto_task_runner),
164 url_request_context_getter)); 163 url_request_context_getter));
165 } 164 }
166 #endif // defined(OS_CHROMEOS) 165 #endif // defined(OS_CHROMEOS)
167 166
168 } // namespace remoting 167 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host_context.h ('k') | remoting/host/chromoting_host_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698