Chromium Code Reviews| 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 <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/blimp_client_switches.h" | 15 #include "blimp/client/core/blimp_client_switches.h" |
| 16 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 16 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 17 #include "blimp/client/core/compositor/blob_channel_feature.h" | 17 #include "blimp/client/core/compositor/blob_channel_feature.h" |
| 18 #include "blimp/client/core/contents/blimp_contents_impl.h" | 18 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 19 #include "blimp/client/core/contents/blimp_contents_manager.h" | 19 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 20 #include "blimp/client/core/contents/ime_feature.h" | 20 #include "blimp/client/core/contents/ime_feature.h" |
| 21 #include "blimp/client/core/contents/navigation_feature.h" | 21 #include "blimp/client/core/contents/navigation_feature.h" |
| 22 #include "blimp/client/core/contents/tab_control_feature.h" | 22 #include "blimp/client/core/contents/tab_control_feature.h" |
| 23 #include "blimp/client/core/feedback/blimp_feedback_data.h" | 23 #include "blimp/client/core/feedback/blimp_feedback_data.h" |
| 24 #include "blimp/client/core/geolocation/geolocation_feature.h" | 24 #include "blimp/client/core/geolocation/geolocation_feature.h" |
| 25 #include "blimp/client/core/render_widget/render_widget_feature.h" | 25 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 26 #include "blimp/client/core/session/cross_thread_network_event_observer.h" | 26 #include "blimp/client/core/session/cross_thread_network_event_observer.h" |
| 27 #include "blimp/client/core/settings/settings.h" | |
| 27 #include "blimp/client/core/settings/settings_feature.h" | 28 #include "blimp/client/core/settings/settings_feature.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/android/blimp_client_context_impl_android.h" | 37 #include "blimp/client/core/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(io_thread_task_runner, |
| 63 file_thread_task_runner, | 66 file_thread_task_runner, |
| 64 std::move(compositor_dependencies)); | 67 std::move(compositor_dependencies), |
| 68 local_state); | |
| 65 #else | 69 #else |
| 66 return new BlimpClientContextImpl(io_thread_task_runner, | 70 return new BlimpClientContextImpl(io_thread_task_runner, |
| 67 file_thread_task_runner, | 71 file_thread_task_runner, |
| 68 std::move(compositor_dependencies)); | 72 std::move(compositor_dependencies), |
| 73 local_state); | |
| 69 #endif // defined(OS_ANDROID) | 74 #endif // defined(OS_ANDROID) |
| 70 } | 75 } |
| 71 | 76 |
| 77 // This function is declared in //blimp/client/public/blimp_client_context.h | |
| 78 // and either this function or the one in | |
| 79 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | |
| 80 // any binary using BlimpClientContext::RegisterPrefs. | |
| 81 // static | |
| 82 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 83 Settings::RegisterPrefs(registry); | |
| 84 } | |
| 85 | |
| 72 BlimpClientContextImpl::BlimpClientContextImpl( | 86 BlimpClientContextImpl::BlimpClientContextImpl( |
| 73 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 74 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 88 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 75 std::unique_ptr<CompositorDependencies> compositor_dependencies) | 89 std::unique_ptr<CompositorDependencies> compositor_dependencies, |
| 90 PrefService* local_state) | |
| 76 : BlimpClientContext(), | 91 : BlimpClientContext(), |
| 77 io_thread_task_runner_(io_thread_task_runner), | 92 io_thread_task_runner_(io_thread_task_runner), |
| 78 file_thread_task_runner_(file_thread_task_runner), | 93 file_thread_task_runner_(file_thread_task_runner), |
| 79 blimp_compositor_dependencies_( | 94 blimp_compositor_dependencies_( |
| 80 base::MakeUnique<BlimpCompositorDependencies>( | 95 base::MakeUnique<BlimpCompositorDependencies>( |
| 81 std::move(compositor_dependencies))), | 96 std::move(compositor_dependencies))), |
| 97 settings_(new Settings(local_state)), | |
|
David Trainor- moved to gerrit
2016/10/01 03:26:34
base::MakeUnique
Menglin
2016/10/03 23:08:26
Done.
| |
| 82 blob_channel_feature_(new BlobChannelFeature(this)), | 98 blob_channel_feature_(new BlobChannelFeature(this)), |
| 83 geolocation_feature_(base::MakeUnique<GeolocationFeature>( | 99 geolocation_feature_(base::MakeUnique<GeolocationFeature>( |
| 84 base::MakeUnique<device::LocationArbitrator>( | 100 base::MakeUnique<device::LocationArbitrator>( |
| 85 base::MakeUnique<device::GeolocationDelegate>()))), | 101 base::MakeUnique<device::GeolocationDelegate>()))), |
| 86 ime_feature_(new ImeFeature), | 102 ime_feature_(new ImeFeature), |
| 87 navigation_feature_(new NavigationFeature), | 103 navigation_feature_(new NavigationFeature), |
| 88 render_widget_feature_(new RenderWidgetFeature), | 104 render_widget_feature_(new RenderWidgetFeature), |
| 89 settings_feature_(new SettingsFeature), | 105 settings_feature_(new SettingsFeature(settings_.get())), |
|
David Trainor- moved to gerrit
2016/10/01 03:26:34
base::MakeUnique
Menglin
2016/10/03 23:08:26
Done.
| |
| 90 tab_control_feature_(new TabControlFeature), | 106 tab_control_feature_(new TabControlFeature), |
| 91 blimp_contents_manager_( | 107 blimp_contents_manager_( |
| 92 new BlimpContentsManager(blimp_compositor_dependencies_.get(), | 108 new BlimpContentsManager(blimp_compositor_dependencies_.get(), |
| 93 ime_feature_.get(), | 109 ime_feature_.get(), |
| 94 navigation_feature_.get(), | 110 navigation_feature_.get(), |
| 95 render_widget_feature_.get(), | 111 render_widget_feature_.get(), |
| 96 tab_control_feature_.get())), | 112 tab_control_feature_.get())), |
| 97 weak_factory_(this) { | 113 weak_factory_(this) { |
| 98 net_components_.reset(new ClientNetworkComponents( | 114 net_components_.reset(new ClientNetworkComponents( |
| 99 base::MakeUnique<CrossThreadNetworkEventObserver>( | 115 base::MakeUnique<CrossThreadNetworkEventObserver>( |
| 100 connection_status_.GetWeakPtr(), | 116 connection_status_.GetWeakPtr(), |
| 101 base::SequencedTaskRunnerHandle::Get()))); | 117 base::SequencedTaskRunnerHandle::Get()))); |
| 102 | 118 |
| 103 // The |thread_pipe_manager_| must be set up correctly before features are | 119 // The |thread_pipe_manager_| must be set up correctly before features are |
| 104 // registered. | 120 // registered. |
| 105 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( | 121 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( |
| 106 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); | 122 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); |
| 107 | 123 |
| 108 RegisterFeatures(); | 124 RegisterFeatures(); |
| 109 InitializeSettings(); | 125 settings_feature_->PushSettings(); |
|
David Trainor- moved to gerrit
2016/10/01 03:26:34
I wonder if this would make more sense being done
Menglin
2016/10/03 23:08:26
Yeah this just just queues up the message until co
| |
| 110 | 126 |
| 111 // Initialize must only be posted after the features have been | 127 // Initialize must only be posted after the features have been |
| 112 // registered. | 128 // registered. |
| 113 io_thread_task_runner_->PostTask( | 129 io_thread_task_runner_->PostTask( |
| 114 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 130 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 115 base::Unretained(net_components_.get()))); | 131 base::Unretained(net_components_.get()))); |
| 116 | 132 |
| 117 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); | 133 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); |
| 118 } | 134 } |
| 119 | 135 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 241 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 226 render_widget_feature_.get()); | 242 render_widget_feature_.get()); |
| 227 settings_feature_->set_outgoing_message_processor( | 243 settings_feature_->set_outgoing_message_processor( |
| 228 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 244 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 229 settings_feature_.get())); | 245 settings_feature_.get())); |
| 230 tab_control_feature_->set_outgoing_message_processor( | 246 tab_control_feature_->set_outgoing_message_processor( |
| 231 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, | 247 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, |
| 232 tab_control_feature_.get())); | 248 tab_control_feature_.get())); |
| 233 } | 249 } |
| 234 | 250 |
| 235 void BlimpClientContextImpl::InitializeSettings() { | |
| 236 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 237 switches::kDownloadWholeDocument)) | |
| 238 settings_feature_->SetRecordWholeDocument(true); | |
| 239 } | |
| 240 | |
| 241 void BlimpClientContextImpl::DropConnection() { | 251 void BlimpClientContextImpl::DropConnection() { |
| 242 io_thread_task_runner_->PostTask( | 252 io_thread_task_runner_->PostTask( |
| 243 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); | 253 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); |
| 244 } | 254 } |
| 245 | 255 |
| 246 void BlimpClientContextImpl::CreateIdentitySource() { | 256 void BlimpClientContextImpl::CreateIdentitySource() { |
| 247 identity_source_ = base::MakeUnique<IdentitySource>( | 257 identity_source_ = base::MakeUnique<IdentitySource>( |
| 248 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, | 258 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, |
| 249 base::Unretained(this))); | 259 base::Unretained(this))); |
| 250 } | 260 } |
| 251 | 261 |
| 252 void BlimpClientContextImpl::OnImageDecodeError() { | 262 void BlimpClientContextImpl::OnImageDecodeError() { |
| 253 // Currently we just drop the connection on image decoding error. | 263 // Currently we just drop the connection on image decoding error. |
| 254 DropConnection(); | 264 DropConnection(); |
| 255 } | 265 } |
| 256 | 266 |
| 257 } // namespace client | 267 } // namespace client |
| 258 } // namespace blimp | 268 } // namespace blimp |
| OLD | NEW |