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