| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ | |
| 6 #define GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "google_apis/gaia/oauth2_revocation_consumer.h" | |
| 13 #include "googleurl/src/gurl.h" | |
| 14 #include "net/url_request/url_fetcher_delegate.h" | |
| 15 | |
| 16 class OAuth2RevocationFetcherTest; | |
| 17 | |
| 18 namespace net { | |
| 19 class URLFetcher; | |
| 20 class URLRequestContextGetter; | |
| 21 class URLRequestStatus; | |
| 22 } | |
| 23 | |
| 24 // Abstracts the details to perform OAuth2 grant revocation. | |
| 25 // | |
| 26 // This class should be used on a single thread, but it can be whichever thread | |
| 27 // that you like. | |
| 28 // Also, do not reuse the same instance. Once Start() is called, the instance | |
| 29 // should not be reused. | |
| 30 // | |
| 31 // Usage: | |
| 32 // * Create an instance with a consumer. | |
| 33 // * Call Start() | |
| 34 // * The consumer passed in the constructor will be called on the same | |
| 35 // thread Start was called with the results. | |
| 36 // | |
| 37 // This class can handle one request at a time. To parallelize requests, | |
| 38 // create multiple instances. | |
| 39 class OAuth2RevocationFetcher : public net::URLFetcherDelegate { | |
| 40 public: | |
| 41 OAuth2RevocationFetcher(OAuth2RevocationConsumer* consumer, | |
| 42 net::URLRequestContextGetter* getter); | |
| 43 virtual ~OAuth2RevocationFetcher(); | |
| 44 | |
| 45 // Starts the flow with the given parameters. | |
| 46 // |access_token| should be an OAuth2 login scoped access token. | |
| 47 void Start(const std::string& access_token, | |
| 48 const std::string& client_id, | |
| 49 const std::string& origin); | |
| 50 | |
| 51 void CancelRequest(); | |
| 52 | |
| 53 // Implementation of net::URLFetcherDelegate | |
| 54 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 55 | |
| 56 private: | |
| 57 enum State { | |
| 58 INITIAL, | |
| 59 REVOCATION_STARTED, | |
| 60 REVOCATION_DONE, | |
| 61 ERROR_STATE, | |
| 62 }; | |
| 63 | |
| 64 // Helper methods for the flow. | |
| 65 void StartRevocation(); | |
| 66 void EndRevocation(const net::URLFetcher* source); | |
| 67 | |
| 68 // Helper mehtods for reporting back results. | |
| 69 void OnRevocationSuccess(); | |
| 70 void OnRevocationFailure(const GoogleServiceAuthError& error); | |
| 71 | |
| 72 // Other helpers. | |
| 73 static GURL MakeRevocationUrl(); | |
| 74 static std::string MakeRevocationHeader(const std::string& access_token); | |
| 75 static std::string MakeRevocationBody(const std::string& client_id, | |
| 76 const std::string& origin); | |
| 77 | |
| 78 // State that is set during construction. | |
| 79 OAuth2RevocationConsumer* const consumer_; | |
| 80 net::URLRequestContextGetter* const getter_; | |
| 81 State state_; | |
| 82 | |
| 83 // While a fetch is in progress. | |
| 84 scoped_ptr<net::URLFetcher> fetcher_; | |
| 85 std::string access_token_; | |
| 86 std::string client_id_; | |
| 87 std::string origin_; | |
| 88 | |
| 89 friend class OAuth2RevocationFetcherTest; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(OAuth2RevocationFetcher); | |
| 92 }; | |
| 93 | |
| 94 #endif // GOOGLE_APIS_GAIA_OAUTH2_REVOCATION_FETCHER_H_ | |
| OLD | NEW |