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

Side by Side Diff: chrome/common/net/gaia/oauth2_revocation_fetcher.h

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

Powered by Google App Engine
This is Rietveld 408576698