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 COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
6 #define CHROME_BROWSER_TRANSLATE_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" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
| 13 class TranslateDelegate; |
| 14 |
13 class TranslateURLFetcher : public net::URLFetcherDelegate { | 15 class TranslateURLFetcher : public net::URLFetcherDelegate { |
14 public: | 16 public: |
15 // Callback type for Request(). | 17 // Callback type for Request(). |
16 typedef base::Callback<void(int, bool, const std::string&)> Callback; | 18 typedef base::Callback<void(int, bool, const std::string&)> Callback; |
17 | 19 |
18 // Represents internal state if the fetch is completed successfully. | 20 // Represents internal state if the fetch is completed successfully. |
19 enum State { | 21 enum State { |
20 IDLE, // No fetch request was issued. | 22 IDLE, // No fetch request was issued. |
21 REQUESTING, // A fetch request was issued, but not finished yet. | 23 REQUESTING, // A fetch request was issued, but not finished yet. |
22 COMPLETED, // The last fetch request was finished successfully. | 24 COMPLETED, // The last fetch request was finished successfully. |
23 FAILED, // The last fetch request was finished with a failure. | 25 FAILED, // The last fetch request was finished with a failure. |
24 }; | 26 }; |
25 | 27 |
26 explicit TranslateURLFetcher(int id); | 28 // |delegate| is expected to outlive the TranslateURLFetcher. |
| 29 explicit TranslateURLFetcher(int id, TranslateDelegate* delegate); |
27 virtual ~TranslateURLFetcher(); | 30 virtual ~TranslateURLFetcher(); |
28 | 31 |
29 int max_retry_on_5xx() { | 32 int max_retry_on_5xx() { |
30 return max_retry_on_5xx_; | 33 return max_retry_on_5xx_; |
31 } | 34 } |
32 void set_max_retry_on_5xx(int count) { | 35 void set_max_retry_on_5xx(int count) { |
33 max_retry_on_5xx_ = count; | 36 max_retry_on_5xx_ = count; |
34 } | 37 } |
35 | 38 |
36 const std::string& extra_request_header() { | 39 const std::string& extra_request_header() { |
(...skipping 15 matching lines...) Expand all Loading... |
52 // net::URLFetcherDelegate implementation: | 55 // net::URLFetcherDelegate implementation: |
53 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 56 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
54 | 57 |
55 private: | 58 private: |
56 // URL to send the request. | 59 // URL to send the request. |
57 GURL url_; | 60 GURL url_; |
58 | 61 |
59 // ID which is assigned to the URLFetcher. | 62 // ID which is assigned to the URLFetcher. |
60 const int id_; | 63 const int id_; |
61 | 64 |
| 65 // Used to get information from the embedder of Translate. |
| 66 TranslateDelegate* translate_delegate_; |
| 67 |
62 // Internal state. | 68 // Internal state. |
63 enum State state_; | 69 enum State state_; |
64 | 70 |
65 // URLFetcher instance. | 71 // URLFetcher instance. |
66 scoped_ptr<net::URLFetcher> fetcher_; | 72 scoped_ptr<net::URLFetcher> fetcher_; |
67 | 73 |
68 // Callback passed at Request(). It will be invoked when an asynchronous | 74 // Callback passed at Request(). It will be invoked when an asynchronous |
69 // fetch operation is finished. | 75 // fetch operation is finished. |
70 Callback callback_; | 76 Callback callback_; |
71 | 77 |
72 // Counts how many times did it try to fetch the language list. | 78 // Counts how many times did it try to fetch the language list. |
73 int retry_count_; | 79 int retry_count_; |
74 | 80 |
75 // Max number how many times to retry on the server error | 81 // Max number how many times to retry on the server error |
76 int max_retry_on_5xx_; | 82 int max_retry_on_5xx_; |
77 | 83 |
78 // An extra HTTP request header | 84 // An extra HTTP request header |
79 std::string extra_request_header_; | 85 std::string extra_request_header_; |
80 | 86 |
81 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); | 87 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); |
82 }; | 88 }; |
83 | 89 |
84 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ | 90 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
OLD | NEW |