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 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { |
38 return new BlimpClientContextImpl(io_thread_task_runner); | |
34 } | 39 } |
35 | 40 |
36 BlimpClientContextImpl::BlimpClientContextImpl() : BlimpClientContext() {} | 41 BlimpClientContextImpl::BlimpClientContextImpl( |
42 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) | |
43 : BlimpClientContext(), | |
44 io_thread_task_runner_(io_thread_task_runner), | |
45 weak_factory_(this) { | |
46 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | |
47 net_components_.reset(new ClientNetworkComponents( | |
48 base::MakeUnique<CrossThreadNetworkEventObserver>( | |
49 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()), | |
50 base::WrapUnique(blimp_connection_statistics_))); | |
37 | 51 |
38 BlimpClientContextImpl::~BlimpClientContextImpl() {} | 52 // The |thread_pipe_manager_| must be set up correctly before features are |
53 // registered. | |
54 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | |
55 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | |
56 | |
57 // Initialize must only be posted after the RegisterFeature calls have | |
Kevin M
2016/08/02 19:55:40
RegisterFeature() isn't a thing anymore?
nyquist
2016/08/02 21:47:04
Done.
| |
58 // completed. | |
59 io_thread_task_runner_->PostTask( | |
60 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | |
61 base::Unretained(net_components_.get()))); | |
62 } | |
63 | |
64 BlimpClientContextImpl::~BlimpClientContextImpl() { | |
65 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | |
66 } | |
39 | 67 |
40 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
41 | 69 |
42 base::android::ScopedJavaLocalRef<jobject> | 70 base::android::ScopedJavaLocalRef<jobject> |
43 BlimpClientContextImpl::GetJavaObject() { | 71 BlimpClientContextImpl::GetJavaObject() { |
44 return GetBlimpClientContextImplAndroid()->GetJavaObject(); | 72 return GetBlimpClientContextImplAndroid()->GetJavaObject(); |
45 } | 73 } |
46 | 74 |
47 BlimpClientContextImplAndroid* | 75 BlimpClientContextImplAndroid* |
48 BlimpClientContextImpl::GetBlimpClientContextImplAndroid() { | 76 BlimpClientContextImpl::GetBlimpClientContextImplAndroid() { |
(...skipping 10 matching lines...) Expand all Loading... | |
59 } | 87 } |
60 | 88 |
61 #endif // defined(OS_ANDROID) | 89 #endif // defined(OS_ANDROID) |
62 | 90 |
63 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { | 91 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { |
64 delegate_ = delegate; | 92 delegate_ = delegate; |
65 } | 93 } |
66 | 94 |
67 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 95 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
68 std::unique_ptr<BlimpContents> blimp_contents = | 96 std::unique_ptr<BlimpContents> blimp_contents = |
69 base::WrapUnique(new BlimpContentsImpl); | 97 base::MakeUnique<BlimpContentsImpl>(); |
70 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 98 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
71 return blimp_contents; | 99 return blimp_contents; |
72 } | 100 } |
73 | 101 |
102 void BlimpClientContextImpl::OnConnected() {} | |
103 | |
104 void BlimpClientContextImpl::OnDisconnected(int result) {} | |
105 | |
74 } // namespace client | 106 } // namespace client |
75 } // namespace blimp | 107 } // namespace blimp |
OLD | NEW |