| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); | 142 UMA_HISTOGRAM_BOOLEAN("Blimp.Supported", true); |
| 143 } | 143 } |
| 144 | 144 |
| 145 BlimpClientContextImpl::~BlimpClientContextImpl() { | 145 BlimpClientContextImpl::~BlimpClientContextImpl() { |
| 146 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); | 146 io_thread_task_runner_->DeleteSoon(FROM_HERE, net_components_.release()); |
| 147 connection_status_.RemoveObserver(this); | 147 connection_status_.RemoveObserver(this); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { | 150 void BlimpClientContextImpl::SetDelegate(BlimpClientContextDelegate* delegate) { |
| 151 DCHECK(!delegate_ || !delegate); |
| 151 delegate_ = delegate; | 152 delegate_ = delegate; |
| 153 |
| 154 // TODO(xingliu): Pass the IdentityProvider needed by |assignment_fetcher_| |
| 155 // in the constructor, see crbug/661848. |
| 156 if (delegate_) { |
| 157 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( |
| 158 io_thread_task_runner_, file_thread_task_runner_, |
| 159 delegate_->CreateIdentityProvider(), GetAssignerURL(), |
| 160 base::Bind(&BlimpClientContextImpl::OnAssignmentReceived, |
| 161 weak_factory_.GetWeakPtr()), |
| 162 base::Bind(&BlimpClientContextDelegate::OnAuthenticationError, |
| 163 base::Unretained(delegate_))); |
| 164 } |
| 152 } | 165 } |
| 153 | 166 |
| 154 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( | 167 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents( |
| 155 gfx::NativeWindow window) { | 168 gfx::NativeWindow window) { |
| 156 std::unique_ptr<BlimpContents> blimp_contents = | 169 std::unique_ptr<BlimpContents> blimp_contents = |
| 157 blimp_contents_manager_->CreateBlimpContents(window); | 170 blimp_contents_manager_->CreateBlimpContents(window); |
| 158 if (blimp_contents) | 171 if (blimp_contents) |
| 159 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 172 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 160 return blimp_contents; | 173 return blimp_contents; |
| 161 } | 174 } |
| 162 | 175 |
| 163 void BlimpClientContextImpl::Connect() { | 176 void BlimpClientContextImpl::Connect() { |
| 164 if (!assignment_fetcher_) { | 177 DCHECK(assignment_fetcher_); |
| 165 assignment_fetcher_ = base::MakeUnique<AssignmentFetcher>( | |
| 166 io_thread_task_runner_, file_thread_task_runner_, | |
| 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(); | 178 assignment_fetcher_->Fetch(); |
| 174 } | 179 } |
| 175 | 180 |
| 176 void BlimpClientContextImpl::ConnectWithAssignment( | 181 void BlimpClientContextImpl::ConnectWithAssignment( |
| 177 const Assignment& assignment) { | 182 const Assignment& assignment) { |
| 178 io_thread_task_runner_->PostTask( | 183 io_thread_task_runner_->PostTask( |
| 179 FROM_HERE, | 184 FROM_HERE, |
| 180 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 185 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 181 base::Unretained(net_components_.get()), assignment)); | 186 base::Unretained(net_components_.get()), assignment)); |
| 182 } | 187 } |
| 183 | 188 |
| 184 std::unordered_map<std::string, std::string> | 189 std::unordered_map<std::string, std::string> |
| 185 BlimpClientContextImpl::CreateFeedbackData() { | 190 BlimpClientContextImpl::CreateFeedbackData() { |
| 186 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); | 191 return CreateBlimpFeedbackData(blimp_contents_manager_.get()); |
| 187 } | 192 } |
| 188 | 193 |
| 189 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { | 194 IdentitySource* BlimpClientContextImpl::GetIdentitySource() { |
| 195 DCHECK(assignment_fetcher_); |
| 190 return assignment_fetcher_->GetIdentitySource(); | 196 return assignment_fetcher_->GetIdentitySource(); |
| 191 } | 197 } |
| 192 | 198 |
| 193 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { | 199 ConnectionStatus* BlimpClientContextImpl::GetConnectionStatus() { |
| 194 return &connection_status_; | 200 return &connection_status_; |
| 195 } | 201 } |
| 196 | 202 |
| 197 GURL BlimpClientContextImpl::GetAssignerURL() { | 203 GURL BlimpClientContextImpl::GetAssignerURL() { |
| 198 return GURL(kDefaultAssignerUrl); | 204 return GURL(kDefaultAssignerUrl); |
| 199 } | 205 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (result >= 0) { | 275 if (result >= 0) { |
| 270 delegate_->OnEngineDisconnected(result); | 276 delegate_->OnEngineDisconnected(result); |
| 271 } else { | 277 } else { |
| 272 delegate_->OnNetworkDisconnected(result); | 278 delegate_->OnNetworkDisconnected(result); |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 } | 281 } |
| 276 | 282 |
| 277 } // namespace client | 283 } // namespace client |
| 278 } // namespace blimp | 284 } // namespace blimp |
| OLD | NEW |