| 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" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 125 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 126 return blimp_contents; | 126 return blimp_contents; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void BlimpClientContextImpl::Connect() { | 129 void BlimpClientContextImpl::Connect() { |
| 130 // Start Blimp authentication flow. The OAuth2 token will be used in | 130 // Start Blimp authentication flow. The OAuth2 token will be used in |
| 131 // assignment source. | 131 // assignment source. |
| 132 GetIdentitySource()->Connect(); | 132 GetIdentitySource()->Connect(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void BlimpClientContextImpl::ConnectToAssignmentSource( | 135 void BlimpClientContextImpl::ConnectWithAssignment( |
| 136 const Assignment& assignment) { |
| 137 io_thread_task_runner_->PostTask( |
| 138 FROM_HERE, |
| 139 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 140 base::Unretained(net_components_.get()), assignment)); |
| 141 } |
| 142 |
| 143 void BlimpClientContextImpl::OnAuthTokenReceived( |
| 136 const std::string& client_auth_token) { | 144 const std::string& client_auth_token) { |
| 137 if (!assignment_source_) { | 145 if (!assignment_source_) { |
| 138 assignment_source_.reset(new AssignmentSource( | 146 assignment_source_.reset(new AssignmentSource( |
| 139 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | 147 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); |
| 140 } | 148 } |
| 141 | 149 |
| 142 VLOG(1) << "Trying to get assignment."; | 150 VLOG(1) << "Trying to get assignment."; |
| 143 assignment_source_->GetAssignment( | 151 assignment_source_->GetAssignment( |
| 144 client_auth_token, | 152 client_auth_token, |
| 145 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, | 153 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, |
| 146 weak_factory_.GetWeakPtr())); | 154 weak_factory_.GetWeakPtr())); |
| 147 } | 155 } |
| 148 | 156 |
| 149 void BlimpClientContextImpl::OnConnected() { | 157 void BlimpClientContextImpl::OnConnected() { |
| 150 UMA_HISTOGRAM_BOOLEAN("Blimp.Connected", true); | 158 UMA_HISTOGRAM_BOOLEAN("Blimp.Connected", true); |
| 151 } | 159 } |
| 152 | 160 |
| 153 void BlimpClientContextImpl::OnDisconnected(int result) { | 161 void BlimpClientContextImpl::OnDisconnected(int result) { |
| 154 UMA_HISTOGRAM_BOOLEAN("Blimp.Connected", false); | 162 UMA_HISTOGRAM_BOOLEAN("Blimp.Connected", false); |
| 155 } | 163 } |
| 156 | 164 |
| 157 GURL BlimpClientContextImpl::GetAssignerURL() { | 165 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 158 return GURL(kDefaultAssignerUrl); | 166 return GURL(kDefaultAssignerUrl); |
| 159 } | 167 } |
| 160 | 168 |
| 161 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | 169 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 162 if (!identity_source_) { | 170 if (!identity_source_) { |
| 163 CreateIdentitySource(); | 171 CreateIdentitySource(); |
| 164 } | 172 } |
| 165 return identity_source_.get(); | 173 return identity_source_.get(); |
| 166 } | 174 } |
| 167 | 175 |
| 168 void BlimpClientContextImpl::ConnectWithAssignment( | 176 void BlimpClientContextImpl::OnAssignmentReceived( |
| 169 AssignmentRequestResult result, | 177 AssignmentRequestResult result, |
| 170 const Assignment& assignment) { | 178 const Assignment& assignment) { |
| 171 VLOG(1) << "Assignment result: " << result; | 179 VLOG(1) << "Assignment result: " << result; |
| 172 | 180 |
| 173 if (delegate_) { | 181 if (delegate_) { |
| 174 delegate_->OnAssignmentConnectionAttempted(result, assignment); | 182 delegate_->OnAssignmentConnectionAttempted(result, assignment); |
| 175 } | 183 } |
| 176 | 184 |
| 177 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { | 185 if (result != ASSIGNMENT_REQUEST_RESULT_OK) { |
| 178 LOG(ERROR) << "Assignment failed, reason: " << result; | 186 LOG(ERROR) << "Assignment failed, reason: " << result; |
| 179 return; | 187 return; |
| 180 } | 188 } |
| 181 | 189 |
| 182 io_thread_task_runner_->PostTask( | 190 ConnectWithAssignment(assignment); |
| 183 FROM_HERE, | |
| 184 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | |
| 185 base::Unretained(net_components_.get()), assignment)); | |
| 186 } | 191 } |
| 187 | 192 |
| 188 void BlimpClientContextImpl::RegisterFeatures() { | 193 void BlimpClientContextImpl::RegisterFeatures() { |
| 189 // Register features' message senders and receivers. | 194 // Register features' message senders and receivers. |
| 190 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, | 195 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, |
| 191 blob_channel_feature_.get()); | 196 blob_channel_feature_.get()); |
| 192 geolocation_feature_->set_outgoing_message_processor( | 197 geolocation_feature_->set_outgoing_message_processor( |
| 193 thread_pipe_manager_->RegisterFeature(BlimpMessage::kGeolocation, | 198 thread_pipe_manager_->RegisterFeature(BlimpMessage::kGeolocation, |
| 194 geolocation_feature_.get())); | 199 geolocation_feature_.get())); |
| 195 ime_feature_->set_outgoing_message_processor( | 200 ime_feature_->set_outgoing_message_processor( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 215 } | 220 } |
| 216 | 221 |
| 217 void BlimpClientContextImpl::InitializeSettings() { | 222 void BlimpClientContextImpl::InitializeSettings() { |
| 218 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 223 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 219 switches::kDownloadWholeDocument)) | 224 switches::kDownloadWholeDocument)) |
| 220 settings_feature_->SetRecordWholeDocument(true); | 225 settings_feature_->SetRecordWholeDocument(true); |
| 221 } | 226 } |
| 222 | 227 |
| 223 void BlimpClientContextImpl::CreateIdentitySource() { | 228 void BlimpClientContextImpl::CreateIdentitySource() { |
| 224 identity_source_ = base::MakeUnique<IdentitySource>( | 229 identity_source_ = base::MakeUnique<IdentitySource>( |
| 225 delegate_, base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, | 230 delegate_, base::Bind(&BlimpClientContextImpl::OnAuthTokenReceived, |
| 226 base::Unretained(this))); | 231 base::Unretained(this))); |
| 227 } | 232 } |
| 228 | 233 |
| 229 void BlimpClientContextImpl::OnImageDecodeError() { | 234 void BlimpClientContextImpl::OnImageDecodeError() { |
| 230 // Currently we just drop the connection on image decoding error. | 235 // Currently we just drop the connection on image decoding error. |
| 231 io_thread_task_runner_->PostTask( | 236 io_thread_task_runner_->PostTask( |
| 232 FROM_HERE, | 237 FROM_HERE, |
| 233 base::Bind( | 238 base::Bind( |
| 234 &BrowserConnectionHandler::DropCurrentConnection, | 239 &BrowserConnectionHandler::DropCurrentConnection, |
| 235 base::Unretained(net_components_->GetBrowserConnectionHandler()))); | 240 base::Unretained(net_components_->GetBrowserConnectionHandler()))); |
| 236 } | 241 } |
| 237 | 242 |
| 238 } // namespace client | 243 } // namespace client |
| 239 } // namespace blimp | 244 } // namespace blimp |
| OLD | NEW |