| 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_URL_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 virtual void OnNeedPrivetToken( | 47 virtual void OnNeedPrivetToken( |
| 48 PrivetURLFetcher* fetcher, | 48 PrivetURLFetcher* fetcher, |
| 49 const TokenCallback& callback); | 49 const TokenCallback& callback); |
| 50 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; | 50 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; |
| 51 virtual void OnParsedJson(PrivetURLFetcher* fetcher, | 51 virtual void OnParsedJson(PrivetURLFetcher* fetcher, |
| 52 const base::DictionaryValue* value, | 52 const base::DictionaryValue* value, |
| 53 bool has_error) = 0; | 53 bool has_error) = 0; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 PrivetURLFetcher( | 56 PrivetURLFetcher( |
| 57 const std::string& token, | |
| 58 const GURL& url, | 57 const GURL& url, |
| 59 net::URLFetcher::RequestType request_type, | 58 net::URLFetcher::RequestType request_type, |
| 60 net::URLRequestContextGetter* request_context, | 59 net::URLRequestContextGetter* request_context, |
| 61 Delegate* delegate); | 60 Delegate* delegate); |
| 61 |
| 62 virtual ~PrivetURLFetcher(); | 62 virtual ~PrivetURLFetcher(); |
| 63 | 63 |
| 64 static void SetTokenForHost( |
| 65 const std::string& host, |
| 66 const std::string& token); |
| 67 |
| 68 static void ResetTokenMapForTests(); |
| 69 |
| 64 void DoNotRetryOnTransientError(); | 70 void DoNotRetryOnTransientError(); |
| 65 | 71 |
| 66 void AllowEmptyPrivetToken(); | 72 void AllowEmptyPrivetToken(); |
| 67 | 73 |
| 68 void Start(); | 74 void Start(); |
| 69 | 75 |
| 70 void SetUploadData(const std::string& upload_content_type, | 76 void SetUploadData(const std::string& upload_content_type, |
| 71 const std::string& upload_data); | 77 const std::string& upload_data); |
| 72 | 78 |
| 73 void SetUploadFilePath(const std::string& upload_content_type, | 79 void SetUploadFilePath(const std::string& upload_content_type, |
| 74 const base::FilePath& upload_file_path); | 80 const base::FilePath& upload_file_path); |
| 75 | 81 |
| 76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 82 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 77 | 83 |
| 78 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } | 84 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } |
| 79 int response_code() const { return url_fetcher_->GetResponseCode(); } | 85 int response_code() const { return url_fetcher_->GetResponseCode(); } |
| 80 | 86 |
| 81 private: | 87 private: |
| 88 std::string GetHostString(); // Get string representing the host. |
| 89 std::string GetPrivetAccessToken(); |
| 82 void Try(); | 90 void Try(); |
| 83 void ScheduleRetry(int timeout_seconds); | 91 void ScheduleRetry(int timeout_seconds); |
| 84 bool PrivetErrorTransient(const std::string& error); | 92 bool PrivetErrorTransient(const std::string& error); |
| 85 void RequestTokenRefresh(); | 93 void RequestTokenRefresh(); |
| 86 void RefreshToken(const std::string& token); | 94 void RefreshToken(const std::string& token); |
| 87 | 95 |
| 88 std::string privet_access_token_; | |
| 89 GURL url_; | 96 GURL url_; |
| 90 net::URLFetcher::RequestType request_type_; | 97 net::URLFetcher::RequestType request_type_; |
| 91 scoped_refptr<net::URLRequestContextGetter> request_context_; | 98 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 92 Delegate* delegate_; | 99 Delegate* delegate_; |
| 93 | 100 |
| 94 bool do_not_retry_on_transient_error_; | 101 bool do_not_retry_on_transient_error_; |
| 95 bool allow_empty_privet_token_; | 102 bool allow_empty_privet_token_; |
| 96 | 103 |
| 97 int tries_; | 104 int tries_; |
| 98 std::string upload_data_; | 105 std::string upload_data_; |
| 99 std::string upload_content_type_; | 106 std::string upload_content_type_; |
| 100 base::FilePath upload_file_path_; | 107 base::FilePath upload_file_path_; |
| 101 scoped_ptr<net::URLFetcher> url_fetcher_; | 108 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 102 | 109 |
| 103 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; | 110 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; |
| 104 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); | 111 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); |
| 105 }; | 112 }; |
| 106 | 113 |
| 107 class PrivetURLFetcherFactory { | |
| 108 public: | |
| 109 explicit PrivetURLFetcherFactory( | |
| 110 net::URLRequestContextGetter* request_context); | |
| 111 ~PrivetURLFetcherFactory(); | |
| 112 | |
| 113 scoped_ptr<PrivetURLFetcher> CreateURLFetcher( | |
| 114 const GURL& url, | |
| 115 net::URLFetcher::RequestType request_type, | |
| 116 PrivetURLFetcher::Delegate* delegate) const; | |
| 117 | |
| 118 void set_token(const std::string& token) { token_ = token; } | |
| 119 const std::string& get_token() const { return token_; } | |
| 120 | |
| 121 private: | |
| 122 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 123 std::string token_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); | |
| 126 }; | |
| 127 | |
| 128 } // namespace local_discovery | 114 } // namespace local_discovery |
| 129 | 115 |
| 130 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 116 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
| OLD | NEW |