| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( | 131 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( |
| 132 gfx::NativeWindow window) { | 132 gfx::NativeWindow window) { |
| 133 std::unique_ptr<BlimpContents> blimp_contents = | 133 std::unique_ptr<BlimpContents> blimp_contents = |
| 134 blimp_contents_manager_->CreateBlimpContents(window); | 134 blimp_contents_manager_->CreateBlimpContents(window); |
| 135 if (blimp_contents) | 135 if (blimp_contents) |
| 136 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 136 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 137 return blimp_contents; | 137 return blimp_contents; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void BlimpClientContextImpl::Connect() { | 140 void BlimpClientContextImpl::Connect() { |
| 141 // Start Blimp authentication flow. The OAuth2 token will be used in | 141 if (!assignment_fetcher_) { |
| 142 // assignment source. | 142 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( |
| 143 GetIdentitySource()->Connect(); | 143 io_thread_task_runner_, file_thread_task_runner_, |
| 144 delegate_->CreateIdentityProvider(), GetAssignerURL(), |
| 145 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, |
| 146 weak_factory_.GetWeakPtr()), |
| 147 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, |
| 148 base::Unretained(delegate_))); |
| 149 } |
| 150 assignment_fetcher_->Fetch(); |
| 144 } | 151 } |
| 145 | 152 |
| 146 void BlimpClientContextImpl::ConnectWithAssignment( | 153 void BlimpClientContextImpl::ConnectWithAssignment( |
| 147 const Assignment& assignment) { | 154 const Assignment& assignment) { |
| 148 io_thread_task_runner_->PostTask( | 155 io_thread_task_runner_->PostTask( |
| 149 FROM_HERE, | 156 FROM_HERE, |
| 150 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 157 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 151 base::Unretained(net_components_.get()), assignment)); | 158 base::Unretained(net_components_.get()), assignment)); |
| 152 } | 159 } |
| 153 | 160 |
| 154 std::unordered_map<std::string, std::string> | 161 std::unordered_map<std::string, std::string> |
| 155 BlimpClientContextImpl::CreateFeedbackData() { | 162 BlimpClientContextImpl::CreateFeedbackData() { |
| 156 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); | 163 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); |
| 157 } | 164 } |
| 158 | 165 |
| 159 void BlimpClientContextImpl::OnAuthTokenReceived( | 166 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 160 const std::string& client_auth_token) { | 167 return assignment_fetcher_->GetIdentitySource(); |
| 161 if (!assignment_source_) { | 168 } |
| 162 assignment_source_.reset(new AssignmentSource( | |
| 163 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | |
| 164 } | |
| 165 | 169 |
| 166 VLOG(1) << "Trying to get assignment."; | 170 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { |
| 167 assignment_source_->GetAssignment( | 171 return &connection_status_; |
| 168 client_auth_token, | |
| 169 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | |
| 170 weak_factory_.GetWeakPtr())); | |
| 171 } | 172 } |
| 172 | 173 |
| 173 GURL BlimpClientContextImpl::GetAssignerURL() { | 174 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 174 return GURL(kDefaultAssignerUrl); | 175 return GURL(kDefaultAssignerUrl); |
| 175 } | 176 } |
| 176 | 177 |
| 177 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | |
| 178 if (!identity_source_) { | |
| 179 CreateIdentitySource(); | |
| 180 } | |
| 181 return identity_source_.get(); | |
| 182 } | |
| 183 | |
| 184 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { | |
| 185 return &connection_status_; | |
| 186 } | |
| 187 | |
| 188 void BlimpClientContextImpl::OnAssignmentReceived( | 178 void BlimpClientContextImpl::OnAssignmentReceived( |
| 189 AssignmentRequestResult result, | 179 AssignmentRequestResult result, |
| 190 const Assignment& assignment) { | 180 const Assignment& assignment) { |
| 191 VLOG(1) << "Assignment result: " << result; | 181 VLOG(1) << "Assignment result: " << result; |
| 192 | 182 |
| 193 // Cache engine info. | 183 // Cache engine info. |
| 194 connection_status_.OnAssignmentResult(result, assignment); | 184 connection_status_.OnAssignmentResult(result, assignment); |
| 195 | 185 |
| 196 // Inform the embedder of the assignment result. | 186 // Inform the embedder of the assignment result. |
| 197 if (delegate_) { | 187 if (delegate_) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 229 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 240 switches::kDownloadWholeDocument)) | 230 switches::kDownloadWholeDocument)) |
| 241 settings_feature_->SetRecordWholeDocument(true); | 231 settings_feature_->SetRecordWholeDocument(true); |
| 242 } | 232 } |
| 243 | 233 |
| 244 void BlimpClientContextImpl::DropConnection() { | 234 void BlimpClientContextImpl::DropConnection() { |
| 245 io_thread_task_runner_->PostTask( | 235 io_thread_task_runner_->PostTask( |
| 246 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); | 236 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); |
| 247 } | 237 } |
| 248 | 238 |
| 249 void BlimpClientContextImpl::CreateIdentitySource() { | |
| 250 identity_source_ = base::MakeUnique<IdentitySource>( | |
| 251 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, | |
| 252 base::Unretained(this))); | |
| 253 } | |
| 254 | |
| 255 void BlimpClientContextImpl::OnImageDecodeError() { | 239 void BlimpClientContextImpl::OnImageDecodeError() { |
| 256 // Currently we just drop the connection on image decoding error. | 240 // Currently we just drop the connection on image decoding error. |
| 257 DropConnection(); | 241 DropConnection(); |
| 258 } | 242 } |
| 259 | 243 |
| 260 void BlimpClientContextImpl::OnConnected() { | 244 void BlimpClientContextImpl::OnConnected() { |
| 261 if (delegate_) { | 245 if (delegate_) { |
| 262 delegate_->OnConnected(); | 246 delegate_->OnConnected(); |
| 263 } | 247 } |
| 264 } | 248 } |
| 265 | 249 |
| 266 void BlimpClientContextImpl::OnDisconnected(int result) { | 250 void BlimpClientContextImpl::OnDisconnected(int result) { |
| 267 if (delegate_) { | 251 if (delegate_) { |
| 268 if (result >= 0) { | 252 if (result >= 0) { |
| 269 delegate_->OnEngineDisconnected(result); | 253 delegate_->OnEngineDisconnected(result); |
| 270 } else { | 254 } else { |
| 271 delegate_->OnNetworkDisconnected(result); | 255 delegate_->OnNetworkDisconnected(result); |
| 272 } | 256 } |
| 273 } | 257 } |
| 274 } | 258 } |
| 275 | 259 |
| 276 } // namespace client | 260 } // namespace client |
| 277 } // namespace blimp | 261 } // namespace blimp |
| OLD | NEW |