| 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/context/blimp_client_context_impl.h" | 5 #include "blimp/client/core/context/blimp_client_context_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/threading/sequenced_task_runner_handle.h" | 14 #include "base/threading/sequenced_task_runner_handle.h" |
| 15 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 15 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 16 #include "blimp/client/core/compositor/blob_channel_feature.h" | 16 #include "blimp/client/core/compositor/blob_channel_feature.h" |
| 17 #include "blimp/client/core/contents/blimp_contents_impl.h" | 17 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 18 #include "blimp/client/core/contents/blimp_contents_manager.h" | 18 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 19 #include "blimp/client/core/contents/ime_feature.h" | 19 #include "blimp/client/core/contents/ime_feature.h" |
| 20 #include "blimp/client/core/contents/navigation_feature.h" | 20 #include "blimp/client/core/contents/navigation_feature.h" |
| 21 #include "blimp/client/core/contents/tab_control_feature.h" | 21 #include "blimp/client/core/contents/tab_control_feature.h" |
| 22 #include "blimp/client/core/feedback/blimp_feedback_data.h" | 22 #include "blimp/client/core/feedback/blimp_feedback_data.h" |
| 23 #include "blimp/client/core/geolocation/geolocation_feature.h" | 23 #include "blimp/client/core/geolocation/geolocation_feature.h" |
| 24 #include "blimp/client/core/render_widget/render_widget_feature.h" | 24 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 25 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 25 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 26 #include "blimp/client/core/settings/settings.h" |
| 26 #include "blimp/client/core/settings/settings_feature.h" | 27 #include "blimp/client/core/settings/settings_feature.h" |
| 27 #include "blimp/client/core/switches/blimp_client_switches.h" | 28 #include "blimp/client/core/switches/blimp_client_switches.h" |
| 28 #include "blimp/client/public/blimp_client_context_delegate.h" | 29 #include "blimp/client/public/blimp_client_context_delegate.h" |
| 29 #include "blimp/client/public/compositor/compositor_dependencies.h" | 30 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 31 #include "components/prefs/pref_service.h" |
| 30 #include "device/geolocation/geolocation_delegate.h" | 32 #include "device/geolocation/geolocation_delegate.h" |
| 31 #include "device/geolocation/location_arbitrator.h" | 33 #include "device/geolocation/location_arbitrator.h" |
| 32 #include "ui/gfx/native_widget_types.h" | 34 #include "ui/gfx/native_widget_types.h" |
| 33 | 35 |
| 34 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 35 #include "blimp/client/core/context/android/blimp_client_context_impl_android.h" | 37 #include "blimp/client/core/context/android/blimp_client_context_impl_android.h" |
| 36 #endif // OS_ANDROID | 38 #endif // OS_ANDROID |
| 37 | 39 |
| 38 namespace blimp { | 40 namespace blimp { |
| 39 namespace client { | 41 namespace client { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 } // namespace | 52 } // namespace |
| 51 | 53 |
| 52 // This function is declared in //blimp/client/public/blimp_client_context.h, | 54 // This function is declared in //blimp/client/public/blimp_client_context.h, |
| 53 // and either this function or the one in | 55 // and either this function or the one in |
| 54 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 56 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 55 // any binary using BlimpClientContext::Create. | 57 // any binary using BlimpClientContext::Create. |
| 56 // static | 58 // static |
| 57 BlimpClientContext* BlimpClientContext::Create( | 59 BlimpClientContext* BlimpClientContext::Create( |
| 58 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 60 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 60 std::unique_ptr<CompositorDependencies> compositor_dependencies) { | 62 std::unique_ptr<CompositorDependencies> compositor_dependencies, |
| 63 PrefService* local_state) { |
| 61 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
| 62 return new BlimpClientContextImplAndroid(io_thread_task_runner, | 65 return new BlimpClientContextImplAndroid( |
| 63 file_thread_task_runner, | 66 io_thread_task_runner, file_thread_task_runner, |
| 64 std::move(compositor_dependencies)); | 67 std::move(compositor_dependencies), local_state); |
| 65 #else | 68 #else |
| 66 return new BlimpClientContextImpl(io_thread_task_runner, | 69 return new BlimpClientContextImpl( |
| 67 file_thread_task_runner, | 70 io_thread_task_runner, file_thread_task_runner, |
| 68 std::move(compositor_dependencies)); | 71 std::move(compositor_dependencies), local_state); |
| 69 #endif // defined(OS_ANDROID) | 72 #endif // defined(OS_ANDROID) |
| 70 } | 73 } |
| 71 | 74 |
| 75 // This function is declared in //blimp/client/public/blimp_client_context.h |
| 76 // and either this function or the one in |
| 77 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 78 // any binary using BlimpClientContext::RegisterPrefs. |
| 79 // static |
| 80 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) { |
| 81 Settings::RegisterPrefs(registry); |
| 82 } |
| 83 |
| 84 // This function is declared in //blimp/client/public/blimp_client_context.h |
| 85 // and either this function or the one in |
| 86 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 87 // any binary using BlimpClientContext::ApplyBlimpSwitches. |
| 88 // static |
| 89 void BlimpClientContext::ApplyBlimpSwitches(CommandLinePrefStore* store) { |
| 90 Settings::ApplyBlimpSwitches(store); |
| 91 } |
| 92 |
| 72 BlimpClientContextImpl::BlimpClientContextImpl( | 93 BlimpClientContextImpl::BlimpClientContextImpl( |
| 73 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 94 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 74 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 95 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 75 std::unique_ptr<CompositorDependencies> compositor_dependencies) | 96 std::unique_ptr<CompositorDependencies> compositor_dependencies, |
| 97 PrefService* local_state) |
| 76 : BlimpClientContext(), | 98 : BlimpClientContext(), |
| 77 io_thread_task_runner_(io_thread_task_runner), | 99 io_thread_task_runner_(io_thread_task_runner), |
| 78 file_thread_task_runner_(file_thread_task_runner), | 100 file_thread_task_runner_(file_thread_task_runner), |
| 79 blimp_compositor_dependencies_( | 101 blimp_compositor_dependencies_( |
| 80 base::MakeUnique<BlimpCompositorDependencies>( | 102 base::MakeUnique<BlimpCompositorDependencies>( |
| 81 std::move(compositor_dependencies))), | 103 std::move(compositor_dependencies))), |
| 104 settings_(base::MakeUnique<Settings>(local_state)), |
| 82 blob_channel_feature_(new BlobChannelFeature(this)), | 105 blob_channel_feature_(new BlobChannelFeature(this)), |
| 83 geolocation_feature_(base::MakeUnique<GeolocationFeature>( | 106 geolocation_feature_(base::MakeUnique<GeolocationFeature>( |
| 84 base::MakeUnique<device::LocationArbitrator>( | 107 base::MakeUnique<device::LocationArbitrator>( |
| 85 base::MakeUnique<device::GeolocationDelegate>()))), | 108 base::MakeUnique<device::GeolocationDelegate>()))), |
| 86 ime_feature_(new ImeFeature), | 109 ime_feature_(new ImeFeature), |
| 87 navigation_feature_(new NavigationFeature), | 110 navigation_feature_(new NavigationFeature), |
| 88 render_widget_feature_(new RenderWidgetFeature), | 111 render_widget_feature_(new RenderWidgetFeature), |
| 89 settings_feature_(new SettingsFeature), | 112 settings_feature_(base::MakeUnique<SettingsFeature>(settings_.get())), |
| 90 tab_control_feature_(new TabControlFeature), | 113 tab_control_feature_(new TabControlFeature), |
| 91 blimp_contents_manager_( | 114 blimp_contents_manager_( |
| 92 new BlimpContentsManager(blimp_compositor_dependencies_.get(), | 115 new BlimpContentsManager(blimp_compositor_dependencies_.get(), |
| 93 ime_feature_.get(), | 116 ime_feature_.get(), |
| 94 navigation_feature_.get(), | 117 navigation_feature_.get(), |
| 95 render_widget_feature_.get(), | 118 render_widget_feature_.get(), |
| 96 tab_control_feature_.get())), | 119 tab_control_feature_.get())), |
| 97 weak_factory_(this) { | 120 weak_factory_(this) { |
| 98 net_components_.reset(new ClientNetworkComponents( | 121 net_components_.reset(new ClientNetworkComponents( |
| 99 base::MakeUnique<CrossThreadNetworkEventObserver>( | 122 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 100 connection_status_.GetWeakPtr(), | 123 connection_status_.GetWeakPtr(), |
| 101 base::SequencedTaskRunnerHandle::Get()))); | 124 base::SequencedTaskRunnerHandle::Get()))); |
| 102 | 125 |
| 103 // The |thread_pipe_manager_| must be set up correctly before features are | 126 // The |thread_pipe_manager_| must be set up correctly before features are |
| 104 // registered. | 127 // registered. |
| 105 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 128 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 106 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 129 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 107 | 130 |
| 108 RegisterFeatures(); | 131 RegisterFeatures(); |
| 109 InitializeSettings(); | 132 settings_feature_->PushSettings(); |
| 110 | 133 |
| 111 connection_status_.AddObserver(this); | 134 connection_status_.AddObserver(this); |
| 112 | 135 |
| 113 // Initialize must only be posted after the features have been | 136 // Initialize must only be posted after the features have been |
| 114 // registered. | 137 // registered. |
| 115 io_thread_task_runner_->PostTask( | 138 io_thread_task_runner_->PostTask( |
| 116 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 139 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 117 base::Unretained(net_components_.get()))); | 140 base::Unretained(net_components_.get()))); |
| 118 | 141 |
| 119 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); | 142 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 241 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 219 render_widget_feature_.get()); | 242 render_widget_feature_.get()); |
| 220 settings_feature_->set_outgoing_message_processor( | 243 settings_feature_->set_outgoing_message_processor( |
| 221 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 244 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 222 settings_feature_.get())); | 245 settings_feature_.get())); |
| 223 tab_control_feature_->set_outgoing_message_processor( | 246 tab_control_feature_->set_outgoing_message_processor( |
| 224 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, | 247 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, |
| 225 tab_control_feature_.get())); | 248 tab_control_feature_.get())); |
| 226 } | 249 } |
| 227 | 250 |
| 228 void BlimpClientContextImpl::InitializeSettings() { | |
| 229 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 230 switches::kDownloadWholeDocument)) | |
| 231 settings_feature_->SetRecordWholeDocument(true); | |
| 232 } | |
| 233 | |
| 234 void BlimpClientContextImpl::DropConnection() { | 251 void BlimpClientContextImpl::DropConnection() { |
| 235 io_thread_task_runner_->PostTask( | 252 io_thread_task_runner_->PostTask( |
| 236 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); | 253 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); |
| 237 } | 254 } |
| 238 | 255 |
| 239 void BlimpClientContextImpl::OnImageDecodeError() { | 256 void BlimpClientContextImpl::OnImageDecodeError() { |
| 240 // Currently we just drop the connection on image decoding error. | 257 // Currently we just drop the connection on image decoding error. |
| 241 DropConnection(); | 258 DropConnection(); |
| 242 } | 259 } |
| 243 | 260 |
| 244 void BlimpClientContextImpl::OnConnected() { | 261 void BlimpClientContextImpl::OnConnected() { |
| 245 if (delegate_) { | 262 if (delegate_) { |
| 246 delegate_->OnConnected(); | 263 delegate_->OnConnected(); |
| 247 } | 264 } |
| 248 } | 265 } |
| 249 | 266 |
| 250 void BlimpClientContextImpl::OnDisconnected(int result) { | 267 void BlimpClientContextImpl::OnDisconnected(int result) { |
| 251 if (delegate_) { | 268 if (delegate_) { |
| 252 if (result >= 0) { | 269 if (result >= 0) { |
| 253 delegate_->OnEngineDisconnected(result); | 270 delegate_->OnEngineDisconnected(result); |
| 254 } else { | 271 } else { |
| 255 delegate_->OnNetworkDisconnected(result); | 272 delegate_->OnNetworkDisconnected(result); |
| 256 } | 273 } |
| 257 } | 274 } |
| 258 } | 275 } |
| 259 | 276 |
| 260 } // namespace client | 277 } // namespace client |
| 261 } // namespace blimp | 278 } // namespace blimp |
| OLD | NEW |