OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:21:45
Don't use (c)
Noam Samuel
2013/07/23 00:02:42
Done.
| |
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_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | |
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "chrome/browser/local_discovery/privet_http.h" | |
11 #include "chrome/browser/signin/oauth2_token_service.h" | |
12 #include "net/url_request/url_fetcher.h" | |
13 #include "net/url_request/url_fetcher_delegate.h" | |
14 #include "net/url_request/url_request_context_getter.h" | |
15 | |
16 namespace local_discovery { | |
17 | |
18 // API call flow for server-side communication with cloudprint for registration. | |
19 class PrivetConfirmApiCallFlow : public net::URLFetcherDelegate, | |
20 public OAuth2TokenService::Consumer { | |
21 public: | |
22 // TODO(noamsml): Better error model for this class. | |
23 enum Status { | |
24 SUCCESS, | |
25 ERROR_TOKEN, | |
26 ERROR_NETWORK, | |
27 ERROR_HTTP_CODE, | |
28 ERROR_FROM_SERVER, | |
29 ERROR_MALFORMED_RESPONSE | |
30 }; | |
31 typedef base::Callback<void(Status /*success*/)> ResponseCallback; | |
32 | |
33 PrivetConfirmApiCallFlow(net::URLRequestContextGetter* request_context, | |
34 OAuth2TokenService* token_service_, | |
35 const GURL& automated_claim_url, | |
36 const ResponseCallback& callback); | |
37 virtual ~PrivetConfirmApiCallFlow(); | |
38 | |
39 void Start(); | |
40 | |
41 // net::URLFetcherDelegate implementation: | |
42 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
43 | |
44 // OAuth2TokenService::Consumer implementation: | |
45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
46 const std::string& access_token, | |
47 const base::Time& expiration_time) OVERRIDE; | |
48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
49 const GoogleServiceAuthError& error) OVERRIDE; | |
50 | |
51 private: | |
52 scoped_ptr<net::URLFetcher> url_fetcher_; | |
53 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | |
54 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
55 OAuth2TokenService* token_service_; | |
56 GURL automated_claim_url_; | |
57 ResponseCallback callback_; | |
58 }; | |
59 | |
60 } // namespace local_discovery | |
61 | |
62 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | |
OLD | NEW |