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_TRANSLATE_TRANSLATE_URL_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_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 "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "net/url_request/url_fetcher_delegate.h" | 11 #include "net/url_request/url_fetcher_delegate.h" |
12 | 12 |
13 class TranslateURLFetcher : public net::URLFetcherDelegate { | 13 class TranslateURLFetcher : public net::URLFetcherDelegate { |
14 public: | 14 public: |
15 // Callback type for Request(). | 15 // Callback type for Request(). |
16 typedef base::Callback<void(int, bool, const std::string&)> Callback; | 16 typedef base::Callback<void(int, bool, const std::string&)> Callback; |
17 | 17 |
18 // Represents internal state if the fetch is completed successfully. | 18 // Represents internal state if the fetch is completed successfully. |
19 enum State { | 19 enum State { |
20 IDLE, // No fetch request was issued. | 20 IDLE, // No fetch request was issued. |
21 REQUESTING, // A fetch request was issued, but not finished yet. | 21 REQUESTING, // A fetch request was issued, but not finished yet. |
22 COMPLETED, // The last fetch request was finished successfully. | 22 COMPLETED, // The last fetch request was finished successfully. |
23 FAILED, // The last fetch request was finished with a failure. | 23 FAILED, // The last fetch request was finished with a failure. |
24 }; | 24 }; |
25 | 25 |
26 explicit TranslateURLFetcher(int id); | 26 explicit TranslateURLFetcher(int id); |
27 virtual ~TranslateURLFetcher(); | 27 virtual ~TranslateURLFetcher(); |
28 | 28 |
| 29 int max_retry_on_5xx() { |
| 30 return max_retry_on_5xx_; |
| 31 } |
| 32 void set_max_retry_on_5xx(int count) { |
| 33 max_retry_on_5xx_ = count; |
| 34 } |
| 35 |
| 36 const std::string& extra_request_header() { |
| 37 return extra_request_header_; |
| 38 } |
| 39 void set_extra_request_header(const std::string& header) { |
| 40 extra_request_header_ = header; |
| 41 } |
| 42 |
29 // Requests to |url|. |callback| will be invoked when the function returns | 43 // Requests to |url|. |callback| will be invoked when the function returns |
30 // true, and the request is finished asynchronously. | 44 // true, and the request is finished asynchronously. |
31 // Returns false if the previous request is not finished, or the request | 45 // Returns false if the previous request is not finished, or the request |
32 // is omitted due to retry limitation. | 46 // is omitted due to retry limitation. |
33 bool Request(const GURL& url, const Callback& callback); | 47 bool Request(const GURL& url, const Callback& callback); |
34 | 48 |
35 // Gets internal state. | 49 // Gets internal state. |
36 State state() { return state_; } | 50 State state() { return state_; } |
37 | 51 |
38 // net::URLFetcherDelegate implementation: | 52 // net::URLFetcherDelegate implementation: |
(...skipping 12 matching lines...) Expand all Loading... |
51 // URLFetcher instance. | 65 // URLFetcher instance. |
52 scoped_ptr<net::URLFetcher> fetcher_; | 66 scoped_ptr<net::URLFetcher> fetcher_; |
53 | 67 |
54 // Callback passed at Request(). It will be invoked when an asynchronous | 68 // Callback passed at Request(). It will be invoked when an asynchronous |
55 // fetch operation is finished. | 69 // fetch operation is finished. |
56 Callback callback_; | 70 Callback callback_; |
57 | 71 |
58 // Counts how many times did it try to fetch the language list. | 72 // Counts how many times did it try to fetch the language list. |
59 int retry_count_; | 73 int retry_count_; |
60 | 74 |
| 75 // Max number how many times to retry on the server error |
| 76 int max_retry_on_5xx_; |
| 77 |
| 78 // An extra HTTP request header |
| 79 std::string extra_request_header_; |
| 80 |
61 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); | 81 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); |
62 }; | 82 }; |
63 | 83 |
64 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ | 84 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ |
OLD | NEW |