1 // Copyright 2014 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_GCD_BASE_API_FLOW_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_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 GCDBaseApiFlow : 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 OnGCDAPIFlowError(GCDBaseApiFlow* flow, Status status) = 0;
39 virtual void OnGCDAPIFlowComplete(GCDBaseApiFlow* flow,
40 const base::DictionaryValue* value) = 0;
42 // Return 1 if flow is for a Cloud Print device
43 virtual bool GCDIsCloudPrint() = 0;
45 virtual net::URLFetcher::RequestType GetRequestType();
47 // If there is no data, set upload_type and upload_data to ""
48 virtual void GetUploadData(std::string* upload_type,
49 std::string* upload_data);
52 // Create an OAuth2-based confirmation.
53 GCDBaseApiFlow(net::URLRequestContextGetter* request_context,
54 OAuth2TokenService* token_service,
55 const std::string& account_id,
56 const GURL& automated_claim_url,
59 // Create a cookie-based confirmation.
60 GCDBaseApiFlow(net::URLRequestContextGetter* request_context,
62 const std::string& xsrf_token,
63 const GURL& automated_claim_url,
66 // Create a cookie-based confirmation with no XSRF token (for requests that
67 // don't need an XSRF token).
68 GCDBaseApiFlow(net::URLRequestContextGetter* request_context,
70 const GURL& automated_claim_url,
73 virtual ~GCDBaseApiFlow();
77 // net::URLFetcherDelegate implementation:
78 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
80 // OAuth2TokenService::Consumer implementation:
81 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
82 const std::string& access_token,
83 const base::Time& expiration_time) OVERRIDE;
84 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
85 const GoogleServiceAuthError& error) OVERRIDE;
88 void CreateRequest(const GURL& url);
90 scoped_ptr<net::URLFetcher> url_fetcher_;
91 scoped_ptr<OAuth2TokenService::Request> oauth_request_;
92 scoped_refptr<net::URLRequestContextGetter> request_context_;
93 OAuth2TokenService* token_service_;
94 std::string account_id_;
99 } // namespace local_discovery
101 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_