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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
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 "base/prefs/public/pref_change_registrar.h" | 17 #include "base/prefs/public/pref_change_registrar.h" |
| 18 #include "base/prefs/public/pref_observer.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "chrome/common/translate_errors.h" | 20 #include "chrome/common/translate_errors.h" |
20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.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; |
28 class TranslateInfoBarDelegate; | 29 class TranslateInfoBarDelegate; |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 class WebContents; | 32 class WebContents; |
32 } | 33 } |
33 | 34 |
34 namespace net { | 35 namespace net { |
35 class URLFetcher; | 36 class URLFetcher; |
36 } | 37 } |
37 | 38 |
38 // The TranslateManager class is responsible for showing an info-bar when a page | 39 // The TranslateManager class is responsible for showing an info-bar when a page |
39 // in a language different than the user language is loaded. It triggers the | 40 // in a language different than the user language is loaded. It triggers the |
40 // page translation the user requests. | 41 // page translation the user requests. |
41 // It is a singleton. | 42 // It is a singleton. |
42 | 43 |
43 class TranslateManager : public content::NotificationObserver, | 44 class TranslateManager : public content::NotificationObserver, |
| 45 public PrefObserver, |
44 public net::URLFetcherDelegate { | 46 public net::URLFetcherDelegate { |
45 public: | 47 public: |
46 // Returns the singleton instance. | 48 // Returns the singleton instance. |
47 static TranslateManager* GetInstance(); | 49 static TranslateManager* GetInstance(); |
48 | 50 |
49 virtual ~TranslateManager(); | 51 virtual ~TranslateManager(); |
50 | 52 |
51 // Let the caller decide if and when we should fetch the language list from | 53 // Let the caller decide if and when we should fetch the language list from |
52 // the translate server. This is a NOOP if switches::kDisableTranslate is | 54 // the translate server. This is a NOOP if switches::kDisableTranslate is |
53 // set or if prefs::kEnableTranslate is set to false. | 55 // set or if prefs::kEnableTranslate is set to false. |
(...skipping 21 matching lines...) Expand all Loading... |
75 void ReportLanguageDetectionError(content::WebContents* web_contents); | 77 void ReportLanguageDetectionError(content::WebContents* web_contents); |
76 | 78 |
77 // Clears the translate script, so it will be fetched next time we translate. | 79 // Clears the translate script, so it will be fetched next time we translate. |
78 void ClearTranslateScript() { translate_script_.clear(); } | 80 void ClearTranslateScript() { translate_script_.clear(); } |
79 | 81 |
80 // content::NotificationObserver implementation: | 82 // content::NotificationObserver implementation: |
81 virtual void Observe(int type, | 83 virtual void Observe(int type, |
82 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) OVERRIDE; | 85 const content::NotificationDetails& details) OVERRIDE; |
84 | 86 |
| 87 // PrefObserver implementation: |
| 88 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 89 const std::string& pref_name) OVERRIDE; |
| 90 |
85 // net::URLFetcherDelegate implementation: | 91 // net::URLFetcherDelegate implementation: |
86 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 92 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
87 | 93 |
88 // Used by unit-tests to override the default delay after which the translate | 94 // Used by unit-tests to override the default delay after which the translate |
89 // script is fetched again from the translation server. | 95 // script is fetched again from the translation server. |
90 void set_translate_script_expiration_delay(int delay_ms) { | 96 void set_translate_script_expiration_delay(int delay_ms) { |
91 translate_script_expiration_delay_ = | 97 translate_script_expiration_delay_ = |
92 base::TimeDelta::FromMilliseconds(delay_ms); | 98 base::TimeDelta::FromMilliseconds(delay_ms); |
93 } | 99 } |
94 | 100 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // server. | 229 // server. |
224 std::vector<PendingRequest> pending_requests_; | 230 std::vector<PendingRequest> pending_requests_; |
225 | 231 |
226 // The languages supported by the translation server. | 232 // The languages supported by the translation server. |
227 static base::LazyInstance<std::set<std::string> > supported_languages_; | 233 static base::LazyInstance<std::set<std::string> > supported_languages_; |
228 | 234 |
229 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 235 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
230 }; | 236 }; |
231 | 237 |
232 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 238 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |