Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1365)

Unified Diff: blimp/client/core/context/assignment_fetcher.cc

Issue 2406403003: Clean up Assignment Create in BlimpClientContextImpl. (Closed)
Patch Set: Moves GetGURL up to protected. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/client/core/context/assignment_fetcher.cc
diff --git a/blimp/client/core/context/assignment_fetcher.cc b/blimp/client/core/context/assignment_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..930b467150a476fc3ab7a2bb9b928a0fe28e6bae
--- /dev/null
+++ b/blimp/client/core/context/assignment_fetcher.cc
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/client/core/context/assignment_fetcher.h"
+
+#include <string>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "blimp/client/core/session/assignment_source.h"
+#include "blimp/client/core/session/identity_source.h"
+
+namespace blimp {
+namespace client {
+
+AssignmentFetcher::AssignmentFetcher(
+ std::unique_ptr<IdentityProvider> identity_provider,
+ const base::Callback<void(const GoogleServiceAuthError&)> error_callback,
+ GURL assigner_url,
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> file_thread_task_runner)
+ : identity_source_(base::MakeUnique<IdentitySource>(
+ std::move(identity_provider),
+ error_callback,
+ base::Bind(&AssignmentFetcher::OnAuthTokenReceived,
+ base::Unretained(this)))),
+ assigner_url_(assigner_url),
+ io_thread_task_runner_(io_thread_task_runner),
+ file_thread_task_runner_(file_thread_task_runner) {}
+
+AssignmentFetcher::~AssignmentFetcher() = default;
+
+void AssignmentFetcher::Fetch(
+ base::Callback<void(AssignmentRequestResult, const Assignment&)>
+ assignment_received_callback) {
+ assignment_received_callback_ = assignment_received_callback;
+ // Start Blimp authentication flow. The OAuth2 token will be used in
+ // assignment source.
+ identity_source_->Connect();
+}
+
+IdentitySource* AssignmentFetcher::GetIdentitySource() {
+ return identity_source_.get();
+}
+
+void AssignmentFetcher::OnAuthTokenReceived(
+ const std::string& client_auth_token) {
+ if (!assignment_source_) {
+ assignment_source_.reset(new AssignmentSource(
+ assigner_url_, io_thread_task_runner_, file_thread_task_runner_));
+ }
+
+ VLOG(1) << "Trying to get assignment.";
+ assignment_source_->GetAssignment(client_auth_token,
+ assignment_received_callback_);
+}
+
+} // namespace client
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698