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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" |
8 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
| 11 #include "base/threading/sequenced_task_runner_handle.h" |
9 #include "blimp/client/core/contents/blimp_contents_impl.h" | 12 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 13 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
10 #include "blimp/client/public/blimp_client_context_delegate.h" | 14 #include "blimp/client/public/blimp_client_context_delegate.h" |
11 | 15 |
12 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
13 #include "blimp/client/core/android/blimp_client_context_impl_android.h" | 17 #include "blimp/client/core/android/blimp_client_context_impl_android.h" |
14 #endif // OS_ANDROID | 18 #endif // OS_ANDROID |
15 | 19 |
16 namespace blimp { | 20 namespace blimp { |
17 namespace client { | 21 namespace client { |
18 | 22 |
19 namespace { | 23 namespace { |
20 | 24 |
21 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
22 const char kBlimpClientContextImplAndroidKey[] = | 26 const char kBlimpClientContextImplAndroidKey[] = |
23 "blimp_client_context_impl_android"; | 27 "blimp_client_context_impl_android"; |
24 #endif // OS_ANDROID | 28 #endif // OS_ANDROID |
25 } | 29 } |
26 | 30 |
27 // This function is declared in //blimp/client/public/blimp_client_context.h, | 31 // This function is declared in //blimp/client/public/blimp_client_context.h, |
28 // and either this function or the one in | 32 // and either this function or the one in |
29 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 33 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
30 // any binary using BlimpClientContext::Create. | 34 // any binary using BlimpClientContext::Create. |
31 // static | 35 // static |
32 BlimpClientContext* BlimpClientContext::Create() { | 36 BlimpClientContext* BlimpClientContext::Create() { |
33 return new BlimpClientContextImpl(); | 37 return new BlimpClientContextImpl(); |
34 } | 38 } |
35 | 39 |
36 BlimpClientContextImpl::BlimpClientContextImpl() : BlimpClientContext() {} | 40 BlimpClientContextImpl::BlimpClientContextImpl() |
| 41 : BlimpClientContext(), io_thread_("BlimpIOThread"), weak_factory_(this) { |
| 42 base::Thread::Options options; |
| 43 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 44 io_thread_.StartWithOptions(options); |
| 45 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 46 net_components_.reset(new ClientNetworkComponents( |
| 47 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 48 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), |
| 49 base::WrapUnique(blimp_connection_statistics_))); |
37 | 50 |
38 BlimpClientContextImpl::~BlimpClientContextImpl() {} | 51 RegisterFeatures(); |
| 52 |
| 53 // Initialize must only be posted after the RegisterFeature calls have |
| 54 // completed. |
| 55 io_thread_.task_runner()->PostTask( |
| 56 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 57 base::Unretained(net_components_.get()))); |
| 58 } |
| 59 |
| 60 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 61 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
| 62 } |
| 63 |
| 64 void BlimpClientContextImpl::RegisterFeatures() { |
| 65 thread_pipe_manager_ = base::WrapUnique( |
| 66 new ThreadPipeManager(io_thread_.task_runner(), |
| 67 net_components_->GetBrowserConnectionHandler())); |
| 68 } |
39 | 69 |
40 #if defined(OS_ANDROID) | 70 #if defined(OS_ANDROID) |
41 | 71 |
42 base::android::ScopedJavaLocalRef<jobject> | 72 base::android::ScopedJavaLocalRef<jobject> |
43 BlimpClientContextImpl::GetJavaObject() { | 73 BlimpClientContextImpl::GetJavaObject() { |
44 return GetBlimpClientContextImplAndroid()->GetJavaObject(); | 74 return GetBlimpClientContextImplAndroid()->GetJavaObject(); |
45 } | 75 } |
46 | 76 |
47 BlimpClientContextImplAndroid* | 77 BlimpClientContextImplAndroid* |
48 BlimpClientContextImpl::GetBlimpClientContextImplAndroid() { | 78 BlimpClientContextImpl::GetBlimpClientContextImplAndroid() { |
(...skipping 15 matching lines...) Expand all Loading... |
64 delegate_ = delegate; | 94 delegate_ = delegate; |
65 } | 95 } |
66 | 96 |
67 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 97 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
68 std::unique_ptr<BlimpContents> blimp_contents = | 98 std::unique_ptr<BlimpContents> blimp_contents = |
69 base::WrapUnique(new BlimpContentsImpl); | 99 base::WrapUnique(new BlimpContentsImpl); |
70 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 100 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
71 return blimp_contents; | 101 return blimp_contents; |
72 } | 102 } |
73 | 103 |
| 104 void BlimpClientContextImpl::OnConnected() {} |
| 105 |
| 106 void BlimpClientContextImpl::OnDisconnected(int result) {} |
| 107 |
74 } // namespace client | 108 } // namespace client |
75 } // namespace blimp | 109 } // namespace blimp |
OLD | NEW |