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> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/scoped_ptr.h" |
15 #include "base/task.h" | 16 #include "base/task.h" |
16 #include "chrome/browser/prefs/pref_change_registrar.h" | 17 #include "chrome/browser/prefs/pref_change_registrar.h" |
17 #include "chrome/common/translate_errors.h" | 18 #include "chrome/common/translate_errors.h" |
18 #include "content/common/notification_observer.h" | 19 #include "content/common/notification_observer.h" |
19 #include "content/common/notification_registrar.h" | 20 #include "content/common/notification_registrar.h" |
20 #include "content/common/url_fetcher.h" | 21 #include "content/common/url_fetcher.h" |
21 | 22 |
22 template <typename T> struct DefaultSingletonTraits; | 23 template <typename T> struct DefaultSingletonTraits; |
23 class GURL; | 24 class GURL; |
24 struct PageTranslatedDetails; | 25 struct PageTranslatedDetails; |
(...skipping 13 matching lines...) Expand all Loading... |
38 static TranslateManager* GetInstance(); | 39 static TranslateManager* GetInstance(); |
39 | 40 |
40 virtual ~TranslateManager(); | 41 virtual ~TranslateManager(); |
41 | 42 |
42 // Let the caller decide if and when we should fetch the language list from | 43 // Let the caller decide if and when we should fetch the language list from |
43 // the translate server. This is a NOOP if switches::kDisableTranslate is | 44 // the translate server. This is a NOOP if switches::kDisableTranslate is |
44 // set or if prefs::kEnableTranslate is set to false. | 45 // set or if prefs::kEnableTranslate is set to false. |
45 // It will not retry more than kMaxRetryLanguageListFetch times. | 46 // It will not retry more than kMaxRetryLanguageListFetch times. |
46 void FetchLanguageListFromTranslateServer(PrefService* prefs); | 47 void FetchLanguageListFromTranslateServer(PrefService* prefs); |
47 | 48 |
| 49 // Allows caller to cleanup pending URLFetcher objects to make sure they |
| 50 // get released in the appropriate thread... Mainly for tests. |
| 51 void CleanupPendingUlrFetcher(); |
| 52 |
48 // Translates the page contents from |source_lang| to |target_lang|. | 53 // Translates the page contents from |source_lang| to |target_lang|. |
49 // The actual translation might be performed asynchronously if the translate | 54 // The actual translation might be performed asynchronously if the translate |
50 // script is not yet available. | 55 // script is not yet available. |
51 void TranslatePage(TabContents* tab_contents, | 56 void TranslatePage(TabContents* tab_contents, |
52 const std::string& source_lang, | 57 const std::string& source_lang, |
53 const std::string& target_lang); | 58 const std::string& target_lang); |
54 | 59 |
55 // Reverts the contents of the page in |tab_contents| to its original | 60 // Reverts the contents of the page in |tab_contents| to its original |
56 // language. | 61 // language. |
57 void RevertTranslation(TabContents* tab_contents); | 62 void RevertTranslation(TabContents* tab_contents); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 187 |
183 ScopedRunnableMethodFactory<TranslateManager> method_factory_; | 188 ScopedRunnableMethodFactory<TranslateManager> method_factory_; |
184 | 189 |
185 // The JS injected in the page to do the translation. | 190 // The JS injected in the page to do the translation. |
186 std::string translate_script_; | 191 std::string translate_script_; |
187 | 192 |
188 // Delay in milli-seconds after which the translate script is fetched again | 193 // Delay in milli-seconds after which the translate script is fetched again |
189 // from the translate server. | 194 // from the translate server. |
190 int translate_script_expiration_delay_; | 195 int translate_script_expiration_delay_; |
191 | 196 |
192 // Whether the translate JS is currently being retrieved. | 197 // Set when the translate JS is currently being retrieved. NULL otherwise. |
193 bool translate_script_request_pending_; | 198 scoped_ptr<URLFetcher> translate_script_request_pending_; |
194 | 199 |
195 // Whether the list of languages is currently being retrieved. | 200 // Set when the list of languages is currently being retrieved. |
196 bool language_list_request_pending_; | 201 // NULL otherwise. |
| 202 scoped_ptr<URLFetcher> language_list_request_pending_; |
197 | 203 |
198 // The list of pending translate requests. Translate requests are queued when | 204 // The list of pending translate requests. Translate requests are queued when |
199 // the translate script is not ready and has to be fetched from the translate | 205 // the translate script is not ready and has to be fetched from the translate |
200 // server. | 206 // server. |
201 std::vector<PendingRequest> pending_requests_; | 207 std::vector<PendingRequest> pending_requests_; |
202 | 208 |
203 // The languages supported by the translation server. | 209 // The languages supported by the translation server. |
204 static base::LazyInstance<std::set<std::string> > supported_languages_; | 210 static base::LazyInstance<std::set<std::string> > supported_languages_; |
205 | 211 |
206 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 212 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
207 }; | 213 }; |
208 | 214 |
209 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 215 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |