| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/client/core/context/assignment_fetcher.h" |
| 6 |
| 7 #include <string> |
| 8 #include <utility> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "blimp/client/core/session/assignment_source.h" |
| 13 #include "blimp/client/core/session/identity_source.h" |
| 14 |
| 15 namespace blimp { |
| 16 namespace client { |
| 17 |
| 18 AssignmentFetcher::AssignmentFetcher( |
| 19 std::unique_ptr<IdentityProvider> identity_provider, |
| 20 const base::Callback<void(const GoogleServiceAuthError&)> error_callback, |
| 21 GURL assigner_url, |
| 22 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 23 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) |
| 24 : identity_source_(base::MakeUnique<IdentitySource>( |
| 25 std::move(identity_provider), |
| 26 error_callback, |
| 27 base::Bind(&AssignmentFetcher::OnAuthTokenReceived, |
| 28 base::Unretained(this)))), |
| 29 assigner_url_(assigner_url), |
| 30 io_thread_task_runner_(io_thread_task_runner), |
| 31 file_thread_task_runner_(file_thread_task_runner) {} |
| 32 |
| 33 AssignmentFetcher::~AssignmentFetcher() = default; |
| 34 |
| 35 void AssignmentFetcher::Fetch( |
| 36 base::Callback<void(AssignmentRequestResult, const Assignment&)> |
| 37 assignment_received_callback) { |
| 38 assignment_received_callback_ = assignment_received_callback; |
| 39 // Start Blimp authentication flow. The OAuth2 token will be used in |
| 40 // assignment source. |
| 41 identity_source_->Connect(); |
| 42 } |
| 43 |
| 44 IdentitySource* AssignmentFetcher::GetIdentitySource() { |
| 45 return identity_source_.get(); |
| 46 } |
| 47 |
| 48 void AssignmentFetcher::OnAuthTokenReceived( |
| 49 const std::string& client_auth_token) { |
| 50 if (!assignment_source_) { |
| 51 assignment_source_.reset(new AssignmentSource( |
| 52 assigner_url_, io_thread_task_runner_, file_thread_task_runner_)); |
| 53 } |
| 54 |
| 55 VLOG(1) << "Trying to get assignment."; |
| 56 assignment_source_->GetAssignment(client_auth_token, |
| 57 assignment_received_callback_); |
| 58 } |
| 59 |
| 60 } // namespace client |
| 61 } // namespace blimp |
| OLD | NEW |