Chromium Code Reviews| 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 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "blimp/client/core/session/assignment_source.h" | |
| 12 | |
| 13 namespace blimp { | |
| 14 namespace client { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kDefaultAssignerUrl[] = | |
| 19 "https://blimp-pa.googleapis.com/v1/assignment"; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 AssignmentFetcher::AssignmentFetcher( | |
| 24 base::Callback<void(AssignmentRequestResult, const Assignment&)> | |
| 25 assignment_received_callback, | |
| 26 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, | |
| 27 scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner) | |
| 28 : assignment_received_callback_(assignment_received_callback), | |
| 29 io_thread_task_runner_(io_thread_task_runner), | |
| 30 file_thread_task_runner_(file_thread_task_runner) {} | |
| 31 | |
| 32 AssignmentFetcher::~AssignmentFetcher() {} | |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
= default
CJ
2016/10/13 21:19:16
Done.
| |
| 33 | |
| 34 void AssignmentFetcher::Fetch(BlimpClientContextDelegate* delegate) { | |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
Should this just take the AssignmentRequestResult
CJ
2016/10/13 21:19:16
Not sure what u mean by the errors, but otherwise
David Trainor- moved to gerrit
2016/10/14 16:38:33
So one of the main reasons we have to pass in a de
CJ
2016/10/18 00:18:32
Done.
| |
| 35 delegate_ = delegate; | |
| 36 // Start Blimp authentication flow. The OAuth2 token will be used in | |
| 37 // assignment source. | |
| 38 GetIdentitySource()->Connect(); | |
| 39 } | |
| 40 | |
| 41 IdentitySource* AssignmentFetcher::GetIdentitySource() { | |
| 42 if (!identity_source_) { | |
| 43 CreateIdentitySource(); | |
| 44 } | |
| 45 return identity_source_.get(); | |
| 46 } | |
| 47 | |
| 48 void AssignmentFetcher::CreateIdentitySource() { | |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
If we don't need a delegate we could probably just
CJ
2016/10/13 21:19:16
I am unfamiliar with doing things lazily. Would yo
David Trainor- moved to gerrit
2016/10/14 16:38:33
Sure! Want to have a quick vc at 1:30 or somethin
CJ
2016/10/18 00:18:32
Acknowledged.
| |
| 49 identity_source_ = base::MakeUnique<IdentitySource>( | |
| 50 delegate_, base::Bind(&AssignmentFetcher::OnAuthTokenReceived, | |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
If we remove the delegate dependency we could also
CJ
2016/10/13 21:19:16
Not sure what you mean. It needs the delegate to m
David Trainor- moved to gerrit
2016/10/14 16:38:33
Yeah I was hoping we could rip that whole dependen
CJ
2016/10/18 00:18:32
Done.
| |
| 51 base::Unretained(this))); | |
| 52 } | |
| 53 | |
| 54 void AssignmentFetcher::OnAuthTokenReceived( | |
| 55 const std::string& client_auth_token) { | |
| 56 if (!assignment_source_) { | |
| 57 assignment_source_.reset(new AssignmentSource( | |
| 58 GetAssignerURL(), io_thread_task_runner_, file_thread_task_runner_)); | |
| 59 } | |
| 60 | |
| 61 VLOG(1) << "Trying to get assignment."; | |
| 62 assignment_source_->GetAssignment(client_auth_token, | |
| 63 assignment_received_callback_); | |
| 64 } | |
| 65 | |
| 66 GURL AssignmentFetcher::GetAssignerURL() { | |
|
David Trainor- moved to gerrit
2016/10/13 03:52:29
This was overridden by blimp_client_context_impl_a
CJ
2016/10/13 21:19:16
Done.
| |
| 67 return GURL(kDefaultAssignerUrl); | |
| 68 } | |
| 69 | |
| 70 } // namespace client | |
| 71 } // namespace blimp | |
| OLD | NEW |