| 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/supports_user_data.h" | |
| 11 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
| 12 #include "blimp/client/core/contents/blimp_contents_impl.h" | 11 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 12 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 14 #include "blimp/client/public/blimp_client_context_delegate.h" | 13 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 15 | 14 |
| 16 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
| 17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" | 16 #include "blimp/client/core/android/blimp_client_context_impl_android.h" |
| 18 #endif // OS_ANDROID | 17 #endif // OS_ANDROID |
| 19 | 18 |
| 20 namespace blimp { | 19 namespace blimp { |
| 21 namespace client { | 20 namespace client { |
| 22 | 21 |
| 23 namespace { | |
| 24 | |
| 25 #if defined(OS_ANDROID) | |
| 26 const char kBlimpClientContextImplAndroidKey[] = | |
| 27 "blimp_client_context_impl_android"; | |
| 28 #endif // OS_ANDROID | |
| 29 } | |
| 30 | |
| 31 // This function is declared in //blimp/client/public/blimp_client_context.h, | 22 // This function is declared in //blimp/client/public/blimp_client_context.h, |
| 32 // and either this function or the one in | 23 // and either this function or the one in |
| 33 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 24 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 34 // any binary using BlimpClientContext::Create. | 25 // any binary using BlimpClientContext::Create. |
| 35 // static | 26 // static |
| 36 BlimpClientContext* BlimpClientContext::Create( | 27 BlimpClientContext* BlimpClientContext::Create( |
| 37 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { | 28 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { |
| 29 #if defined(OS_ANDROID) |
| 30 return new BlimpClientContextImplAndroid(io_thread_task_runner); |
| 31 #else |
| 38 return new BlimpClientContextImpl(io_thread_task_runner); | 32 return new BlimpClientContextImpl(io_thread_task_runner); |
| 33 #endif // defined(OS_ANDROID) |
| 39 } | 34 } |
| 40 | 35 |
| 41 BlimpClientContextImpl::BlimpClientContextImpl( | 36 BlimpClientContextImpl::BlimpClientContextImpl( |
| 42 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) | 37 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) |
| 43 : BlimpClientContext(), | 38 : BlimpClientContext(), |
| 44 io_thread_task_runner_(io_thread_task_runner), | 39 io_thread_task_runner_(io_thread_task_runner), |
| 45 weak_factory_(this) { | 40 weak_factory_(this) { |
| 46 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | 41 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 47 net_components_.reset(new ClientNetworkComponents( | 42 net_components_.reset(new ClientNetworkComponents( |
| 48 base::MakeUnique<CrossThreadNetworkEventObserver>( | 43 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 49 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), | 44 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), |
| 50 base::WrapUnique(blimp_connection_statistics_))); | 45 base::WrapUnique(blimp_connection_statistics_))); |
| 51 | 46 |
| 52 // The |thread_pipe_manager_| must be set up correctly before features are | 47 // The |thread_pipe_manager_| must be set up correctly before features are |
| 53 // registered. | 48 // registered. |
| 54 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 49 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 55 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 50 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 56 | 51 |
| 57 // Initialize must only be posted after the calls features have been | 52 // Initialize must only be posted after the calls features have been |
| 58 // registered. | 53 // registered. |
| 59 io_thread_task_runner_->PostTask( | 54 io_thread_task_runner_->PostTask( |
| 60 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 55 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 61 base::Unretained(net_components_.get()))); | 56 base::Unretained(net_components_.get()))); |
| 62 } | 57 } |
| 63 | 58 |
| 64 BlimpClientContextImpl::~BlimpClientContextImpl() { | 59 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 65 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 60 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
| 66 } | 61 } |
| 67 | 62 |
| 68 #if defined(OS_ANDROID) | |
| 69 | |
| 70 base::android::ScopedJavaLocalRef<jobject> | |
| 71 BlimpClientContextImpl::GetJavaObject() { | |
| 72 return GetBlimpClientContextImplAndroid()->GetJavaObject(); | |
| 73 } | |
| 74 | |
| 75 BlimpClientContextImplAndroid* | |
| 76 BlimpClientContextImpl::GetBlimpClientContextImplAndroid() { | |
| 77 BlimpClientContextImplAndroid* blimp_client_contents_impl_android = | |
| 78 static_cast<BlimpClientContextImplAndroid*>( | |
| 79 GetUserData(kBlimpClientContextImplAndroidKey)); | |
| 80 if (!blimp_client_contents_impl_android) { | |
| 81 blimp_client_contents_impl_android = | |
| 82 new BlimpClientContextImplAndroid(this); | |
| 83 SetUserData(kBlimpClientContextImplAndroidKey, | |
| 84 blimp_client_contents_impl_android); | |
| 85 } | |
| 86 return blimp_client_contents_impl_android; | |
| 87 } | |
| 88 | |
| 89 #endif // defined(OS_ANDROID) | |
| 90 | |
| 91 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { | 63 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { |
| 92 delegate_ = delegate; | 64 delegate_ = delegate; |
| 93 } | 65 } |
| 94 | 66 |
| 95 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 67 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
| 96 std::unique_ptr<BlimpContents> blimp_contents = | 68 std::unique_ptr<BlimpContents> blimp_contents = |
| 97 base::MakeUnique<BlimpContentsImpl>(); | 69 base::MakeUnique<BlimpContentsImpl>(); |
| 98 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 70 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 99 return blimp_contents; | 71 return blimp_contents; |
| 100 } | 72 } |
| 101 | 73 |
| 102 void BlimpClientContextImpl::OnConnected() {} | 74 void BlimpClientContextImpl::OnConnected() {} |
| 103 | 75 |
| 104 void BlimpClientContextImpl::OnDisconnected(int result) {} | 76 void BlimpClientContextImpl::OnDisconnected(int result) {} |
| 105 | 77 |
| 106 } // namespace client | 78 } // namespace client |
| 107 } // namespace blimp | 79 } // namespace blimp |
| OLD | NEW |