| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // If you do not implement this method, you will always get a | 45 // If you do not implement this method, you will always get a |
| 46 // TOKEN_ERROR error when your token is invalid. | 46 // TOKEN_ERROR error when your token is invalid. |
| 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 |
| 55 // If this method is returns true, the data will not be parsed as JSON, and |
| 56 // |OnParsedJson| will not be called. Otherwise, |OnParsedJson| will be |
| 57 // called. |
| 58 virtual bool OnRawData(PrivetURLFetcher* fetcher, |
| 59 bool response_is_file, |
| 60 const std::string& data_string, |
| 61 const base::FilePath& data_file); |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 PrivetURLFetcher( | 64 PrivetURLFetcher( |
| 57 const std::string& token, | 65 const std::string& token, |
| 58 const GURL& url, | 66 const GURL& url, |
| 59 net::URLFetcher::RequestType request_type, | 67 net::URLFetcher::RequestType request_type, |
| 60 net::URLRequestContextGetter* request_context, | 68 net::URLRequestContextGetter* request_context, |
| 61 Delegate* delegate); | 69 Delegate* delegate); |
| 62 virtual ~PrivetURLFetcher(); | 70 virtual ~PrivetURLFetcher(); |
| 63 | 71 |
| 64 void DoNotRetryOnTransientError(); | 72 void DoNotRetryOnTransientError(); |
| 65 | 73 |
| 66 void AllowEmptyPrivetToken(); | 74 void AllowEmptyPrivetToken(); |
| 67 | 75 |
| 76 // Set the contents of the Range header. |OnRawData| must return true if this |
| 77 // is called. |
| 78 void SetByteRange(int start, int end); |
| 79 |
| 80 // Save the response to a file. |OnRawData| must return true if this is |
| 81 // called. |
| 82 void SaveResponseToFile(); |
| 83 |
| 68 void Start(); | 84 void Start(); |
| 69 | 85 |
| 70 void SetUploadData(const std::string& upload_content_type, | 86 void SetUploadData(const std::string& upload_content_type, |
| 71 const std::string& upload_data); | 87 const std::string& upload_data); |
| 72 | 88 |
| 73 void SetUploadFilePath(const std::string& upload_content_type, | 89 void SetUploadFilePath(const std::string& upload_content_type, |
| 74 const base::FilePath& upload_file_path); | 90 const base::FilePath& upload_file_path); |
| 75 | 91 |
| 76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 92 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 93 void OnURLFetchCompleteParseData(const net::URLFetcher* source); |
| 94 bool OnURLFetchCompleteDoNotParseData(const net::URLFetcher* source); |
| 77 | 95 |
| 78 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } | 96 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } |
| 79 int response_code() const { return url_fetcher_->GetResponseCode(); } | 97 int response_code() const { return url_fetcher_->GetResponseCode(); } |
| 80 | 98 |
| 81 private: | 99 private: |
| 82 void Try(); | 100 void Try(); |
| 83 void ScheduleRetry(int timeout_seconds); | 101 void ScheduleRetry(int timeout_seconds); |
| 84 bool PrivetErrorTransient(const std::string& error); | 102 bool PrivetErrorTransient(const std::string& error); |
| 85 void RequestTokenRefresh(); | 103 void RequestTokenRefresh(); |
| 86 void RefreshToken(const std::string& token); | 104 void RefreshToken(const std::string& token); |
| 87 | 105 |
| 88 std::string privet_access_token_; | 106 std::string privet_access_token_; |
| 89 GURL url_; | 107 GURL url_; |
| 90 net::URLFetcher::RequestType request_type_; | 108 net::URLFetcher::RequestType request_type_; |
| 91 scoped_refptr<net::URLRequestContextGetter> request_context_; | 109 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 92 Delegate* delegate_; | 110 Delegate* delegate_; |
| 93 | 111 |
| 94 bool do_not_retry_on_transient_error_; | 112 bool do_not_retry_on_transient_error_; |
| 95 bool allow_empty_privet_token_; | 113 bool allow_empty_privet_token_; |
| 114 bool has_byte_range_; |
| 115 bool make_response_file_; |
| 116 |
| 117 int byte_range_start_; |
| 118 int byte_range_end_; |
| 96 | 119 |
| 97 int tries_; | 120 int tries_; |
| 98 std::string upload_data_; | 121 std::string upload_data_; |
| 99 std::string upload_content_type_; | 122 std::string upload_content_type_; |
| 100 base::FilePath upload_file_path_; | 123 base::FilePath upload_file_path_; |
| 101 scoped_ptr<net::URLFetcher> url_fetcher_; | 124 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 102 | 125 |
| 103 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; | 126 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; |
| 104 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); | 127 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); |
| 105 }; | 128 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 private: | 144 private: |
| 122 scoped_refptr<net::URLRequestContextGetter> request_context_; | 145 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 123 std::string token_; | 146 std::string token_; |
| 124 | 147 |
| 125 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); | 148 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); |
| 126 }; | 149 }; |
| 127 | 150 |
| 128 } // namespace local_discovery | 151 } // namespace local_discovery |
| 129 | 152 |
| 130 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 153 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
| OLD | NEW |