1 // Copyright 2013 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 CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_
10 #include "chrome/browser/local_discovery/privet_constants.h"
11 #include "chrome/browser/local_discovery/privet_http.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
13 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "net/url_request/url_request_context_getter.h"
17 namespace local_discovery
{
19 // API call flow for communicating with cloud print.
20 class CloudPrintBaseApiFlow
: public net::URLFetcherDelegate
,
21 public OAuth2TokenService::Consumer
{
23 // TODO(noamsml): Better error model for this class.
30 ERROR_MALFORMED_RESPONSE
35 virtual ~Delegate() {}
37 virtual void OnCloudPrintAPIFlowError(CloudPrintBaseApiFlow
* flow
,
39 virtual void OnCloudPrintAPIFlowComplete(
40 CloudPrintBaseApiFlow
* flow
,
41 const base::DictionaryValue
* value
) = 0;
44 // Create an OAuth2-based confirmation.
45 CloudPrintBaseApiFlow(net::URLRequestContextGetter
* request_context
,
46 OAuth2TokenService
* token_service_
,
47 const std::string
& account_id
,
48 const GURL
& automated_claim_url
,
51 // Create a cookie-based confirmation.
52 CloudPrintBaseApiFlow(net::URLRequestContextGetter
* request_context
,
54 const std::string
& xsrf_token
,
55 const GURL
& automated_claim_url
,
58 // Create a cookie-based confirmation with no XSRF token (for requests that
59 // don't need an XSRF token).
60 CloudPrintBaseApiFlow(net::URLRequestContextGetter
* request_context
,
62 const GURL
& automated_claim_url
,
66 virtual ~CloudPrintBaseApiFlow();
71 // net::URLFetcherDelegate implementation:
72 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) OVERRIDE
;
74 // OAuth2TokenService::Consumer implementation:
75 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request
* request
,
76 const std::string
& access_token
,
77 const base::Time
& expiration_time
) OVERRIDE
;
78 virtual void OnGetTokenFailure(const OAuth2TokenService::Request
* request
,
79 const GoogleServiceAuthError
& error
) OVERRIDE
;
81 // Return the user index or kAccountIndexUseOAuth2 if none is available.
82 int user_index() { return user_index_
; }
85 bool UseOAuth2() { return user_index_
== kAccountIndexUseOAuth2
; }
87 void CreateRequest(const GURL
& url
);
89 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
90 scoped_ptr
<OAuth2TokenService::Request
> oauth_request_
;
91 scoped_refptr
<net::URLRequestContextGetter
> request_context_
;
92 OAuth2TokenService
* token_service_
;
93 std::string account_id_
;
95 std::string xsrf_token_
;
100 } // namespace local_discovery
102 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_