OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // Reverts the contents of the page in |tab_contents| to its original | 44 // Reverts the contents of the page in |tab_contents| to its original |
45 // language. | 45 // language. |
46 void RevertTranslation(TabContents* tab_contents); | 46 void RevertTranslation(TabContents* tab_contents); |
47 | 47 |
48 // Reports to the Google translate server that a page language was incorrectly | 48 // Reports to the Google translate server that a page language was incorrectly |
49 // detected. This call is initiated by the user selecting the "report" menu | 49 // detected. This call is initiated by the user selecting the "report" menu |
50 // under options in the translate infobar. | 50 // under options in the translate infobar. |
51 void ReportLanguageDetectionError(TabContents* tab_contents); | 51 void ReportLanguageDetectionError(TabContents* tab_contents); |
52 | 52 |
53 // Clears the translate script, so it will be fetched next time we translate. | 53 // Clears the translate script, so it will be fetched next time we translate. |
54 // Currently used by unit-tests. | |
55 void ClearTranslateScript() { translate_script_.clear(); } | 54 void ClearTranslateScript() { translate_script_.clear(); } |
56 | 55 |
57 // NotificationObserver implementation: | 56 // NotificationObserver implementation: |
58 virtual void Observe(NotificationType type, | 57 virtual void Observe(NotificationType type, |
59 const NotificationSource& source, | 58 const NotificationSource& source, |
60 const NotificationDetails& details); | 59 const NotificationDetails& details); |
61 | 60 |
62 // URLFetcher::Delegate implementation: | 61 // URLFetcher::Delegate implementation: |
63 virtual void OnURLFetchComplete(const URLFetcher* source, | 62 virtual void OnURLFetchComplete(const URLFetcher* source, |
64 const GURL& url, | 63 const GURL& url, |
65 const URLRequestStatus& status, | 64 const URLRequestStatus& status, |
66 int response_code, | 65 int response_code, |
67 const ResponseCookies& cookies, | 66 const ResponseCookies& cookies, |
68 const std::string& data); | 67 const std::string& data); |
69 | 68 |
| 69 // Used by unit-tests to override the default delay after which the translate |
| 70 // script is fetched again from the translation server. |
| 71 void set_translate_script_expiration_delay(int delay_ms) { |
| 72 translate_script_expiration_delay_ = delay_ms; |
| 73 } |
| 74 |
70 // Convenience method to know if a tab is showing a translate infobar. | 75 // Convenience method to know if a tab is showing a translate infobar. |
71 static bool IsShowingTranslateInfobar(TabContents* tab); | 76 static bool IsShowingTranslateInfobar(TabContents* tab); |
72 | 77 |
73 // Returns true if the URL can be translated, if it is not an internal URL | 78 // Returns true if the URL can be translated, if it is not an internal URL |
74 // (chrome:// and others). | 79 // (chrome:// and others). |
75 static bool IsTranslatableURL(const GURL& url); | 80 static bool IsTranslatableURL(const GURL& url); |
76 | 81 |
77 // Fills |languages| with the list of languages that the translate server can | 82 // Fills |languages| with the list of languages that the translate server can |
78 // translate to and from. | 83 // translate to and from. |
79 static void GetSupportedLanguages(std::vector<std::string>* languages); | 84 static void GetSupportedLanguages(std::vector<std::string>* languages); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // A map that associates a profile with its parsed "accept languages". | 156 // A map that associates a profile with its parsed "accept languages". |
152 typedef std::set<std::string> LanguageSet; | 157 typedef std::set<std::string> LanguageSet; |
153 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; | 158 typedef std::map<PrefService*, LanguageSet> PrefServiceLanguagesMap; |
154 PrefServiceLanguagesMap accept_languages_; | 159 PrefServiceLanguagesMap accept_languages_; |
155 | 160 |
156 ScopedRunnableMethodFactory<TranslateManager> method_factory_; | 161 ScopedRunnableMethodFactory<TranslateManager> method_factory_; |
157 | 162 |
158 // The JS injected in the page to do the translation. | 163 // The JS injected in the page to do the translation. |
159 std::string translate_script_; | 164 std::string translate_script_; |
160 | 165 |
| 166 // Delay in milli-seconds after which the translate script is fetched again |
| 167 // from the translate server. |
| 168 int translate_script_expiration_delay_; |
| 169 |
161 // Whether the translate JS is currently being retrieved. | 170 // Whether the translate JS is currently being retrieved. |
162 bool translate_script_request_pending_; | 171 bool translate_script_request_pending_; |
163 | 172 |
164 // The list of pending translate requests. Translate requests are queued when | 173 // The list of pending translate requests. Translate requests are queued when |
165 // the translate script is not ready and has to be fetched from the translate | 174 // the translate script is not ready and has to be fetched from the translate |
166 // server. | 175 // server. |
167 std::vector<PendingRequest> pending_requests_; | 176 std::vector<PendingRequest> pending_requests_; |
168 | 177 |
169 // The languages supported by the translation server. | 178 // The languages supported by the translation server. |
170 static base::LazyInstance<std::set<std::string> > supported_languages_; | 179 static base::LazyInstance<std::set<std::string> > supported_languages_; |
171 | 180 |
172 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 181 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
173 }; | 182 }; |
174 | 183 |
175 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 184 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |