| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 delegate_ = delegate; | 74 delegate_ = delegate; |
| 75 } | 75 } |
| 76 | 76 |
| 77 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { | 77 std::unique_ptr<BlimpContents> BlimpClientContextImpl::CreateBlimpContents() { |
| 78 std::unique_ptr<BlimpContents> blimp_contents = | 78 std::unique_ptr<BlimpContents> blimp_contents = |
| 79 blimp_contents_manager_->CreateBlimpContents(); | 79 blimp_contents_manager_->CreateBlimpContents(); |
| 80 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); | 80 delegate_->AttachBlimpContentsHelpers(blimp_contents.get()); |
| 81 return blimp_contents; | 81 return blimp_contents; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void BlimpClientContextImpl::Connect(const std::string& client_auth_token) { | 84 void BlimpClientContextImpl::Connect() { |
| 85 // Lazy initialization of IdentitySource. |
| 86 if (!identity_source_) { |
| 87 identity_source_ = base::MakeUnique<IdentitySource>(delegate_); |
| 88 identity_source_->SetTokenCallback( |
| 89 base::Bind(&BlimpClientContextImpl::ConnectToAssignmentSource, |
| 90 base::Unretained(this))); |
| 91 } |
| 92 |
| 93 // Start Blimp authentication flow. The OAuth2 token will be used in |
| 94 // assignment source. |
| 95 identity_source_->Connect(); |
| 96 } |
| 97 |
| 98 void BlimpClientContextImpl::ConnectToAssignmentSource( |
| 99 const std::string& client_auth_token) { |
| 85 if (!assignment_source_) { | 100 if (!assignment_source_) { |
| 86 assignment_source_.reset(new AssignmentSource( | 101 assignment_source_.reset(new AssignmentSource( |
| 87 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | 102 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); |
| 88 } | 103 } |
| 89 | 104 |
| 90 VLOG(1) << "Trying to get assignment."; | 105 VLOG(1) << "Trying to get assignment."; |
| 91 assignment_source_->GetAssignment( | 106 assignment_source_->GetAssignment( |
| 92 client_auth_token, | 107 client_auth_token, |
| 93 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, | 108 base::Bind(&BlimpClientContextImpl::ConnectWithAssignment, |
| 94 weak_factory_.GetWeakPtr())); | 109 weak_factory_.GetWeakPtr())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 117 } | 132 } |
| 118 | 133 |
| 119 io_thread_task_runner_->PostTask( | 134 io_thread_task_runner_->PostTask( |
| 120 FROM_HERE, | 135 FROM_HERE, |
| 121 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, | 136 base::Bind(&ClientNetworkComponents::ConnectWithAssignment, |
| 122 base::Unretained(net_components_.get()), assignment)); | 137 base::Unretained(net_components_.get()), assignment)); |
| 123 } | 138 } |
| 124 | 139 |
| 125 } // namespace client | 140 } // namespace client |
| 126 } // namespace blimp | 141 } // namespace blimp |
| OLD | NEW |