OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/chromoting_host_context.h" |
| 6 |
| 7 #include "chrome/browser/browser_process.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "net/url_request/url_request_context_getter.h" |
| 10 #include "remoting/base/auto_thread.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 namespace { |
| 15 // Retrieves the task_runner from the browser thread with |id|. |
| 16 AutoThreadTaskRunner* GetTaskRunner(content::BrowserThread::ID id) { |
| 17 return new AutoThreadTaskRunner( |
| 18 content::BrowserThread::GetMessageLoopProxyForThread(id).get(), |
| 19 base::Bind(&base::DoNothing)); |
| 20 } |
| 21 |
| 22 class ChromotingHostContextImpl : public ChromotingHostContext { |
| 23 public: |
| 24 ChromotingHostContextImpl(AutoThreadTaskRunner* ui_task_runner); |
| 25 |
| 26 private: |
| 27 virtual ~ChromotingHostContextImpl() override; |
| 28 }; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 // static |
| 33 scoped_refptr<ChromotingHostContext> ChromotingHostContext::Create( |
| 34 scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { |
| 35 return new ChromotingHostContextImpl(ui_task_runner.get()); |
| 36 } |
| 37 |
| 38 ChromotingHostContextImpl::ChromotingHostContextImpl( |
| 39 AutoThreadTaskRunner* ui_task_runner) |
| 40 : ChromotingHostContext(ui_task_runner) { |
| 41 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 42 |
| 43 // Thread assignments and re-using existing browser sources |
| 44 // (URLRequestContextGetter) must be performed on the UI thread of the |
| 45 // browser process. |
| 46 file_task_runner_ = GetTaskRunner(content::BrowserThread::FILE); |
| 47 network_task_runner_ = GetTaskRunner(content::BrowserThread::IO); |
| 48 video_capture_task_runner_ = GetTaskRunner(content::BrowserThread::UI); |
| 49 |
| 50 // Each instance of BasicURLRequestContext spawns two extra threads. |
| 51 // Reuse the url_request_context_getter of the I/O Thread to avoid creating |
| 52 // extra threads on the UI thread. |
| 53 url_request_context_getter_ = g_browser_process->system_request_context(); |
| 54 |
| 55 // Thread joining is blocking and it can only be done on threads that allows |
| 56 // blocking I/O. Uses the |file_task_runner| as the joiner. |
| 57 input_task_runner_ = AutoThread::CreateWithType( |
| 58 "ChromotingInputThread", file_task_runner_, base::MessageLoop::TYPE_IO); |
| 59 audio_task_runner_ = AutoThread::CreateWithType( |
| 60 "ChromotingAudioThread", file_task_runner_, base::MessageLoop::TYPE_IO); |
| 61 video_encode_task_runner_ = |
| 62 AutoThread::Create("ChromotingEncodeThread", file_task_runner_); |
| 63 |
| 64 } |
| 65 |
| 66 ChromotingHostContextImpl::~ChromotingHostContextImpl() { |
| 67 } |
| 68 |
| 69 } // namespace remoting |
OLD | NEW |