OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/time.h" |
18 #include "chrome/browser/prefs/pref_change_registrar.h" | 19 #include "chrome/browser/prefs/pref_change_registrar.h" |
19 #include "chrome/common/translate_errors.h" | 20 #include "chrome/common/translate_errors.h" |
20 #include "content/public/common/url_fetcher_delegate.h" | 21 #include "content/public/common/url_fetcher_delegate.h" |
21 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
23 | 24 |
24 template <typename T> struct DefaultSingletonTraits; | 25 template <typename T> struct DefaultSingletonTraits; |
25 class GURL; | 26 class GURL; |
26 struct PageTranslatedDetails; | 27 struct PageTranslatedDetails; |
27 class PrefService; | 28 class PrefService; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 virtual void Observe(int type, | 78 virtual void Observe(int type, |
78 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
79 const content::NotificationDetails& details) OVERRIDE; | 80 const content::NotificationDetails& details) OVERRIDE; |
80 | 81 |
81 // content::URLFetcherDelegate implementation: | 82 // content::URLFetcherDelegate implementation: |
82 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 83 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
83 | 84 |
84 // Used by unit-tests to override the default delay after which the translate | 85 // Used by unit-tests to override the default delay after which the translate |
85 // script is fetched again from the translation server. | 86 // script is fetched again from the translation server. |
86 void set_translate_script_expiration_delay(int delay_ms) { | 87 void set_translate_script_expiration_delay(int delay_ms) { |
87 translate_script_expiration_delay_ = delay_ms; | 88 translate_script_expiration_delay_ = |
| 89 base::TimeDelta::FromMilliseconds(delay_ms); |
88 } | 90 } |
89 | 91 |
90 // Convenience method to know if a tab is showing a translate infobar. | 92 // Convenience method to know if a tab is showing a translate infobar. |
91 static bool IsShowingTranslateInfobar(content::WebContents* tab); | 93 static bool IsShowingTranslateInfobar(content::WebContents* tab); |
92 | 94 |
93 // Returns true if the URL can be translated. | 95 // Returns true if the URL can be translated. |
94 static bool IsTranslatableURL(const GURL& url); | 96 static bool IsTranslatableURL(const GURL& url); |
95 | 97 |
96 // Fills |languages| with the list of languages that the translate server can | 98 // Fills |languages| with the list of languages that the translate server can |
97 // translate to and from. | 99 // translate to and from. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // A map that associates a profile with its parsed "accept languages". | 196 // A map that associates a profile with its parsed "accept languages". |
195 typedef std::set<std::string> LanguageSet; | 197 typedef std::set<std::string> LanguageSet; |
196 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; | 198 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; |
197 PrefServiceLanguagesMap accept_languages_; | 199 PrefServiceLanguagesMap accept_languages_; |
198 | 200 |
199 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 201 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
200 | 202 |
201 // The JS injected in the page to do the translation. | 203 // The JS injected in the page to do the translation. |
202 std::string translate_script_; | 204 std::string translate_script_; |
203 | 205 |
204 // Delay in milli-seconds after which the translate script is fetched again | 206 // Delay after which the translate script is fetched again |
205 // from the translate server. | 207 // from the translate server. |
206 int translate_script_expiration_delay_; | 208 base::TimeDelta translate_script_expiration_delay_; |
207 | 209 |
208 // Set when the translate JS is currently being retrieved. NULL otherwise. | 210 // Set when the translate JS is currently being retrieved. NULL otherwise. |
209 scoped_ptr<content::URLFetcher> translate_script_request_pending_; | 211 scoped_ptr<content::URLFetcher> translate_script_request_pending_; |
210 | 212 |
211 // Set when the list of languages is currently being retrieved. | 213 // Set when the list of languages is currently being retrieved. |
212 // NULL otherwise. | 214 // NULL otherwise. |
213 scoped_ptr<content::URLFetcher> language_list_request_pending_; | 215 scoped_ptr<content::URLFetcher> language_list_request_pending_; |
214 | 216 |
215 // The list of pending translate requests. Translate requests are queued when | 217 // The list of pending translate requests. Translate requests are queued when |
216 // the translate script is not ready and has to be fetched from the translate | 218 // the translate script is not ready and has to be fetched from the translate |
217 // server. | 219 // server. |
218 std::vector<PendingRequest> pending_requests_; | 220 std::vector<PendingRequest> pending_requests_; |
219 | 221 |
220 // The languages supported by the translation server. | 222 // The languages supported by the translation server. |
221 static base::LazyInstance<std::set<std::string> > supported_languages_; | 223 static base::LazyInstance<std::set<std::string> > supported_languages_; |
222 | 224 |
223 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 225 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
224 }; | 226 }; |
225 | 227 |
226 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 228 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |