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

Unified Diff: chrome/browser/chromeos/drive/drive_readonly_token_fetcher.cc

Issue 371883003: Files.app: Add an private API to get a download URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: chrome/browser/chromeos/drive/drive_readonly_token_fetcher.cc
diff --git a/chrome/browser/chromeos/drive/drive_readonly_token_fetcher.cc b/chrome/browser/chromeos/drive/drive_readonly_token_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..846d0c9e643a382b211e5a652bb5e0093b8e3a0a
--- /dev/null
+++ b/chrome/browser/chromeos/drive/drive_readonly_token_fetcher.cc
@@ -0,0 +1,76 @@
+// Copyright 2014 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 "chrome/browser/chromeos/drive/drive_readonly_token_fetcher.h"
+
+#include "base/bind.h"
+#include "base/strings/string_util.h"
+#include "google_apis/drive/gdata_errorcode.h"
+#include "google_apis/google_api_keys.h"
+
+namespace drive {
+
+DriveReadonlyTokenFetcher::DriveReadonlyTokenFetcher(
+ const std::string& account_id,
+ OAuth2TokenService* oauth2_token_service,
+ const google_apis::AuthStatusCallback& callback)
+ : OAuth2TokenService::Consumer("auth_service2" /* id */),
+ callback_(callback) {
+ DCHECK(!callback_.is_null());
+ std::vector<std::string> scopes;
+ scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
+
+ google_apis::OAuth2Client oauth2_client = google_apis::CLIENT_MAIN;
+ const std::string client_id = google_apis::GetOAuth2ClientID(oauth2_client);
+ const std::string client_secret =
+ google_apis::GetOAuth2ClientSecret(oauth2_client);
+
+ request_ = oauth2_token_service->StartRequestForClient(
+ account_id,
+ client_id,
+ client_secret,
+ OAuth2TokenService::ScopeSet(scopes.begin(), scopes.end()),
+ this);
+}
+
+DriveReadonlyTokenFetcher::~DriveReadonlyTokenFetcher() {
+}
+
+// Callback for OAuth2AccessTokenFetcher on success. |access_token| is the token
+// used to start fetching user data.
+void DriveReadonlyTokenFetcher::OnGetTokenSuccess(
+ const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ callback_.Run(google_apis::HTTP_SUCCESS, access_token);
+ delete this;
+}
+
+// Callback for OAuth2AccessTokenFetcher on failure.
+void DriveReadonlyTokenFetcher::OnGetTokenFailure(
+ const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ LOG(WARNING) << "AuthRequest: token request using refresh token failed: "
+ << error.ToString();
+
+ // There are many ways to fail, but if the failure is due to connection,
+ // it's likely that the device is off-line. We treat the error differently
+ // so that the file manager works while off-line.
+ if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
+ callback_.Run(google_apis::GDATA_NO_CONNECTION, std::string());
+ } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
+ // Temporary auth error.
+ callback_.Run(google_apis::HTTP_FORBIDDEN, std::string());
+ } else {
+ // Permanent auth error.
+ callback_.Run(google_apis::HTTP_UNAUTHORIZED, std::string());
+ }
+ delete this;
+}
+
+} // namespace drive

Powered by Google App Engine
This is Rietveld 408576698