Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( | 154 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( |
| 155 gfx::NativeWindow window) { | 155 gfx::NativeWindow window) { |
| 156 std::unique_ptr<BlimpContents> blimp_contents = | 156 std::unique_ptr<BlimpContents> blimp_contents = |
| 157 blimp_contents_manager_->CreateBlimpContents(window); | 157 blimp_contents_manager_->CreateBlimpContents(window); |
| 158 if (blimp_contents) | 158 if (blimp_contents) |
| 159 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 159 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 160 return blimp_contents; | 160 return blimp_contents; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void BlimpClientContextImpl::Connect() { | 163 void BlimpClientContextImpl::Connect() { |
| 164 if (!assignment_fetcher_) { | 164 if (!assignment_fetcher_) |
| 165 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( | 165 CreateAssignmentFetcher(); |
| 166 io_thread_task_runner_, file_thread_task_runner_, | 166 |
| 167 delegate_->CreateIdentityProvider(), GetAssignerURL(), | |
| 168 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | |
| 169 weak_factory_.GetWeakPtr()), | |
| 170 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, | |
| 171 base::Unretained(delegate_))); | |
| 172 } | |
| 173 assignment_fetcher_->Fetch(); | 167 assignment_fetcher_->Fetch(); |
| 174 } | 168 } |
| 175 | 169 |
| 176 void BlimpClientContextImpl::ConnectWithAssignment( | 170 void BlimpClientContextImpl::ConnectWithAssignment( |
| 177 const Assignment& assignment) { | 171 const Assignment& assignment) { |
| 178 io_thread_task_runner_->PostTask( | 172 io_thread_task_runner_->PostTask( |
| 179 FROM_HERE, | 173 FROM_HERE, |
| 180 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 174 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 181 base::Unretained(net_components_.get()), assignment)); | 175 base::Unretained(net_components_.get()), assignment)); |
| 182 } | 176 } |
| 183 | 177 |
| 184 std::unordered_map<std::string, std::string> | 178 std::unordered_map<std::string, std::string> |
| 185 BlimpClientContextImpl::CreateFeedbackData() { | 179 BlimpClientContextImpl::CreateFeedbackData() { |
| 186 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); | 180 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); |
| 187 } | 181 } |
| 188 | 182 |
| 189 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | 183 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 184 if (!assignment_fetcher_) | |
| 185 CreateAssignmentFetcher(); | |
| 186 | |
| 190 return assignment_fetcher_->GetIdentitySource(); | 187 return assignment_fetcher_->GetIdentitySource(); |
| 191 } | 188 } |
| 192 | 189 |
| 193 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { | 190 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { |
| 194 return &connection_status_; | 191 return &connection_status_; |
| 195 } | 192 } |
| 196 | 193 |
| 197 GURL BlimpClientContextImpl::GetAssignerURL() { | 194 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 198 return GURL(kDefaultAssignerUrl); | 195 return GURL(kDefaultAssignerUrl); |
| 199 } | 196 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 tab_control_feature_->set_outgoing_message_processor( | 243 tab_control_feature_->set_outgoing_message_processor( |
| 247 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, | 244 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, |
| 248 tab_control_feature_.get())); | 245 tab_control_feature_.get())); |
| 249 } | 246 } |
| 250 | 247 |
| 251 void BlimpClientContextImpl::DropConnection() { | 248 void BlimpClientContextImpl::DropConnection() { |
| 252 io_thread_task_runner_->PostTask( | 249 io_thread_task_runner_->PostTask( |
| 253 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); | 250 FROM_HERE, base::Bind(&DropConnectionOnIOThread, net_components_.get())); |
| 254 } | 251 } |
| 255 | 252 |
| 253 void BlimpClientContextImpl::CreateAssignmentFetcher() { | |
| 254 if (assignment_fetcher_) | |
|
Khushal
2016/11/02 23:45:45
nit: Why do the if check at the call sites if you'
| |
| 255 return; | |
| 256 | |
| 257 // |assignment_fetcher_| needs services from BlimpClientContextDelegate, so | |
| 258 // it can't be created in the constructor. | |
| 259 DCHECK(delegate_); | |
| 260 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( | |
|
Khushal
2016/11/02 21:29:56
Can we create this in SetDelegate instead then? Ra
xingliu
2016/11/02 23:26:52
@nyquist, I think do it in SetDelegate makes sense
Khushal
2016/11/02 23:45:45
Definitely can't do without a |delegate_|, you nee
xingliu
2016/11/03 00:08:04
Yeah, agree.
Put it into SetDelegate. Since the de
| |
| 261 io_thread_task_runner_, file_thread_task_runner_, | |
| 262 delegate_->CreateIdentityProvider(), GetAssignerURL(), | |
| 263 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, | |
| 264 weak_factory_.GetWeakPtr()), | |
| 265 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, | |
| 266 base::Unretained(delegate_))); | |
| 267 } | |
| 268 | |
| 256 void BlimpClientContextImpl::OnImageDecodeError() { | 269 void BlimpClientContextImpl::OnImageDecodeError() { |
| 257 // Currently we just drop the connection on image decoding error. | 270 // Currently we just drop the connection on image decoding error. |
| 258 DropConnection(); | 271 DropConnection(); |
| 259 } | 272 } |
| 260 | 273 |
| 261 void BlimpClientContextImpl::OnConnected() { | 274 void BlimpClientContextImpl::OnConnected() { |
| 262 if (delegate_) { | 275 if (delegate_) { |
| 263 delegate_->OnConnected(); | 276 delegate_->OnConnected(); |
| 264 } | 277 } |
| 265 } | 278 } |
| 266 | 279 |
| 267 void BlimpClientContextImpl::OnDisconnected(int result) { | 280 void BlimpClientContextImpl::OnDisconnected(int result) { |
| 268 if (delegate_) { | 281 if (delegate_) { |
| 269 if (result >= 0) { | 282 if (result >= 0) { |
| 270 delegate_->OnEngineDisconnected(result); | 283 delegate_->OnEngineDisconnected(result); |
| 271 } else { | 284 } else { |
| 272 delegate_->OnNetworkDisconnected(result); | 285 delegate_->OnNetworkDisconnected(result); |
| 273 } | 286 } |
| 274 } | 287 } |
| 275 } | 288 } |
| 276 | 289 |
| 277 } // namespace client | 290 } // namespace client |
| 278 } // namespace blimp | 291 } // namespace blimp |
| OLD | NEW |