| 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/command_line.h" |
| 8 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/sequenced_task_runner_handle.h" | 11 #include "base/threading/sequenced_task_runner_handle.h" |
| 12 #include "blimp/client/core/blimp_client_switches.h" |
| 13 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 11 #include "blimp/client/core/contents/blimp_contents_impl.h" | 14 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 12 #include "blimp/client/core/contents/blimp_contents_manager.h" | 15 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 13 #include "blimp/client/core/contents/ime_feature.h" | 16 #include "blimp/client/core/contents/ime_feature.h" |
| 14 #include "blimp/client/core/contents/navigation_feature.h" | 17 #include "blimp/client/core/contents/navigation_feature.h" |
| 15 #include "blimp/client/core/contents/tab_control_feature.h" | 18 #include "blimp/client/core/contents/tab_control_feature.h" |
| 19 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 16 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 20 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 21 #include "blimp/client/core/settings/settings_feature.h" |
| 17 #include "blimp/client/public/blimp_client_context_delegate.h" | 22 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 23 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 18 | 24 |
| 19 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 20 #include "blimp/client/core/android/blimp_client_context_impl_android.h" | 26 #include "blimp/client/core/android/blimp_client_context_impl_android.h" |
| 21 #endif // OS_ANDROID | 27 #endif // OS_ANDROID |
| 22 | 28 |
| 23 namespace blimp { | 29 namespace blimp { |
| 24 namespace client { | 30 namespace client { |
| 25 | 31 |
| 26 namespace { | 32 namespace { |
| 27 const char kDefaultAssignerUrl[] = | 33 const char kDefaultAssignerUrl[] = |
| 28 "https://blimp-pa.googleapis.com/v1/assignment"; | 34 "https://blimp-pa.googleapis.com/v1/assignment"; |
| 29 } // namespace | 35 } // namespace |
| 30 | 36 |
| 31 // This function is declared in //blimp/client/public/blimp_client_context.h, | 37 // This function is declared in //blimp/client/public/blimp_client_context.h, |
| 32 // and either this function or the one in | 38 // and either this function or the one in |
| 33 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 39 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 34 // any binary using BlimpClientContext::Create. | 40 // any binary using BlimpClientContext::Create. |
| 35 // static | 41 // static |
| 36 BlimpClientContext* BlimpClientContext::Create( | 42 BlimpClientContext* BlimpClientContext::Create( |
| 37 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 38 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) { | 44 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 45 std::unique_ptr<CompositorDependencies> compositor_dependencies) { |
| 39 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 40 return new BlimpClientContextImplAndroid(io_thread_task_runner, | 47 return new BlimpClientContextImplAndroid(io_thread_task_runner, |
| 41 file_thread_task_runner); | 48 file_thread_task_runner, |
| 49 std::move(compositor_dependencies)); |
| 42 #else | 50 #else |
| 43 return new BlimpClientContextImpl(io_thread_task_runner, | 51 return new BlimpClientContextImpl(io_thread_task_runner, |
| 44 file_thread_task_runner); | 52 file_thread_task_runner, |
| 53 std::move(compositor_dependencies)); |
| 45 #endif // defined(OS_ANDROID) | 54 #endif // defined(OS_ANDROID) |
| 46 } | 55 } |
| 47 | 56 |
| 48 BlimpClientContextImpl::BlimpClientContextImpl( | 57 BlimpClientContextImpl::BlimpClientContextImpl( |
| 49 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 58 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) | 59 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 60 std::unique_ptr<CompositorDependencies> compositor_dependencies) |
| 51 : BlimpClientContext(), | 61 : BlimpClientContext(), |
| 52 io_thread_task_runner_(io_thread_task_runner), | 62 io_thread_task_runner_(io_thread_task_runner), |
| 53 file_thread_task_runner_(file_thread_task_runner), | 63 file_thread_task_runner_(file_thread_task_runner), |
| 64 blimp_compositor_dependencies_( |
| 65 base::MakeUnique<BlimpCompositorDependencies>( |
| 66 std::move(compositor_dependencies))), |
| 54 ime_feature_(new ImeFeature), | 67 ime_feature_(new ImeFeature), |
| 55 navigation_feature_(new NavigationFeature), | 68 navigation_feature_(new NavigationFeature), |
| 69 render_widget_feature_(new RenderWidgetFeature), |
| 70 settings_feature_(new SettingsFeature), |
| 56 tab_control_feature_(new TabControlFeature), | 71 tab_control_feature_(new TabControlFeature), |
| 57 blimp_contents_manager_( | 72 blimp_contents_manager_( |
| 58 new BlimpContentsManager(ime_feature_.get(), | 73 new BlimpContentsManager(blimp_compositor_dependencies_.get(), |
| 74 ime_feature_.get(), |
| 59 navigation_feature_.get(), | 75 navigation_feature_.get(), |
| 76 render_widget_feature_.get(), |
| 60 tab_control_feature_.get())), | 77 tab_control_feature_.get())), |
| 61 weak_factory_(this) { | 78 weak_factory_(this) { |
| 62 net_components_.reset(new ClientNetworkComponents( | 79 net_components_.reset(new ClientNetworkComponents( |
| 63 base::MakeUnique<CrossThreadNetworkEventObserver>( | 80 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 64 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); | 81 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get()))); |
| 65 | 82 |
| 66 // The |thread_pipe_manager_| must be set up correctly before features are | 83 // The |thread_pipe_manager_| must be set up correctly before features are |
| 67 // registered. | 84 // registered. |
| 68 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 85 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 69 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 86 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 70 | 87 |
| 71 RegisterFeatures(); | 88 RegisterFeatures(); |
| 89 InitializeSettings(); |
| 72 | 90 |
| 73 // Initialize must only be posted after the calls features have been | 91 // Initialize must only be posted after the calls features have been |
| 74 // registered. | 92 // registered. |
| 75 io_thread_task_runner_->PostTask( | 93 io_thread_task_runner_->PostTask( |
| 76 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 94 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 77 base::Unretained(net_components_.get()))); | 95 base::Unretained(net_components_.get()))); |
| 78 } | 96 } |
| 79 | 97 |
| 80 BlimpClientContextImpl::~BlimpClientContextImpl() { | 98 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 81 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 99 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 171 } |
| 154 | 172 |
| 155 void BlimpClientContextImpl::RegisterFeatures() { | 173 void BlimpClientContextImpl::RegisterFeatures() { |
| 156 // Register features' message senders and receivers. | 174 // Register features' message senders and receivers. |
| 157 ime_feature_->set_outgoing_message_processor( | 175 ime_feature_->set_outgoing_message_processor( |
| 158 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 176 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
| 159 ime_feature_.get())); | 177 ime_feature_.get())); |
| 160 navigation_feature_->set_outgoing_message_processor( | 178 navigation_feature_->set_outgoing_message_processor( |
| 161 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation, | 179 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation, |
| 162 navigation_feature_.get())); | 180 navigation_feature_.get())); |
| 181 render_widget_feature_->set_outgoing_input_message_processor( |
| 182 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, |
| 183 render_widget_feature_.get())); |
| 184 render_widget_feature_->set_outgoing_compositor_message_processor( |
| 185 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, |
| 186 render_widget_feature_.get())); |
| 187 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 188 render_widget_feature_.get()); |
| 189 settings_feature_->set_outgoing_message_processor( |
| 190 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 191 settings_feature_.get())); |
| 163 tab_control_feature_->set_outgoing_message_processor( | 192 tab_control_feature_->set_outgoing_message_processor( |
| 164 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, | 193 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, |
| 165 tab_control_feature_.get())); | 194 tab_control_feature_.get())); |
| 166 } | 195 } |
| 167 | 196 |
| 197 void BlimpClientContextImpl::InitializeSettings() { |
| 198 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 199 switches::kDownloadWholeDocument)) |
| 200 settings_feature_->SetRecordWholeDocument(true); |
| 201 } |
| 202 |
| 168 void BlimpClientContextImpl::CreateIdentitySource() { | 203 void BlimpClientContextImpl::CreateIdentitySource() { |
| 169 identity_source_ = base::MakeUnique<IdentitySource>( | 204 identity_source_ = base::MakeUnique<IdentitySource>( |
| 170 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, | 205 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, |
| 171 base::Unretained(this))); | 206 base::Unretained(this))); |
| 172 } | 207 } |
| 173 | 208 |
| 174 } // namespace client | 209 } // namespace client |
| 175 } // namespace blimp | 210 } // namespace blimp |
| OLD | NEW |