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 explicit TranslateURLFetcher(int id, TranslateDelegate* delegate); |
blundell
2014/01/09 12:14:17
Document lifetime assumption of the passed-in poin
| |
27 virtual ~TranslateURLFetcher(); | 29 virtual ~TranslateURLFetcher(); |
28 | 30 |
29 int max_retry_on_5xx() { | 31 int max_retry_on_5xx() { |
30 return max_retry_on_5xx_; | 32 return max_retry_on_5xx_; |
31 } | 33 } |
32 void set_max_retry_on_5xx(int count) { | 34 void set_max_retry_on_5xx(int count) { |
33 max_retry_on_5xx_ = count; | 35 max_retry_on_5xx_ = count; |
34 } | 36 } |
35 | 37 |
36 const std::string& extra_request_header() { | 38 const std::string& extra_request_header() { |
(...skipping 15 matching lines...) Expand all Loading... | |
52 // net::URLFetcherDelegate implementation: | 54 // net::URLFetcherDelegate implementation: |
53 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
54 | 56 |
55 private: | 57 private: |
56 // URL to send the request. | 58 // URL to send the request. |
57 GURL url_; | 59 GURL url_; |
58 | 60 |
59 // ID which is assigned to the URLFetcher. | 61 // ID which is assigned to the URLFetcher. |
60 const int id_; | 62 const int id_; |
61 | 63 |
64 TranslateDelegate* translate_delegate_; | |
blundell
2014/01/09 12:14:17
Needs a comment.
| |
65 | |
62 // Internal state. | 66 // Internal state. |
63 enum State state_; | 67 enum State state_; |
64 | 68 |
65 // URLFetcher instance. | 69 // URLFetcher instance. |
66 scoped_ptr<net::URLFetcher> fetcher_; | 70 scoped_ptr<net::URLFetcher> fetcher_; |
67 | 71 |
68 // Callback passed at Request(). It will be invoked when an asynchronous | 72 // Callback passed at Request(). It will be invoked when an asynchronous |
69 // fetch operation is finished. | 73 // fetch operation is finished. |
70 Callback callback_; | 74 Callback callback_; |
71 | 75 |
72 // Counts how many times did it try to fetch the language list. | 76 // Counts how many times did it try to fetch the language list. |
73 int retry_count_; | 77 int retry_count_; |
74 | 78 |
75 // Max number how many times to retry on the server error | 79 // Max number how many times to retry on the server error |
76 int max_retry_on_5xx_; | 80 int max_retry_on_5xx_; |
77 | 81 |
78 // An extra HTTP request header | 82 // An extra HTTP request header |
79 std::string extra_request_header_; | 83 std::string extra_request_header_; |
80 | 84 |
81 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); | 85 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); |
82 }; | 86 }; |
83 | 87 |
84 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_URL_FETCHER_H_ | 88 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ |
OLD | NEW |