| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 // and either this function or the one in | 61 // and either this function or the one in |
| 61 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 62 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 62 // any binary using BlimpClientContext::Create. | 63 // any binary using BlimpClientContext::Create. |
| 63 // static | 64 // static |
| 64 BlimpClientContext* BlimpClientContext::Create( | 65 BlimpClientContext* BlimpClientContext::Create( |
| 65 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 66 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 66 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 67 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 67 std::unique_ptr<CompositorDependencies> compositor_dependencies, | 68 std::unique_ptr<CompositorDependencies> compositor_dependencies, |
| 68 PrefService* local_state) { | 69 PrefService* local_state) { |
| 69 #if defined(OS_ANDROID) | 70 #if defined(OS_ANDROID) |
| 71 auto settings = base::MakeUnique<SettingsAndroid>(local_state); |
| 70 return new BlimpClientContextImplAndroid( | 72 return new BlimpClientContextImplAndroid( |
| 71 io_thread_task_runner, file_thread_task_runner, | 73 io_thread_task_runner, file_thread_task_runner, |
| 72 std::move(compositor_dependencies), local_state); | 74 std::move(compositor_dependencies), std::move(settings)); |
| 73 #else | 75 #else |
| 76 auto settings = base::MakeUnique<Settings>(local_state); |
| 74 return new BlimpClientContextImpl( | 77 return new BlimpClientContextImpl( |
| 75 io_thread_task_runner, file_thread_task_runner, | 78 io_thread_task_runner, file_thread_task_runner, |
| 76 std::move(compositor_dependencies), local_state); | 79 std::move(compositor_dependencies), std::move(settings)); |
| 77 #endif // defined(OS_ANDROID) | 80 #endif // defined(OS_ANDROID) |
| 78 } | 81 } |
| 79 | 82 |
| 80 // This function is declared in //blimp/client/public/blimp_client_context.h | 83 // This function is declared in //blimp/client/public/blimp_client_context.h |
| 81 // and either this function or the one in | 84 // and either this function or the one in |
| 82 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 85 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 83 // any binary using BlimpClientContext::RegisterPrefs. | 86 // any binary using BlimpClientContext::RegisterPrefs. |
| 84 // static | 87 // static |
| 85 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) { | 88 void BlimpClientContext::RegisterPrefs(PrefRegistrySimple* registry) { |
| 86 Settings::RegisterPrefs(registry); | 89 Settings::RegisterPrefs(registry); |
| 87 } | 90 } |
| 88 | 91 |
| 89 // This function is declared in //blimp/client/public/blimp_client_context.h | 92 // This function is declared in //blimp/client/public/blimp_client_context.h |
| 90 // and either this function or the one in | 93 // and either this function or the one in |
| 91 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to | 94 // //blimp/client/core/dummy_blimp_client_context.cc should be linked in to |
| 92 // any binary using BlimpClientContext::ApplyBlimpSwitches. | 95 // any binary using BlimpClientContext::ApplyBlimpSwitches. |
| 93 // static | 96 // static |
| 94 void BlimpClientContext::ApplyBlimpSwitches(CommandLinePrefStore* store) { | 97 void BlimpClientContext::ApplyBlimpSwitches(CommandLinePrefStore* store) { |
| 95 Settings::ApplyBlimpSwitches(store); | 98 Settings::ApplyBlimpSwitches(store); |
| 96 } | 99 } |
| 97 | 100 |
| 98 BlimpClientContextImpl::BlimpClientContextImpl( | 101 BlimpClientContextImpl::BlimpClientContextImpl( |
| 99 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | 102 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 100 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, | 103 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 101 std::unique_ptr<CompositorDependencies> compositor_dependencies, | 104 std::unique_ptr<CompositorDependencies> compositor_dependencies, |
| 102 PrefService* local_state) | 105 std::unique_ptr<Settings> settings) |
| 103 : BlimpClientContext(), | 106 : BlimpClientContext(), |
| 104 io_thread_task_runner_(io_thread_task_runner), | 107 io_thread_task_runner_(io_thread_task_runner), |
| 105 file_thread_task_runner_(file_thread_task_runner), | 108 file_thread_task_runner_(file_thread_task_runner), |
| 106 blimp_compositor_dependencies_( | 109 blimp_compositor_dependencies_( |
| 107 base::MakeUnique<BlimpCompositorDependencies>( | 110 base::MakeUnique<BlimpCompositorDependencies>( |
| 108 std::move(compositor_dependencies))), | 111 std::move(compositor_dependencies))), |
| 109 settings_(base::MakeUnique<Settings>(local_state)), | 112 settings_(std::move(settings)), |
| 110 blob_channel_feature_(new BlobChannelFeature(this)), | 113 blob_channel_feature_(new BlobChannelFeature(this)), |
| 111 geolocation_feature_(base::MakeUnique<GeolocationFeature>( | 114 geolocation_feature_(base::MakeUnique<GeolocationFeature>( |
| 112 base::MakeUnique<device::LocationArbitrator>( | 115 base::MakeUnique<device::LocationArbitrator>( |
| 113 base::MakeUnique<device::GeolocationDelegate>()))), | 116 base::MakeUnique<device::GeolocationDelegate>()))), |
| 114 ime_feature_(new ImeFeature), | 117 ime_feature_(new ImeFeature), |
| 115 navigation_feature_(new NavigationFeature), | 118 navigation_feature_(new NavigationFeature), |
| 116 render_widget_feature_(new RenderWidgetFeature), | 119 render_widget_feature_(new RenderWidgetFeature), |
| 117 settings_feature_(base::MakeUnique<SettingsFeature>(settings_.get())), | 120 settings_feature_(base::MakeUnique<SettingsFeature>(settings_.get())), |
| 118 tab_control_feature_(new TabControlFeature), | 121 tab_control_feature_(new TabControlFeature), |
| 119 blimp_contents_manager_( | 122 blimp_contents_manager_( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 148 | 151 |
| 149 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); | 152 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); |
| 150 } | 153 } |
| 151 | 154 |
| 152 BlimpClientContextImpl::~BlimpClientContextImpl() { | 155 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 153 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 156 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
| 154 connection_status_.RemoveObserver(this); | 157 connection_status_.RemoveObserver(this); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { | 160 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { |
| 158 DCHECK(!delegate_ || !delegate); | 161 DCHECK(!delegate_ && delegate); |
| 159 delegate_ = delegate; | 162 delegate_ = delegate; |
| 160 | 163 |
| 161 // TODO(xingliu): Pass the IdentityProvider needed by |assignment_fetcher_| | 164 // TODO(xingliu): Pass the IdentityProvider needed by |assignment_fetcher_| |
| 162 // in the constructor, see crbug/661848. | 165 // in the constructor, see crbug/661848. |
| 163 if (delegate_) { | 166 if (delegate_) { |
| 164 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( | 167 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( |
| 165 io_thread_task_runner_, file_thread_task_runner_, | 168 io_thread_task_runner_, file_thread_task_runner_, |
| 166 delegate_->CreateIdentityProvider(), GetAssignerURL(), | 169 delegate_->CreateIdentityProvider(), GetAssignerURL(), |
| 167 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | 170 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, |
| 168 weak_factory_.GetWeakPtr()), | 171 weak_factory_.GetWeakPtr()), |
| 169 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, | 172 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, |
| 170 base::Unretained(delegate_))); | 173 base::Unretained(delegate_))); |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( | 177 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( |
| 175 gfx::NativeWindow window) { | 178 gfx::NativeWindow window) { |
| 176 std::unique_ptr<BlimpContents> blimp_contents = | 179 std::unique_ptr<BlimpContents> blimp_contents = |
| 177 blimp_contents_manager_->CreateBlimpContents(window); | 180 blimp_contents_manager_->CreateBlimpContents(window); |
| 178 if (blimp_contents) | 181 if (blimp_contents) |
| 179 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 182 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 180 return blimp_contents; | 183 return blimp_contents; |
| 181 } | 184 } |
| 182 | 185 |
| 183 void BlimpClientContextImpl::Connect() { | 186 void BlimpClientContextImpl::Connect() { |
| 187 DCHECK(delegate_); |
| 184 DCHECK(assignment_fetcher_); | 188 DCHECK(assignment_fetcher_); |
| 185 assignment_fetcher_->Fetch(); | 189 assignment_fetcher_->Fetch(); |
| 186 } | 190 } |
| 187 | 191 |
| 188 void BlimpClientContextImpl::ConnectWithAssignment( | 192 void BlimpClientContextImpl::ConnectWithAssignment( |
| 189 const Assignment& assignment) { | 193 const Assignment& assignment) { |
| 190 io_thread_task_runner_->PostTask( | 194 io_thread_task_runner_->PostTask( |
| 191 FROM_HERE, | 195 FROM_HERE, |
| 192 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 196 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 193 base::Unretained(net_components_.get()), assignment)); | 197 base::Unretained(net_components_.get()), assignment)); |
| 194 } | 198 } |
| 195 | 199 |
| 196 std::unordered_map<std::string, std::string> | 200 std::unordered_map<std::string, std::string> |
| 197 BlimpClientContextImpl::CreateFeedbackData() { | 201 BlimpClientContextImpl::CreateFeedbackData() { |
| 198 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); | 202 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); |
| 199 } | 203 } |
| 200 | 204 |
| 201 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | 205 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 206 DCHECK(delegate_); |
| 202 DCHECK(assignment_fetcher_); | 207 DCHECK(assignment_fetcher_); |
| 203 return assignment_fetcher_->GetIdentitySource(); | 208 return assignment_fetcher_->GetIdentitySource(); |
| 204 } | 209 } |
| 205 | 210 |
| 206 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { | 211 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { |
| 207 return &connection_status_; | 212 return &connection_status_; |
| 208 } | 213 } |
| 209 | 214 |
| 210 GURL BlimpClientContextImpl::GetAssignerURL() { | 215 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 211 return GURL(kDefaultAssignerUrl); | 216 return GURL(kDefaultAssignerUrl); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (result >= 0) { | 287 if (result >= 0) { |
| 283 delegate_->OnEngineDisconnected(result); | 288 delegate_->OnEngineDisconnected(result); |
| 284 } else { | 289 } else { |
| 285 delegate_->OnNetworkDisconnected(result); | 290 delegate_->OnNetworkDisconnected(result); |
| 286 } | 291 } |
| 287 } | 292 } |
| 288 } | 293 } |
| 289 | 294 |
| 290 } // namespace client | 295 } // namespace client |
| 291 } // namespace blimp | 296 } // namespace blimp |
| OLD | NEW |