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

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

Issue 2463423002: Add Settings[, Oberser] java code and JNI bridge. (Closed)
Patch Set: lifetime of ObserverProxy.java and passing Settings object to BlimpClientContextImpl Created 4 years, 1 month 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/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"
(...skipping 17 matching lines...) Expand all
28 #include "blimp/client/core/switches/blimp_client_switches.h" 28 #include "blimp/client/core/switches/blimp_client_switches.h"
29 #include "blimp/client/public/blimp_client_context_delegate.h" 29 #include "blimp/client/public/blimp_client_context_delegate.h"
30 #include "blimp/client/public/compositor/compositor_dependencies.h" 30 #include "blimp/client/public/compositor/compositor_dependencies.h"
31 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
32 #include "device/geolocation/geolocation_delegate.h" 32 #include "device/geolocation/geolocation_delegate.h"
33 #include "device/geolocation/location_arbitrator.h" 33 #include "device/geolocation/location_arbitrator.h"
34 #include "ui/gfx/native_widget_types.h" 34 #include "ui/gfx/native_widget_types.h"
35 35
36 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
37 #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"
38 #include "blimp/client/core/settings/android/settings_android.h"
38 #endif // OS_ANDROID 39 #endif // OS_ANDROID
39 40
40 namespace blimp { 41 namespace blimp {
41 namespace client { 42 namespace client {
42 43
43 namespace { 44 namespace {
44 45
45 const char kDefaultAssignerUrl[] = 46 const char kDefaultAssignerUrl[] =
46 "https://blimp-pa.googleapis.com/v1/assignment"; 47 "https://blimp-pa.googleapis.com/v1/assignment";
47 48
48 void DropConnectionOnIOThread(ClientNetworkComponents* net_components) { 49 void DropConnectionOnIOThread(ClientNetworkComponents* net_components) {
49 net_components->GetBrowserConnectionHandler()->DropCurrentConnection(); 50 net_components->GetBrowserConnectionHandler()->DropCurrentConnection();
50 } 51 }
51 52
52 } // namespace 53 } // namespace
53 54
54 // This function is declared in //blimp/client/public/blimp_client_context.h, 55 // This function is declared in //blimp/client/public/blimp_client_context.h,
55 // and either this function or the one in 56 // and either this function or the one in
56 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 57 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
57 // any binary using BlimpClientContext::Create. 58 // any binary using BlimpClientContext::Create.
58 // static 59 // static
59 BlimpClientContext* BlimpClientContext::Create( 60 BlimpClientContext* BlimpClientContext::Create(
60 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 61 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
61 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 62 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
62 std::unique_ptr<CompositorDependencies> compositor_dependencies, 63 std::unique_ptr<CompositorDependencies> compositor_dependencies,
63 PrefService* local_state) { 64 PrefService* local_state) {
64 #if defined(OS_ANDROID) 65 #if defined(OS_ANDROID)
66 auto settings = base::MakeUnique<SettingsAndroid>(local_state);
David Trainor- moved to gerrit 2016/11/07 18:30:58 Maybe just inline this? I'm fine either way thoug
Menglin 2016/11/07 19:11:55 i'll just keep it this way then :)
65 return new BlimpClientContextImplAndroid( 67 return new BlimpClientContextImplAndroid(
66 io_thread_task_runner, file_thread_task_runner, 68 io_thread_task_runner, file_thread_task_runner,
67 std::move(compositor_dependencies), local_state); 69 std::move(compositor_dependencies), std::move(settings));
68 #else 70 #else
71 auto settings = base::MakeUnique<Settings>(local_state);
69 return new BlimpClientContextImpl( 72 return new BlimpClientContextImpl(
70 io_thread_task_runner, file_thread_task_runner, 73 io_thread_task_runner, file_thread_task_runner,
71 std::move(compositor_dependencies), local_state); 74 std::move(compositor_dependencies), std::move(settings));
72 #endif // defined(OS_ANDROID) 75 #endif // defined(OS_ANDROID)
73 } 76 }
74 77
75 // This function is declared in //blimp/client/public/blimp_client_context.h 78 // This function is declared in //blimp/client/public/blimp_client_context.h
76 // and either this function or the one in 79 // and either this function or the one in
77 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 80 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
78 // any binary using BlimpClientContext::RegisterPrefs. 81 // any binary using BlimpClientContext::RegisterPrefs.
79 // static 82 // static
80 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) { 83 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) {
81 Settings::RegisterPrefs(registry); 84 Settings::RegisterPrefs(registry);
82 } 85 }
83 86
84 // This function is declared in //blimp/client/public/blimp_client_context.h 87 // This function is declared in //blimp/client/public/blimp_client_context.h
85 // and either this function or the one in 88 // and either this function or the one in
86 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to 89 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to
87 // any binary using BlimpClientContext::ApplyBlimpSwitches. 90 // any binary using BlimpClientContext::ApplyBlimpSwitches.
88 // static 91 // static
89 void BlimpClientContext::ApplyBlimpSwitches(CommandLinePrefStore* store) { 92 void BlimpClientContext::ApplyBlimpSwitches(CommandLinePrefStore* store) {
90 Settings::ApplyBlimpSwitches(store); 93 Settings::ApplyBlimpSwitches(store);
91 } 94 }
92 95
93 BlimpClientContextImpl::BlimpClientContextImpl( 96 BlimpClientContextImpl::BlimpClientContextImpl(
94 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, 97 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
95 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, 98 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner,
96 std::unique_ptr<CompositorDependencies> compositor_dependencies, 99 std::unique_ptr<CompositorDependencies> compositor_dependencies,
97 PrefService* local_state) 100 std::unique_ptr<Settings> settings)
98 : BlimpClientContext(), 101 : BlimpClientContext(),
99 io_thread_task_runner_(io_thread_task_runner), 102 io_thread_task_runner_(io_thread_task_runner),
100 file_thread_task_runner_(file_thread_task_runner), 103 file_thread_task_runner_(file_thread_task_runner),
101 blimp_compositor_dependencies_( 104 blimp_compositor_dependencies_(
102 base::MakeUnique<BlimpCompositorDependencies>( 105 base::MakeUnique<BlimpCompositorDependencies>(
103 std::move(compositor_dependencies))), 106 std::move(compositor_dependencies))),
104 settings_(base::MakeUnique<Settings>(local_state)), 107 settings_(std::move(settings)),
105 blob_channel_feature_(new BlobChannelFeature(this)), 108 blob_channel_feature_(new BlobChannelFeature(this)),
106 geolocation_feature_(base::MakeUnique<GeolocationFeature>( 109 geolocation_feature_(base::MakeUnique<GeolocationFeature>(
107 base::MakeUnique<device::LocationArbitrator>( 110 base::MakeUnique<device::LocationArbitrator>(
108 base::MakeUnique<device::GeolocationDelegate>()))), 111 base::MakeUnique<device::GeolocationDelegate>()))),
109 ime_feature_(new ImeFeature), 112 ime_feature_(new ImeFeature),
110 navigation_feature_(new NavigationFeature), 113 navigation_feature_(new NavigationFeature),
111 render_widget_feature_(new RenderWidgetFeature), 114 render_widget_feature_(new RenderWidgetFeature),
112 settings_feature_(base::MakeUnique<SettingsFeature>(settings_.get())), 115 settings_feature_(base::MakeUnique<SettingsFeature>(settings_.get())),
113 tab_control_feature_(new TabControlFeature), 116 tab_control_feature_(new TabControlFeature),
114 blimp_contents_manager_( 117 blimp_contents_manager_(
(...skipping 26 matching lines...) Expand all
141 144
142 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); 145 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true);
143 } 146 }
144 147
145 BlimpClientContextImpl::~BlimpClientContextImpl() { 148 BlimpClientContextImpl::~BlimpClientContextImpl() {
146 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); 149 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release());
147 connection_status_.RemoveObserver(this); 150 connection_status_.RemoveObserver(this);
148 } 151 }
149 152
150 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { 153 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) {
151 DCHECK(!delegate_ || !delegate); 154 DCHECK(!delegate_ || !delegate);
David Trainor- moved to gerrit 2016/11/07 18:30:58 Do we support clearing the delegate? I might just
Menglin 2016/11/07 19:11:55 No currently we don't support clearing the delegat
Khushal 2016/11/09 01:15:39 We do clear the delegate, https://cs.chromium.org/
152 delegate_ = delegate; 155 delegate_ = delegate;
153 156
154 // TODO(xingliu): Pass the IdentityProvider needed by |assignment_fetcher_| 157 // TODO(xingliu): Pass the IdentityProvider needed by |assignment_fetcher_|
155 // in the constructor, see crbug/661848. 158 // in the constructor, see crbug/661848.
156 if (delegate_) { 159 if (delegate_) {
157 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( 160 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>(
158 io_thread_task_runner_, file_thread_task_runner_, 161 io_thread_task_runner_, file_thread_task_runner_,
159 delegate_->CreateIdentityProvider(), GetAssignerURL(), 162 delegate_->CreateIdentityProvider(), GetAssignerURL(),
160 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, 163 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived,
161 weak_factory_.GetWeakPtr()), 164 weak_factory_.GetWeakPtr()),
162 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, 165 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError,
163 base::Unretained(delegate_))); 166 base::Unretained(delegate_)));
164 } 167 }
165 } 168 }
166 169
167 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( 170 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents(
168 gfx::NativeWindow window) { 171 gfx::NativeWindow window) {
169 std::unique_ptr<BlimpContents> blimp_contents = 172 std::unique_ptr<BlimpContents> blimp_contents =
170 blimp_contents_manager_->CreateBlimpContents(window); 173 blimp_contents_manager_->CreateBlimpContents(window);
171 if (blimp_contents) 174 if (blimp_contents)
172 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); 175 delegate_->AttachBlimpContentsHelpers(blimp_contents.get());
173 return blimp_contents; 176 return blimp_contents;
174 } 177 }
175 178
176 void BlimpClientContextImpl::Connect() { 179 void BlimpClientContextImpl::Connect() {
177 DCHECK(assignment_fetcher_); 180 DCHECK(assignment_fetcher_);
David Trainor- moved to gerrit 2016/11/07 18:30:58 << "Make sure SetDelegate is called with a valid d
Menglin 2016/11/07 19:11:55 in BlimpClientContextImpl::SetDelegate (line 159),
David Trainor- moved to gerrit 2016/11/08 00:14:49 That should be fine, the error message just makes
Menglin 2016/11/08 05:03:23 ok
178 assignment_fetcher_->Fetch(); 181 assignment_fetcher_->Fetch();
179 } 182 }
180 183
181 void BlimpClientContextImpl::ConnectWithAssignment( 184 void BlimpClientContextImpl::ConnectWithAssignment(
182 const Assignment& assignment) { 185 const Assignment& assignment) {
183 io_thread_task_runner_->PostTask( 186 io_thread_task_runner_->PostTask(
184 FROM_HERE, 187 FROM_HERE,
185 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, 188 base::Bind(&ClientNetworkComponents::ConnectWithAssignment,
186 base::Unretained(net_components_.get()), assignment)); 189 base::Unretained(net_components_.get()), assignment));
187 } 190 }
188 191
189 std::unordered_map<std::string, std::string> 192 std::unordered_map<std::string, std::string>
190 BlimpClientContextImpl::CreateFeedbackData() { 193 BlimpClientContextImpl::CreateFeedbackData() {
191 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); 194 return CreateBlimpFeedbackData(blimp_contents_manager_.get());
192 } 195 }
193 196
194 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { 197 IdentitySource* BlimpClientContextImpl::GetIdentitySource() {
195 DCHECK(assignment_fetcher_); 198 DCHECK(assignment_fetcher_);
David Trainor- moved to gerrit 2016/11/07 18:30:58 << "Make sure SetDelegate is called with a valid d
Menglin 2016/11/07 19:11:55 same as the above?
Menglin 2016/11/08 05:03:23 Done.
196 return assignment_fetcher_->GetIdentitySource(); 199 return assignment_fetcher_->GetIdentitySource();
197 } 200 }
198 201
199 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { 202 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() {
200 return &connection_status_; 203 return &connection_status_;
201 } 204 }
202 205
203 GURL BlimpClientContextImpl::GetAssignerURL() { 206 GURL BlimpClientContextImpl::GetAssignerURL() {
204 return GURL(kDefaultAssignerUrl); 207 return GURL(kDefaultAssignerUrl);
205 } 208 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (result >= 0) { 278 if (result >= 0) {
276 delegate_->OnEngineDisconnected(result); 279 delegate_->OnEngineDisconnected(result);
277 } else { 280 } else {
278 delegate_->OnNetworkDisconnected(result); 281 delegate_->OnNetworkDisconnected(result);
279 } 282 }
280 } 283 }
281 } 284 }
282 285
283 } // namespace client 286 } // namespace client
284 } // namespace blimp 287 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698