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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: 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 <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/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/record_whole_document_observer.h"
27 #include "blimp/client/core/settings/settings.h"
26 #include "blimp/client/core/settings/settings_feature.h" 28 #include "blimp/client/core/settings/settings_feature.h"
27 #include "blimp/client/public/blimp_client_context_delegate.h" 29 #include "blimp/client/public/blimp_client_context_delegate.h"
28 #include "blimp/client/public/compositor/compositor_dependencies.h" 30 #include "blimp/client/public/compositor/compositor_dependencies.h"
31 #include "components/prefs/pref_service.h"
29 #include "device/geolocation/geolocation_delegate.h" 32 #include "device/geolocation/geolocation_delegate.h"
30 #include "device/geolocation/location_arbitrator.h" 33 #include "device/geolocation/location_arbitrator.h"
31 #include "ui/gfx/native_widget_types.h" 34 #include "ui/gfx/native_widget_types.h"
32 35
33 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
34 #include "blimp/client/core/android/blimp_client_context_impl_android.h" 37 #include "blimp/client/core/android/blimp_client_context_impl_android.h"
35 #endif // OS_ANDROID 38 #endif // OS_ANDROID
36 39
37 namespace blimp { 40 namespace blimp {
38 namespace client { 41 namespace client {
39 42
40 namespace { 43 namespace {
41 const char kDefaultAssignerUrl[] = 44 const char kDefaultAssignerUrl[] =
42 "https://blimp-pa.googleapis.com/v1/assignment"; 45 "https://blimp-pa.googleapis.com/v1/assignment";
43 } // namespace 46 } // namespace
44 47
45 // This function is declared in //blimp/client/public/blimp_client_context.h, 48 // This function is declared in //blimp/client/public/blimp_client_context.h,
46 // and either this function or the one in 49 // and either this function or the one in
47 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 50 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
48 // any binary using BlimpClientContext::Create. 51 // any binary using BlimpClientContext::Create.
49 // static 52 // static
50 BlimpClientContext* BlimpClientContext::Create( 53 BlimpClientContext* BlimpClientContext::Create(
51 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 54 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
52 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 55 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
53 std::unique_ptr<CompositorDependencies> compositor_dependencies) { 56 std::unique_ptr<CompositorDependencies> compositor_dependencies,
57 PrefService* local_state) {
54 #if defined(OS_ANDROID) 58 #if defined(OS_ANDROID)
55 return new BlimpClientContextImplAndroid(io_thread_task_runner, 59 return new BlimpClientContextImplAndroid(io_thread_task_runner,
56 file_thread_task_runner, 60 file_thread_task_runner,
57 std::move(compositor_dependencies)); 61 std::move(compositor_dependencies),
62 local_state);
58 #else 63 #else
59 return new BlimpClientContextImpl(io_thread_task_runner, 64 return new BlimpClientContextImpl(io_thread_task_runner,
60 file_thread_task_runner, 65 file_thread_task_runner,
61 std::move(compositor_dependencies)); 66 std::move(compositor_dependencies),
67 local_state);
62 #endif // defined(OS_ANDROID) 68 #endif // defined(OS_ANDROID)
63 } 69 }
64 70
71 // This function is declared in //blimp/client/public/blimp_client_context.h
72 // and either this function or the one in
73 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
74 // any binary using BlimpClientContext::RegisterPrefs.
75 // static
76 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) {
77 Settings::RegisterPrefs(registry);
78 }
79
65 BlimpClientContextImpl::BlimpClientContextImpl( 80 BlimpClientContextImpl::BlimpClientContextImpl(
66 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 81 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
67 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 82 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
68 std::unique_ptr<CompositorDependencies> compositor_dependencies) 83 std::unique_ptr<CompositorDependencies> compositor_dependencies,
84 PrefService* local_state)
69 : BlimpClientContext(), 85 : BlimpClientContext(),
70 io_thread_task_runner_(io_thread_task_runner), 86 io_thread_task_runner_(io_thread_task_runner),
71 file_thread_task_runner_(file_thread_task_runner), 87 file_thread_task_runner_(file_thread_task_runner),
72 blimp_compositor_dependencies_( 88 blimp_compositor_dependencies_(
73 base::MakeUnique<BlimpCompositorDependencies>( 89 base::MakeUnique<BlimpCompositorDependencies>(
74 std::move(compositor_dependencies))), 90 std::move(compositor_dependencies))),
75 blob_channel_feature_(new BlobChannelFeature(this)), 91 blob_channel_feature_(new BlobChannelFeature(this)),
76 geolocation_feature_(base::MakeUnique<GeolocationFeature>( 92 geolocation_feature_(base::MakeUnique<GeolocationFeature>(
77 base::MakeUnique<device::LocationArbitrator>( 93 base::MakeUnique<device::LocationArbitrator>(
78 base::MakeUnique<device::GeolocationDelegate>()))), 94 base::MakeUnique<device::GeolocationDelegate>()))),
79 ime_feature_(new ImeFeature), 95 ime_feature_(new ImeFeature),
80 navigation_feature_(new NavigationFeature), 96 navigation_feature_(new NavigationFeature),
81 render_widget_feature_(new RenderWidgetFeature), 97 render_widget_feature_(new RenderWidgetFeature),
82 settings_feature_(new SettingsFeature), 98 settings_feature_(new SettingsFeature),
83 tab_control_feature_(new TabControlFeature), 99 tab_control_feature_(new TabControlFeature),
84 blimp_contents_manager_( 100 blimp_contents_manager_(
85 new BlimpContentsManager(blimp_compositor_dependencies_.get(), 101 new BlimpContentsManager(blimp_compositor_dependencies_.get(),
86 ime_feature_.get(), 102 ime_feature_.get(),
87 navigation_feature_.get(), 103 navigation_feature_.get(),
88 render_widget_feature_.get(), 104 render_widget_feature_.get(),
89 tab_control_feature_.get())), 105 tab_control_feature_.get())),
106 settings_(new Settings(local_state)),
90 weak_factory_(this) { 107 weak_factory_(this) {
91 net_components_.reset(new ClientNetworkComponents( 108 net_components_.reset(new ClientNetworkComponents(
92 base::MakeUnique<CrossThreadNetworkEventObserver>( 109 base::MakeUnique<CrossThreadNetworkEventObserver>(
93 connection_status_.GetWeakPtr(), 110 connection_status_.GetWeakPtr(),
94 base::SequencedTaskRunnerHandle::Get()))); 111 base::SequencedTaskRunnerHandle::Get())));
95 112
96 // The |thread_pipe_manager_| must be set up correctly before features are 113 // The |thread_pipe_manager_| must be set up correctly before features are
97 // registered. 114 // registered.
98 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>( 115 thread_pipe_manager_ = base::MakeUnique<ThreadPipeManager>(
99 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler()); 116 io_thread_task_runner_, net_components_->GetBrowserConnectionHandler());
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 render_widget_feature_.get()); 231 render_widget_feature_.get());
215 settings_feature_->set_outgoing_message_processor( 232 settings_feature_->set_outgoing_message_processor(
216 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, 233 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings,
217 settings_feature_.get())); 234 settings_feature_.get()));
218 tab_control_feature_->set_outgoing_message_processor( 235 tab_control_feature_->set_outgoing_message_processor(
219 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, 236 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl,
220 tab_control_feature_.get())); 237 tab_control_feature_.get()));
221 } 238 }
222 239
223 void BlimpClientContextImpl::InitializeSettings() { 240 void BlimpClientContextImpl::InitializeSettings() {
224 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 241 std::unique_ptr<RecordWholeDocumentObserver> record_document_observer =
225 switches::kDownloadWholeDocument)) 242 base::MakeUnique<RecordWholeDocumentObserver>(settings_feature_.get());
226 settings_feature_->SetRecordWholeDocument(true); 243 settings_->AddObserver(std::move(record_document_observer));
244 settings_->InitializeFromCommandLineAndPref();
227 } 245 }
228 246
229 void BlimpClientContextImpl::CreateIdentitySource() { 247 void BlimpClientContextImpl::CreateIdentitySource() {
230 identity_source_ = base::MakeUnique<IdentitySource>( 248 identity_source_ = base::MakeUnique<IdentitySource>(
231 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, 249 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived,
232 base::Unretained(this))); 250 base::Unretained(this)));
233 } 251 }
234 252
235 void BlimpClientContextImpl::OnImageDecodeError() { 253 void BlimpClientContextImpl::OnImageDecodeError() {
236 // Currently we just drop the connection on image decoding error. 254 // Currently we just drop the connection on image decoding error.
237 io_thread_task_runner_->PostTask( 255 io_thread_task_runner_->PostTask(
238 FROM_HERE, 256 FROM_HERE,
239 base::Bind( 257 base::Bind(
240 &BrowserConnectionHandler::DropCurrentConnection, 258 &BrowserConnectionHandler::DropCurrentConnection,
241 base::Unretained(net_components_->GetBrowserConnectionHandler()))); 259 base::Unretained(net_components_->GetBrowserConnectionHandler())));
242 } 260 }
243 261
244 } // namespace client 262 } // namespace client
245 } // namespace blimp 263 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698