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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "chrome/browser/chromeos/drive/drive_readonly_token_fetcher.h"
6
7 #include "base/bind.h"
8 #include "base/strings/string_util.h"
9 #include "google_apis/drive/gdata_errorcode.h"
10 #include "google_apis/google_api_keys.h"
11
12 namespace drive {
13
14 DriveReadonlyTokenFetcher::DriveReadonlyTokenFetcher(
15 const std::string& account_id,
16 OAuth2TokenService* oauth2_token_service,
17 const google_apis::AuthStatusCallback& callback)
18 : OAuth2TokenService::Consumer("auth_service2" /* id */),
19 callback_(callback) {
20 DCHECK(!callback_.is_null());
21 std::vector<std::string> scopes;
22 scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
23
24 google_apis::OAuth2Client oauth2_client = google_apis::CLIENT_MAIN;
25 const std::string client_id = google_apis::GetOAuth2ClientID(oauth2_client);
26 const std::string client_secret =
27 google_apis::GetOAuth2ClientSecret(oauth2_client);
28
29 request_ = oauth2_token_service->StartRequestForClient(
30 account_id,
31 client_id,
32 client_secret,
33 OAuth2TokenService::ScopeSet(scopes.begin(), scopes.end()),
34 this);
35 }
36
37 DriveReadonlyTokenFetcher::~DriveReadonlyTokenFetcher() {
38 }
39
40 // Callback for OAuth2AccessTokenFetcher on success. |access_token| is the token
41 // used to start fetching user data.
42 void DriveReadonlyTokenFetcher::OnGetTokenSuccess(
43 const OAuth2TokenService::Request* request,
44 const std::string& access_token,
45 const base::Time& expiration_time) {
46 DCHECK(thread_checker_.CalledOnValidThread());
47
48 callback_.Run(google_apis::HTTP_SUCCESS, access_token);
49 delete this;
50 }
51
52 // Callback for OAuth2AccessTokenFetcher on failure.
53 void DriveReadonlyTokenFetcher::OnGetTokenFailure(
54 const OAuth2TokenService::Request* request,
55 const GoogleServiceAuthError& error) {
56 DCHECK(thread_checker_.CalledOnValidThread());
57
58 LOG(WARNING) << "AuthRequest: token request using refresh token failed: "
59 << error.ToString();
60
61 // There are many ways to fail, but if the failure is due to connection,
62 // it's likely that the device is off-line. We treat the error differently
63 // so that the file manager works while off-line.
64 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
65 callback_.Run(google_apis::GDATA_NO_CONNECTION, std::string());
66 } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
67 // Temporary auth error.
68 callback_.Run(google_apis::HTTP_FORBIDDEN, std::string());
69 } else {
70 // Permanent auth error.
71 callback_.Run(google_apis::HTTP_UNAUTHORIZED, std::string());
72 }
73 delete this;
74 }
75
76 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698