| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/net/blimp_message_thread_pipe.h" | 5 #include "blimp/net/blimp_message_thread_pipe.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/threading/sequenced_task_runner_handle.h" | 12 #include "base/threading/task_runner_handle.h" |
| 13 #include "blimp/common/proto/blimp_message.pb.h" | 13 #include "blimp/common/proto/blimp_message.pb.h" |
| 14 #include "blimp/net/blimp_message_processor.h" | 14 #include "blimp/net/blimp_message_processor.h" |
| 15 | 15 |
| 16 namespace blimp { | 16 namespace blimp { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class BlimpMessageThreadProxy : public BlimpMessageProcessor { | 20 class BlimpMessageThreadProxy : public BlimpMessageProcessor { |
| 21 public: | 21 public: |
| 22 BlimpMessageThreadProxy( | 22 BlimpMessageThreadProxy( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 void BlimpMessageThreadProxy::ProcessMessage( | 77 void BlimpMessageThreadProxy::ProcessMessage( |
| 78 std::unique_ptr<BlimpMessage> message, | 78 std::unique_ptr<BlimpMessage> message, |
| 79 const net::CompletionCallback& callback) { | 79 const net::CompletionCallback& callback) { |
| 80 // If |callback| is non-null then wrap it to be called on this thread, iff | 80 // If |callback| is non-null then wrap it to be called on this thread, iff |
| 81 // this proxy instance is still alive at the time. | 81 // this proxy instance is still alive at the time. |
| 82 net::CompletionCallback wrapped_callback; | 82 net::CompletionCallback wrapped_callback; |
| 83 if (!callback.is_null()) { | 83 if (!callback.is_null()) { |
| 84 wrapped_callback = base::Bind(&DispatchProcessMessageCallback, | 84 wrapped_callback = base::Bind(&DispatchProcessMessageCallback, |
| 85 base::SequencedTaskRunnerHandle::Get(), | 85 base::TaskRunnerHandle::GetSequenced(), |
| 86 weak_factory_.GetWeakPtr(), callback); | 86 weak_factory_.GetWeakPtr(), callback); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Post |message| to be processed via |pipe_| on |task_runner_|. | 89 // Post |message| to be processed via |pipe_| on |task_runner_|. |
| 90 task_runner_->PostTask(FROM_HERE, | 90 task_runner_->PostTask(FROM_HERE, |
| 91 base::Bind(&DispatchProcessMessage, pipe_, | 91 base::Bind(&DispatchProcessMessage, pipe_, |
| 92 base::Passed(&message), wrapped_callback)); | 92 base::Passed(&message), wrapped_callback)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| (...skipping 16 matching lines...) Expand all Loading... |
| 112 DCHECK(target_task_runner_->RunsTasksOnCurrentThread()); | 112 DCHECK(target_task_runner_->RunsTasksOnCurrentThread()); |
| 113 target_processor_ = processor; | 113 target_processor_ = processor; |
| 114 } | 114 } |
| 115 | 115 |
| 116 BlimpMessageProcessor* BlimpMessageThreadPipe::target_processor() const { | 116 BlimpMessageProcessor* BlimpMessageThreadPipe::target_processor() const { |
| 117 DCHECK(target_task_runner_->RunsTasksOnCurrentThread()); | 117 DCHECK(target_task_runner_->RunsTasksOnCurrentThread()); |
| 118 return target_processor_; | 118 return target_processor_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace blimp | 121 } // namespace blimp |
| OLD | NEW |