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> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
24 | 24 |
25 template <typename T> struct DefaultSingletonTraits; | 25 template <typename T> struct DefaultSingletonTraits; |
26 class GURL; | 26 class GURL; |
27 struct LanguageDetectionDetails; | 27 struct LanguageDetectionDetails; |
28 struct PageTranslatedDetails; | 28 struct PageTranslatedDetails; |
29 class PrefService; | 29 class PrefService; |
30 struct ShortcutConfiguration; | 30 struct ShortcutConfiguration; |
| 31 struct TranslateErrorDetails; |
31 class TranslateInfoBarDelegate; | 32 class TranslateInfoBarDelegate; |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 class WebContents; | 35 class WebContents; |
35 } | 36 } |
36 | 37 |
37 namespace net { | 38 namespace net { |
38 class URLFetcher; | 39 class URLFetcher; |
39 } | 40 } |
40 | 41 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 // static const values shared with our browser tests. | 119 // static const values shared with our browser tests. |
119 static const char kLanguageListCallbackName[]; | 120 static const char kLanguageListCallbackName[]; |
120 static const char kTargetLanguagesKey[]; | 121 static const char kTargetLanguagesKey[]; |
121 | 122 |
122 // The observer class for TranslateManager. | 123 // The observer class for TranslateManager. |
123 class Observer { | 124 class Observer { |
124 public: | 125 public: |
125 virtual void OnLanguageDetection( | 126 virtual void OnLanguageDetection( |
126 const LanguageDetectionDetails& details) = 0; | 127 const LanguageDetectionDetails& details) = 0; |
| 128 virtual void OnTranslateError( |
| 129 const TranslateErrorDetails& details) = 0; |
127 }; | 130 }; |
128 | 131 |
129 // Adds/removes observer. | 132 // Adds/removes observer. |
130 void AddObserver(Observer* obs); | 133 void AddObserver(Observer* obs); |
131 void RemoveObserver(Observer* obs); | 134 void RemoveObserver(Observer* obs); |
132 | 135 |
133 protected: | 136 protected: |
134 TranslateManager(); | 137 TranslateManager(); |
135 | 138 |
136 private: | 139 private: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // preference in |prefs|. | 187 // preference in |prefs|. |
185 void InitAcceptLanguages(PrefService* prefs); | 188 void InitAcceptLanguages(PrefService* prefs); |
186 | 189 |
187 // Fetches the JS translate script (the script that is injected in the page | 190 // Fetches the JS translate script (the script that is injected in the page |
188 // to translate it). | 191 // to translate it). |
189 void RequestTranslateScript(); | 192 void RequestTranslateScript(); |
190 | 193 |
191 // Notifies to the observers when a language is detected. | 194 // Notifies to the observers when a language is detected. |
192 void NotifyLanguageDetection(const LanguageDetectionDetails& details); | 195 void NotifyLanguageDetection(const LanguageDetectionDetails& details); |
193 | 196 |
| 197 // Notifies to the observers when translate failed. |
| 198 void NotifyTranslateError(const TranslateErrorDetails& details); |
| 199 |
194 // Returns the language to translate to. The language returned is the | 200 // Returns the language to translate to. The language returned is the |
195 // first language found in the following list that is supported by the | 201 // first language found in the following list that is supported by the |
196 // translation service: | 202 // translation service: |
197 // the UI language | 203 // the UI language |
198 // the accept-language list | 204 // the accept-language list |
199 // If no language is found then an empty string is returned. | 205 // If no language is found then an empty string is returned. |
200 static std::string GetTargetLanguage(PrefService* prefs); | 206 static std::string GetTargetLanguage(PrefService* prefs); |
201 | 207 |
202 // Returns the different parameters used to decide whether extra shortcuts | 208 // Returns the different parameters used to decide whether extra shortcuts |
203 // are needed. | 209 // are needed. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // The languages supported by the translation server. | 248 // The languages supported by the translation server. |
243 static base::LazyInstance<std::set<std::string> > supported_languages_; | 249 static base::LazyInstance<std::set<std::string> > supported_languages_; |
244 | 250 |
245 // List of registered observers. | 251 // List of registered observers. |
246 ObserverList<Observer> observer_list_; | 252 ObserverList<Observer> observer_list_; |
247 | 253 |
248 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 254 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
249 }; | 255 }; |
250 | 256 |
251 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 257 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |