Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: blimp/client/core/blimp_client_context_impl.cc

Issue 2300493002: Move glue code of blob channel to blimp_client_context_impl. (Closed)
Patch Set: Refactor the code a bit. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/compositor/decoding_image_generator.h"
11 #include "blimp/client/core/contents/blimp_contents_impl.h" 12 #include "blimp/client/core/contents/blimp_contents_impl.h"
12 #include "blimp/client/core/contents/blimp_contents_manager.h" 13 #include "blimp/client/core/contents/blimp_contents_manager.h"
13 #include "blimp/client/core/contents/ime_feature.h" 14 #include "blimp/client/core/contents/ime_feature.h"
14 #include "blimp/client/core/contents/navigation_feature.h" 15 #include "blimp/client/core/contents/navigation_feature.h"
15 #include "blimp/client/core/contents/tab_control_feature.h" 16 #include "blimp/client/core/contents/tab_control_feature.h"
16 #include "blimp/client/core/session/cross_thread_network_event_observer.h" 17 #include "blimp/client/core/session/cross_thread_network_event_observer.h"
17 #include "blimp/client/public/blimp_client_context_delegate.h" 18 #include "blimp/client/public/blimp_client_context_delegate.h"
19 #include "blimp/common/blob_cache/in_memory_blob_cache.h"
20 #include "blimp/net/blob_channel/blob_channel_receiver.h"
21 #include "blimp/net/blob_channel/helium_blob_receiver_delegate.h"
22 #include "third_party/skia/include/core/SkGraphics.h"
18 23
19 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
20 #include "blimp/client/core/android/blimp_client_context_impl_android.h" 25 #include "blimp/client/core/android/blimp_client_context_impl_android.h"
21 #endif // OS_ANDROID 26 #endif // OS_ANDROID
22 27
23 namespace blimp { 28 namespace blimp {
24 namespace client { 29 namespace client {
25 30
26 namespace { 31 namespace {
32
33 SkImageGenerator* CreateImageGenerator(SkData* data) {
34 return blimp::client::DecodingImageGenerator::create(data);
35 }
36
27 const char kDefaultAssignerUrl[] = 37 const char kDefaultAssignerUrl[] =
28 "https://blimp-pa.googleapis.com/v1/assignment"; 38 "https://blimp-pa.googleapis.com/v1/assignment";
29 } // namespace 39 } // namespace
30 40
41 // static
42 void BlimpClientContextImpl::SetImageGeneratorFromEncodedFactory() {
43 SkGraphics::SetImageGeneratorFromEncodedFactory(CreateImageGenerator);
44 }
45
31 // This function is declared in //blimp/client/public/blimp_client_context.h, 46 // This function is declared in //blimp/client/public/blimp_client_context.h,
32 // and either this function or the one in 47 // and either this function or the one in
33 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 48 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
34 // any binary using BlimpClientContext::Create. 49 // any binary using BlimpClientContext::Create.
35 // static 50 // static
36 BlimpClientContext* BlimpClientContext::Create( 51 BlimpClientContext* BlimpClientContext::Create(
37 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 52 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
38 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) { 53 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) {
39 #if defined(OS_ANDROID) 54 #if defined(OS_ANDROID)
40 return new BlimpClientContextImplAndroid(io_thread_task_runner, 55 return new BlimpClientContextImplAndroid(io_thread_task_runner,
(...skipping 20 matching lines...) Expand all
61 weak_factory_(this) { 76 weak_factory_(this) {
62 net_components_.reset(new ClientNetworkComponents( 77 net_components_.reset(new ClientNetworkComponents(
63 base::MakeUnique<CrossThreadNetworkEventObserver>( 78 base::MakeUnique<CrossThreadNetworkEventObserver>(
64 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); 79 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())));
65 80
66 // The |thread_pipe_manager_| must be set up correctly before features are 81 // The |thread_pipe_manager_| must be set up correctly before features are
67 // registered. 82 // registered.
68 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( 83 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>(
69 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); 84 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler());
70 85
86 SetupBlobChannel();
87
71 RegisterFeatures(); 88 RegisterFeatures();
72 89
73 // Initialize must only be posted after the calls features have been 90 // Initialize must only be posted after the calls features have been
74 // registered. 91 // registered.
75 io_thread_task_runner_->PostTask( 92 io_thread_task_runner_->PostTask(
76 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, 93 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize,
77 base::Unretained(net_components_.get()))); 94 base::Unretained(net_components_.get())));
95
96 SetImageGeneratorFromEncodedFactory();
Khushal 2016/08/31 03:55:08 I checked, we don't need to do this. skia calls ou
David Trainor- moved to gerrit 2016/08/31 05:40:57 Looked through the code quickly as well and it loo
nyquist 2016/09/01 00:26:23 I wonder, are there any times where we have to re-
xingliu 2016/09/01 02:08:09 I'll remove this.
78 } 97 }
79 98
80 BlimpClientContextImpl::~BlimpClientContextImpl() { 99 BlimpClientContextImpl::~BlimpClientContextImpl() {
81 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); 100 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release());
82 } 101 }
83 102
84 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { 103 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) {
85 delegate_ = delegate; 104 delegate_ = delegate;
86 } 105 }
87 106
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Register features' message senders and receivers. 175 // Register features' message senders and receivers.
157 ime_feature_->set_outgoing_message_processor( 176 ime_feature_->set_outgoing_message_processor(
158 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, 177 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme,
159 ime_feature_.get())); 178 ime_feature_.get()));
160 navigation_feature_->set_outgoing_message_processor( 179 navigation_feature_->set_outgoing_message_processor(
161 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation, 180 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation,
162 navigation_feature_.get())); 181 navigation_feature_.get()));
163 tab_control_feature_->set_outgoing_message_processor( 182 tab_control_feature_->set_outgoing_message_processor(
164 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, 183 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl,
165 tab_control_feature_.get())); 184 tab_control_feature_.get()));
185 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel,
David Trainor- moved to gerrit 2016/08/31 05:40:57 let's try to keep these in alphabetical order for
xingliu 2016/09/01 02:08:10 Done.
186 blob_delegate_);
187 }
188
189 void BlimpClientContextImpl::SetupBlobChannel() {
190 std::unique_ptr<HeliumBlobReceiverDelegate> blob_delegate(
191 new HeliumBlobReceiverDelegate);
Khushal 2016/08/31 03:55:08 nit: prefer MakeUnique over new Foo. For this and
xingliu 2016/09/01 02:08:09 Changed the first one. Didn't change the second on
192 blob_delegate_ = blob_delegate.get();
Khushal 2016/08/31 03:55:08 Do we actually need to cache this pointer? We only
David Trainor- moved to gerrit 2016/08/31 05:40:57 Would it be cleaner to expose a BlobChannelReceive
xingliu 2016/09/01 02:08:10 RegisterFeatures needs BlimpMessageProcessor*, Hel
Khushal 2016/09/01 02:10:10 Yeah, that's cool too. Or just return the receiver
xingliu 2016/09/01 21:03:34 For test, they have a mock message processor.
193 blob_receiver_ = BlobChannelReceiver::Create(
194 base::WrapUnique(new InMemoryBlobCache), std::move(blob_delegate));
195 blob_image_processor_.set_blob_receiver(blob_receiver_.get());
196 blob_image_processor_.set_error_delegate(this);
197 }
198
199 void BlimpClientContextImpl::OnImageDecodeError() {
200 io_thread_task_runner_->PostTask(
201 FROM_HERE,
202 base::Bind(
203 &BrowserConnectionHandler::DropCurrentConnection,
204 base::Unretained(net_components_->GetBrowserConnectionHandler())));
166 } 205 }
167 206
168 void BlimpClientContextImpl::CreateIdentitySource() { 207 void BlimpClientContextImpl::CreateIdentitySource() {
169 identity_source_ = base::MakeUnique<IdentitySource>( 208 identity_source_ = base::MakeUnique<IdentitySource>(
170 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, 209 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource,
171 base::Unretained(this))); 210 base::Unretained(this)));
172 } 211 }
173 212
174 } // namespace client 213 } // namespace client
175 } // namespace blimp 214 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698