| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/local_discovery/privet_http.h" | 10 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h" |
| 11 #include "google_apis/gaia/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" | 11 #include "net/url_request/url_request_context_getter.h" |
| 15 | 12 |
| 13 |
| 16 namespace local_discovery { | 14 namespace local_discovery { |
| 17 | 15 |
| 18 // API call flow for server-side communication with cloudprint for registration. | 16 // API call flow for server-side communication with cloudprint for registration. |
| 19 class PrivetConfirmApiCallFlow : public net::URLFetcherDelegate, | 17 class PrivetConfirmApiCallFlow : public CloudPrintBaseApiFlow::Delegate { |
| 20 public OAuth2TokenService::Consumer { | |
| 21 public: | 18 public: |
| 22 // TODO(noamsml): Better error model for this class. | 19 typedef base::Callback<void(CloudPrintBaseApiFlow::Status /*success*/)> |
| 23 enum Status { | 20 ResponseCallback; |
| 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 | 21 |
| 33 // Create an OAuth2-based confirmation | 22 // Create an OAuth2-based confirmation |
| 34 PrivetConfirmApiCallFlow(net::URLRequestContextGetter* request_context, | 23 PrivetConfirmApiCallFlow(net::URLRequestContextGetter* request_context, |
| 35 OAuth2TokenService* token_service_, | 24 OAuth2TokenService* token_service_, |
| 36 const GURL& automated_claim_url, | 25 const GURL& automated_claim_url, |
| 37 const ResponseCallback& callback); | 26 const ResponseCallback& callback); |
| 38 | 27 |
| 39 // Create a cookie-based confirmation | 28 // Create a cookie-based confirmation |
| 40 PrivetConfirmApiCallFlow(net::URLRequestContextGetter* request_context, | 29 PrivetConfirmApiCallFlow(net::URLRequestContextGetter* request_context, |
| 41 int user_index, | 30 int user_index, |
| 42 const std::string& xsrf_token, | 31 const std::string& xsrf_token, |
| 43 const GURL& automated_claim_url, | 32 const GURL& automated_claim_url, |
| 44 const ResponseCallback& callback); | 33 const ResponseCallback& callback); |
| 45 | 34 |
| 46 virtual ~PrivetConfirmApiCallFlow(); | 35 virtual ~PrivetConfirmApiCallFlow(); |
| 47 | 36 |
| 48 void Start(); | 37 void Start(); |
| 49 | 38 |
| 50 // net::URLFetcherDelegate implementation: | 39 virtual void OnCloudPrintAPIFlowError( |
| 51 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 40 CloudPrintBaseApiFlow* flow, |
| 41 CloudPrintBaseApiFlow::Status status) OVERRIDE; |
| 42 virtual void OnCloudPrintAPIFlowComplete( |
| 43 CloudPrintBaseApiFlow* flow, |
| 44 const base::DictionaryValue* value) OVERRIDE; |
| 52 | 45 |
| 53 // OAuth2TokenService::Consumer implementation: | 46 CloudPrintBaseApiFlow* GetBaseApiFlowForTests() { |
| 54 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 47 return &flow_; |
| 55 const std::string& access_token, | 48 } |
| 56 const base::Time& expiration_time) OVERRIDE; | |
| 57 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 58 const GoogleServiceAuthError& error) OVERRIDE; | |
| 59 | 49 |
| 60 private: | 50 private: |
| 61 bool UseOAuth2() { return token_service_ != NULL; } | 51 CloudPrintBaseApiFlow flow_; |
| 62 | |
| 63 void CreateRequest(const GURL& url); | |
| 64 | |
| 65 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 66 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | |
| 67 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 68 OAuth2TokenService* token_service_; | |
| 69 int user_index_; | |
| 70 std::string xsrf_token_; | |
| 71 GURL automated_claim_url_; | |
| 72 ResponseCallback callback_; | 52 ResponseCallback callback_; |
| 73 }; | 53 }; |
| 74 | 54 |
| 75 } // namespace local_discovery | 55 } // namespace local_discovery |
| 76 | 56 |
| 77 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ | 57 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_CONFIRM_API_FLOW_H_ |
| OLD | NEW |