MD Downloads: tweak hazardous downloads
[chromium-blink-merge.git] / google_apis / gaia / oauth2_access_token_fetcher.h
blobcd3ee5c7ba4a7d270cbb71c009aa3e33d1ff1a50
1 // Copyright (c) 2012 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.
5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
6 #define GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
8 #include <string>
9 #include <vector>
11 #include "google_apis/gaia/oauth2_access_token_consumer.h"
12 #include "net/url_request/url_fetcher_delegate.h"
14 class OAuth2AccessTokenConsumer;
16 // Interface of a OAuth2 access token fetcher.
18 // Usage:
19 // * Create an instance with a consumer.
20 // * Call Start()
21 // * The consumer passed in the constructor will be called on the same
22 // thread Start was called with the results.
24 // This class can handle one request at a time. To parallelize requests,
25 // create multiple instances.
26 class OAuth2AccessTokenFetcher {
27 public:
28 explicit OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer);
29 virtual ~OAuth2AccessTokenFetcher();
31 // Starts the flow with the given parameters.
32 // |scopes| can be empty. If it is empty then the access token will have the
33 // same scope as the refresh token. If not empty, then access token will have
34 // the scopes specified. In this case, the access token will successfully be
35 // generated only if refresh token has login scope of a list of scopes that is
36 // a super-set of the specified scopes.
37 virtual void Start(const std::string& client_id,
38 const std::string& client_secret,
39 const std::vector<std::string>& scopes) = 0;
41 // Cancels the current request and informs the consumer.
42 virtual void CancelRequest() = 0;
44 protected:
45 // Fires |OnGetTokenSuccess| on |consumer_|.
46 void FireOnGetTokenSuccess(const std::string& access_token,
47 const base::Time& expiration_time);
49 // Fires |OnGetTokenFailure| on |consumer_|.
50 void FireOnGetTokenFailure(const GoogleServiceAuthError& error);
52 private:
53 OAuth2AccessTokenConsumer* const consumer_;
55 DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher);
58 #endif // GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_