OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 virtual void Observe(int type, | 76 virtual void Observe(int type, |
77 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
78 const content::NotificationDetails& details) OVERRIDE; | 78 const content::NotificationDetails& details) OVERRIDE; |
79 | 79 |
80 // content::URLFetcherDelegate implementation: | 80 // content::URLFetcherDelegate implementation: |
81 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 81 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
82 | 82 |
83 // Used by unit-tests to override the default delay after which the translate | 83 // Used by unit-tests to override the default delay after which the translate |
84 // script is fetched again from the translation server. | 84 // script is fetched again from the translation server. |
85 void set_translate_script_expiration_delay(int delay_ms) { | 85 void set_translate_script_expiration_delay(int delay_ms) { |
86 translate_script_expiration_delay_ = delay_ms; | 86 translate_script_expiration_delay_ = |
| 87 base::TimeDelta::FromMilliseconds(delay_ms); |
87 } | 88 } |
88 | 89 |
89 // Convenience method to know if a tab is showing a translate infobar. | 90 // Convenience method to know if a tab is showing a translate infobar. |
90 static bool IsShowingTranslateInfobar(content::WebContents* tab); | 91 static bool IsShowingTranslateInfobar(content::WebContents* tab); |
91 | 92 |
92 // Returns true if the URL can be translated. | 93 // Returns true if the URL can be translated. |
93 static bool IsTranslatableURL(const GURL& url); | 94 static bool IsTranslatableURL(const GURL& url); |
94 | 95 |
95 // Fills |languages| with the list of languages that the translate server can | 96 // Fills |languages| with the list of languages that the translate server can |
96 // translate to and from. | 97 // translate to and from. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // A map that associates a profile with its parsed "accept languages". | 192 // A map that associates a profile with its parsed "accept languages". |
192 typedef std::set<std::string> LanguageSet; | 193 typedef std::set<std::string> LanguageSet; |
193 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; | 194 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; |
194 PrefServiceLanguagesMap accept_languages_; | 195 PrefServiceLanguagesMap accept_languages_; |
195 | 196 |
196 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 197 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
197 | 198 |
198 // The JS injected in the page to do the translation. | 199 // The JS injected in the page to do the translation. |
199 std::string translate_script_; | 200 std::string translate_script_; |
200 | 201 |
201 // Delay in milli-seconds after which the translate script is fetched again | 202 // Delay after which the translate script is fetched again |
202 // from the translate server. | 203 // from the translate server. |
203 int translate_script_expiration_delay_; | 204 base::TimeDelta translate_script_expiration_delay_; |
204 | 205 |
205 // Set when the translate JS is currently being retrieved. NULL otherwise. | 206 // Set when the translate JS is currently being retrieved. NULL otherwise. |
206 scoped_ptr<content::URLFetcher> translate_script_request_pending_; | 207 scoped_ptr<content::URLFetcher> translate_script_request_pending_; |
207 | 208 |
208 // Set when the list of languages is currently being retrieved. | 209 // Set when the list of languages is currently being retrieved. |
209 // NULL otherwise. | 210 // NULL otherwise. |
210 scoped_ptr<content::URLFetcher> language_list_request_pending_; | 211 scoped_ptr<content::URLFetcher> language_list_request_pending_; |
211 | 212 |
212 // The list of pending translate requests. Translate requests are queued when | 213 // The list of pending translate requests. Translate requests are queued when |
213 // the translate script is not ready and has to be fetched from the translate | 214 // the translate script is not ready and has to be fetched from the translate |
214 // server. | 215 // server. |
215 std::vector<PendingRequest> pending_requests_; | 216 std::vector<PendingRequest> pending_requests_; |
216 | 217 |
217 // The languages supported by the translation server. | 218 // The languages supported by the translation server. |
218 static base::LazyInstance<std::set<std::string> > supported_languages_; | 219 static base::LazyInstance<std::set<std::string> > supported_languages_; |
219 | 220 |
220 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 221 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
221 }; | 222 }; |
222 | 223 |
223 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 224 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |