| 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 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner, |
| 21 std::unique_ptr<IdentityProvider> identity_provider, |
| 22 GURL assigner_url, |
| 23 const AssignmentResultCallback& assignment_received_callback, |
| 24 const AuthErrorCallback& error_callback) |
| 25 : identity_source_(base::MakeUnique<IdentitySource>( |
| 26 std::move(identity_provider), |
| 27 error_callback, |
| 28 base::Bind(&AssignmentFetcher::OnAuthTokenReceived, |
| 29 base::Unretained(this)))), |
| 30 assignment_received_callback_(assignment_received_callback), |
| 31 assigner_url_(assigner_url), |
| 32 io_thread_task_runner_(io_thread_task_runner), |
| 33 file_thread_task_runner_(file_thread_task_runner) {} |
| 34 |
| 35 AssignmentFetcher::~AssignmentFetcher() = default; |
| 36 |
| 37 void AssignmentFetcher::Fetch() { |
| 38 // Start Blimp authentication flow. The OAuth2 token will be used in |
| 39 // assignment source. |
| 40 identity_source_->Connect(); |
| 41 } |
| 42 |
| 43 IdentitySource* AssignmentFetcher::GetIdentitySource() { |
| 44 return identity_source_.get(); |
| 45 } |
| 46 |
| 47 void AssignmentFetcher::OnAuthTokenReceived( |
| 48 const std::string& client_auth_token) { |
| 49 if (!assignment_source_) { |
| 50 assignment_source_.reset(new AssignmentSource( |
| 51 assigner_url_, io_thread_task_runner_, file_thread_task_runner_)); |
| 52 } |
| 53 |
| 54 VLOG(1) << "Trying to get assignment."; |
| 55 assignment_source_->GetAssignment(client_auth_token, |
| 56 assignment_received_callback_); |
| 57 } |
| 58 |
| 59 } // namespace client |
| 60 } // namespace blimp |
| OLD | NEW |