Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: components/translate/core/browser/translate_url_fetcher.h

Issue 145023015: Introduce TranslateService and TranslateDownloadManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 13 // Downloads raw Translate data such as the Translate script and the language
14 14 // list.
15 class TranslateURLFetcher : public net::URLFetcherDelegate { 15 class TranslateURLFetcher : public net::URLFetcherDelegate {
16 public: 16 public:
17 // Callback type for Request(). 17 // Callback type for Request().
18 typedef base::Callback<void(int, bool, const std::string&)> Callback; 18 typedef base::Callback<void(int, bool, const std::string&)> Callback;
19 19
20 // Represents internal state if the fetch is completed successfully. 20 // Represents internal state if the fetch is completed successfully.
21 enum State { 21 enum State {
22 IDLE, // No fetch request was issued. 22 IDLE, // No fetch request was issued.
23 REQUESTING, // A fetch request was issued, but not finished yet. 23 REQUESTING, // A fetch request was issued, but not finished yet.
24 COMPLETED, // The last fetch request was finished successfully. 24 COMPLETED, // The last fetch request was finished successfully.
25 FAILED, // The last fetch request was finished with a failure. 25 FAILED, // The last fetch request was finished with a failure.
26 }; 26 };
27 27
28 // |delegate| is expected to outlive the TranslateURLFetcher. 28 explicit TranslateURLFetcher(int id);
29 explicit TranslateURLFetcher(int id, TranslateDelegate* delegate);
30 virtual ~TranslateURLFetcher(); 29 virtual ~TranslateURLFetcher();
31 30
32 int max_retry_on_5xx() { 31 int max_retry_on_5xx() {
33 return max_retry_on_5xx_; 32 return max_retry_on_5xx_;
34 } 33 }
35 void set_max_retry_on_5xx(int count) { 34 void set_max_retry_on_5xx(int count) {
36 max_retry_on_5xx_ = count; 35 max_retry_on_5xx_ = count;
37 } 36 }
38 37
39 const std::string& extra_request_header() { 38 const std::string& extra_request_header() {
(...skipping 15 matching lines...) Expand all
55 // net::URLFetcherDelegate implementation: 54 // net::URLFetcherDelegate implementation:
56 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
57 56
58 private: 57 private:
59 // URL to send the request. 58 // URL to send the request.
60 GURL url_; 59 GURL url_;
61 60
62 // ID which is assigned to the URLFetcher. 61 // ID which is assigned to the URLFetcher.
63 const int id_; 62 const int id_;
64 63
65 // Used to get information from the embedder of Translate.
66 TranslateDelegate* translate_delegate_;
67
68 // Internal state. 64 // Internal state.
69 enum State state_; 65 enum State state_;
70 66
71 // URLFetcher instance. 67 // URLFetcher instance.
72 scoped_ptr<net::URLFetcher> fetcher_; 68 scoped_ptr<net::URLFetcher> fetcher_;
73 69
74 // Callback passed at Request(). It will be invoked when an asynchronous 70 // Callback passed at Request(). It will be invoked when an asynchronous
75 // fetch operation is finished. 71 // fetch operation is finished.
76 Callback callback_; 72 Callback callback_;
77 73
78 // Counts how many times did it try to fetch the language list. 74 // Counts how many times did it try to fetch the language list.
79 int retry_count_; 75 int retry_count_;
80 76
81 // Max number how many times to retry on the server error 77 // Max number how many times to retry on the server error
82 int max_retry_on_5xx_; 78 int max_retry_on_5xx_;
83 79
84 // An extra HTTP request header 80 // An extra HTTP request header
85 std::string extra_request_header_; 81 std::string extra_request_header_;
86 82
87 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher); 83 DISALLOW_COPY_AND_ASSIGN(TranslateURLFetcher);
88 }; 84 };
89 85
90 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_ 86 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_URL_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698