| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/client/core/blimp_client_context_impl.h" | 5 #include "blimp/client/core/blimp_client_context_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
| 11 #include "blimp/client/core/contents/blimp_contents_impl.h" | 11 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 12 #include "blimp/client/core/contents/blimp_contents_manager.h" | 12 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 13 #include "blimp/client/core/contents/tab_control_feature.h" |
| 13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 14 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 14 #include "blimp/client/public/blimp_client_context_delegate.h" | 15 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 15 | 16 |
| 16 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
| 17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" | 18 #include "blimp/client/core/android/blimp_client_context_impl_android.h" |
| 18 #endif // OS_ANDROID | 19 #endif // OS_ANDROID |
| 19 | 20 |
| 20 namespace blimp { | 21 namespace blimp { |
| 21 namespace client { | 22 namespace client { |
| 22 | 23 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 file_thread_task_runner); | 42 file_thread_task_runner); |
| 42 #endif // defined(OS_ANDROID) | 43 #endif // defined(OS_ANDROID) |
| 43 } | 44 } |
| 44 | 45 |
| 45 BlimpClientContextImpl::BlimpClientContextImpl( | 46 BlimpClientContextImpl::BlimpClientContextImpl( |
| 46 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 47 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 47 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) | 48 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) |
| 48 : BlimpClientContext(), | 49 : BlimpClientContext(), |
| 49 io_thread_task_runner_(io_thread_task_runner), | 50 io_thread_task_runner_(io_thread_task_runner), |
| 50 file_thread_task_runner_(file_thread_task_runner), | 51 file_thread_task_runner_(file_thread_task_runner), |
| 51 blimp_contents_manager_(new BlimpContentsManager), | 52 tab_control_feature_(new TabControlFeature), |
| 53 blimp_contents_manager_(new BlimpContentsManager( |
| 54 tab_control_feature_.get())), |
| 52 weak_factory_(this) { | 55 weak_factory_(this) { |
| 53 net_components_.reset(new ClientNetworkComponents( | 56 net_components_.reset(new ClientNetworkComponents( |
| 54 base::MakeUnique<CrossThreadNetworkEventObserver>( | 57 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 55 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); | 58 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); |
| 56 | 59 |
| 57 // The |thread_pipe_manager_| must be set up correctly before features are | 60 // The |thread_pipe_manager_| must be set up correctly before features are |
| 58 // registered. | 61 // registered. |
| 59 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 62 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 60 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 63 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 61 | 64 |
| 65 RegisterFeatures(); |
| 66 |
| 62 // Initialize must only be posted after the calls features have been | 67 // Initialize must only be posted after the calls features have been |
| 63 // registered. | 68 // registered. |
| 64 io_thread_task_runner_->PostTask( | 69 io_thread_task_runner_->PostTask( |
| 65 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 70 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 66 base::Unretained(net_components_.get()))); | 71 base::Unretained(net_components_.get()))); |
| 67 } | 72 } |
| 68 | 73 |
| 69 BlimpClientContextImpl::~BlimpClientContextImpl() { | 74 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 70 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 75 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
| 71 } | 76 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 assignment_source_->GetAssignment( | 96 assignment_source_->GetAssignment( |
| 92 client_auth_token, | 97 client_auth_token, |
| 93 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, | 98 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, |
| 94 weak_factory_.GetWeakPtr())); | 99 weak_factory_.GetWeakPtr())); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void BlimpClientContextImpl::OnConnected() {} | 102 void BlimpClientContextImpl::OnConnected() {} |
| 98 | 103 |
| 99 void BlimpClientContextImpl::OnDisconnected(int result) {} | 104 void BlimpClientContextImpl::OnDisconnected(int result) {} |
| 100 | 105 |
| 106 TabControlFeature* BlimpClientContextImpl::GetTabControlFeature() const { |
| 107 return tab_control_feature_.get(); |
| 108 } |
| 109 |
| 101 GURL BlimpClientContextImpl::GetAssignerURL() { | 110 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 102 return GURL(kDefaultAssignerUrl); | 111 return GURL(kDefaultAssignerUrl); |
| 103 } | 112 } |
| 104 | 113 |
| 105 void BlimpClientContextImpl::ConnectWithAssignment( | 114 void BlimpClientContextImpl::ConnectWithAssignment( |
| 106 AssignmentRequestResult result, | 115 AssignmentRequestResult result, |
| 107 const Assignment& assignment) { | 116 const Assignment& assignment) { |
| 108 VLOG(1) << "Assignment result: " << result; | 117 VLOG(1) << "Assignment result: " << result; |
| 109 | 118 |
| 110 if (delegate_) { | 119 if (delegate_) { |
| 111 delegate_->OnAssignmentConnectionAttempted(result, assignment); | 120 delegate_->OnAssignmentConnectionAttempted(result, assignment); |
| 112 } | 121 } |
| 113 | 122 |
| 114 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { | 123 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { |
| 115 LOG(ERROR) << "Assignment failed, reason: " << result; | 124 LOG(ERROR) << "Assignment failed, reason: " << result; |
| 116 return; | 125 return; |
| 117 } | 126 } |
| 118 | 127 |
| 119 io_thread_task_runner_->PostTask( | 128 io_thread_task_runner_->PostTask( |
| 120 FROM_HERE, | 129 FROM_HERE, |
| 121 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 130 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 122 base::Unretained(net_components_.get()), assignment)); | 131 base::Unretained(net_components_.get()), assignment)); |
| 123 } | 132 } |
| 124 | 133 |
| 134 void BlimpClientContextImpl::RegisterFeatures() { |
| 135 // Register features' message senders and receivers. |
| 136 tab_control_feature_->set_outgoing_message_processor( |
| 137 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, |
| 138 tab_control_feature_.get())); |
| 139 } |
| 140 |
| 125 } // namespace client | 141 } // namespace client |
| 126 } // namespace blimp | 142 } // namespace blimp |
| OLD | NEW |