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. 4 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_IMPL_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_IMPL_H_ 7 8 #include "chrome/browser/local_discovery/gcd_api_flow.h" 9 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher_delegate.h" 11 12 namespace local_discovery { 13 14 namespace { 15 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; 16 } 17 18 class GCDApiFlowImpl : public GCDApiFlow, 19 public net::URLFetcherDelegate, 20 public OAuth2TokenService::Consumer { 21 public: 22 // Create an OAuth2-based confirmation. 23 GCDApiFlowImpl(net::URLRequestContextGetter* request_context, 24 OAuth2TokenService* token_service, 25 const std::string& account_id); 26 27 virtual ~GCDApiFlowImpl(); 28 29 virtual void Start(scoped_ptr<Request> request) OVERRIDE; 30 31 // net::URLFetcherDelegate implementation: 32 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 33 34 // OAuth2TokenService::Consumer implementation: 35 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, 36 const std::string& access_token, 37 const base::Time& expiration_time) OVERRIDE; 38 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, 39 const GoogleServiceAuthError& error) OVERRIDE; 40 41 private: 42 void CreateRequest(const GURL& url); 43 44 scoped_ptr<net::URLFetcher> url_fetcher_; 45 scoped_ptr<OAuth2TokenService::Request> oauth_request_; 46 scoped_refptr<net::URLRequestContextGetter> request_context_; 47 OAuth2TokenService* token_service_; 48 std::string account_id_; 49 scoped_ptr<Request> request_; 50 51 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowImpl); 52 }; 53 54 } // namespace local_discovery 55 56 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_IMPL_H_ 57