| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
| 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/url_request/url_fetcher_delegate.h" | 10 #include "net/url_request/url_fetcher_delegate.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // Represents internal state if the fetch is completed successfully. | 22 // Represents internal state if the fetch is completed successfully. |
| 23 enum State { | 23 enum State { |
| 24 IDLE, // No fetch request was issued. | 24 IDLE, // No fetch request was issued. |
| 25 REQUESTING, // A fetch request was issued, but not finished yet. | 25 REQUESTING, // A fetch request was issued, but not finished yet. |
| 26 COMPLETED, // The last fetch request was finished successfully. | 26 COMPLETED, // The last fetch request was finished successfully. |
| 27 FAILED, // The last fetch request was finished with a failure. | 27 FAILED, // The last fetch request was finished with a failure. |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 explicit TranslateURLFetcher(int id); | 30 explicit TranslateURLFetcher(int id); |
| 31 virtual ~TranslateURLFetcher(); | 31 ~TranslateURLFetcher() override; |
| 32 | 32 |
| 33 int max_retry_on_5xx() { | 33 int max_retry_on_5xx() { |
| 34 return max_retry_on_5xx_; | 34 return max_retry_on_5xx_; |
| 35 } | 35 } |
| 36 void set_max_retry_on_5xx(int count) { | 36 void set_max_retry_on_5xx(int count) { |
| 37 max_retry_on_5xx_ = count; | 37 max_retry_on_5xx_ = count; |
| 38 } | 38 } |
| 39 | 39 |
| 40 const std::string& extra_request_header() { | 40 const std::string& extra_request_header() { |
| 41 return extra_request_header_; | 41 return extra_request_header_; |
| 42 } | 42 } |
| 43 void set_extra_request_header(const std::string& header) { | 43 void set_extra_request_header(const std::string& header) { |
| 44 extra_request_header_ = header; | 44 extra_request_header_ = header; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Requests to |url|. |callback| will be invoked when the function returns | 47 // Requests to |url|. |callback| will be invoked when the function returns |
| 48 // true, and the request is finished asynchronously. | 48 // true, and the request is finished asynchronously. |
| 49 // Returns false if the previous request is not finished, or the request | 49 // Returns false if the previous request is not finished, or the request |
| 50 // is omitted due to retry limitation. | 50 // is omitted due to retry limitation. |
| 51 bool Request(const GURL& url, const Callback& callback); | 51 bool Request(const GURL& url, const Callback& callback); |
| 52 | 52 |
| 53 // Gets internal state. | 53 // Gets internal state. |
| 54 State state() { return state_; } | 54 State state() { return state_; } |
| 55 | 55 |
| 56 // net::URLFetcherDelegate implementation: | 56 // net::URLFetcherDelegate implementation: |
| 57 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 57 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 // URL to send the request. | 60 // URL to send the request. |
| 61 GURL url_; | 61 GURL url_; |
| 62 | 62 |
| 63 // ID which is assigned to the URLFetcher. | 63 // ID which is assigned to the URLFetcher. |
| 64 const int id_; | 64 const int id_; |
| 65 | 65 |
| 66 // Internal state. | 66 // Internal state. |
| 67 enum State state_; | 67 enum State state_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 81 | 81 |
| 82 // An extra HTTP request header | 82 // An extra HTTP request header |
| 83 std::string extra_request_header_; | 83 std::string extra_request_header_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); | 85 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace translate | 88 } // namespace translate |
| 89 | 89 |
| 90 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ | 90 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
| OLD | NEW |