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/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "chrome/browser/prefs/pref_change_registrar.h" | 17 #include "chrome/browser/prefs/pref_change_registrar.h" |
18 #include "chrome/common/translate_errors.h" | 18 #include "chrome/common/translate_errors.h" |
19 #include "content/common/net/url_fetcher.h" | 19 #include "content/public/common/url_fetcher_delegate.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 | 22 |
23 template <typename T> struct DefaultSingletonTraits; | 23 template <typename T> struct DefaultSingletonTraits; |
24 class GURL; | 24 class GURL; |
25 struct PageTranslatedDetails; | 25 struct PageTranslatedDetails; |
26 class PrefService; | 26 class PrefService; |
27 class TabContents; | 27 class TabContents; |
28 class TranslateInfoBarDelegate; | 28 class TranslateInfoBarDelegate; |
29 | 29 |
30 // The TranslateManager class is responsible for showing an info-bar when a page | 30 // The TranslateManager class is responsible for showing an info-bar when a page |
31 // in a language different than the user language is loaded. It triggers the | 31 // in a language different than the user language is loaded. It triggers the |
32 // page translation the user requests. | 32 // page translation the user requests. |
33 // It is a singleton. | 33 // It is a singleton. |
34 | 34 |
35 class TranslateManager : public content::NotificationObserver, | 35 class TranslateManager : public content::NotificationObserver, |
36 public URLFetcher::Delegate { | 36 public content::URLFetcherDelegate { |
37 public: | 37 public: |
38 // Returns the singleton instance. | 38 // Returns the singleton instance. |
39 static TranslateManager* GetInstance(); | 39 static TranslateManager* GetInstance(); |
40 | 40 |
41 virtual ~TranslateManager(); | 41 virtual ~TranslateManager(); |
42 | 42 |
43 // 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 |
44 // the translate server. This is a NOOP if switches::kDisableTranslate is | 44 // the translate server. This is a NOOP if switches::kDisableTranslate is |
45 // set or if prefs::kEnableTranslate is set to false. | 45 // set or if prefs::kEnableTranslate is set to false. |
46 // It will not retry more than kMaxRetryLanguageListFetch times. | 46 // It will not retry more than kMaxRetryLanguageListFetch times. |
(...skipping 20 matching lines...) Expand all Loading... |
67 void ReportLanguageDetectionError(TabContents* tab_contents); | 67 void ReportLanguageDetectionError(TabContents* tab_contents); |
68 | 68 |
69 // Clears the translate script, so it will be fetched next time we translate. | 69 // Clears the translate script, so it will be fetched next time we translate. |
70 void ClearTranslateScript() { translate_script_.clear(); } | 70 void ClearTranslateScript() { translate_script_.clear(); } |
71 | 71 |
72 // content::NotificationObserver implementation: | 72 // content::NotificationObserver implementation: |
73 virtual void Observe(int type, | 73 virtual void Observe(int type, |
74 const content::NotificationSource& source, | 74 const content::NotificationSource& source, |
75 const content::NotificationDetails& details); | 75 const content::NotificationDetails& details); |
76 | 76 |
77 // URLFetcher::Delegate implementation: | 77 // content::URLFetcherDelegate implementation: |
78 virtual void OnURLFetchComplete(const URLFetcher* source, | 78 virtual void OnURLFetchComplete(const URLFetcher* source); |
79 const GURL& url, | |
80 const net::URLRequestStatus& status, | |
81 int response_code, | |
82 const net::ResponseCookies& cookies, | |
83 const std::string& data); | |
84 | 79 |
85 // Used by unit-tests to override the default delay after which the translate | 80 // Used by unit-tests to override the default delay after which the translate |
86 // script is fetched again from the translation server. | 81 // script is fetched again from the translation server. |
87 void set_translate_script_expiration_delay(int delay_ms) { | 82 void set_translate_script_expiration_delay(int delay_ms) { |
88 translate_script_expiration_delay_ = delay_ms; | 83 translate_script_expiration_delay_ = delay_ms; |
89 } | 84 } |
90 | 85 |
91 // Convenience method to know if a tab is showing a translate infobar. | 86 // Convenience method to know if a tab is showing a translate infobar. |
92 static bool IsShowingTranslateInfobar(TabContents* tab); | 87 static bool IsShowingTranslateInfobar(TabContents* tab); |
93 | 88 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // server. | 208 // server. |
214 std::vector<PendingRequest> pending_requests_; | 209 std::vector<PendingRequest> pending_requests_; |
215 | 210 |
216 // The languages supported by the translation server. | 211 // The languages supported by the translation server. |
217 static base::LazyInstance<std::set<std::string> > supported_languages_; | 212 static base::LazyInstance<std::set<std::string> > supported_languages_; |
218 | 213 |
219 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 214 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
220 }; | 215 }; |
221 | 216 |
222 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 217 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |