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/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/prefs/pref_change_registrar.h" | 17 #include "base/prefs/pref_change_registrar.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "chrome/common/translate_errors.h" | 19 #include "chrome/common/translate_errors.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 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
23 | 23 |
24 template <typename T> struct DefaultSingletonTraits; | 24 template <typename T> struct DefaultSingletonTraits; |
25 class GURL; | 25 class GURL; |
26 struct LanguageDetectionDetails; | 26 struct LanguageDetectionDetails; |
27 struct PageTranslatedDetails; | 27 struct PageTranslatedDetails; |
28 class PrefService; | 28 class PrefService; |
29 struct ShortcutConfiguration; | 29 struct ShortcutConfiguration; |
| 30 struct TranslateErrorDetails; |
30 class TranslateInfoBarDelegate; | 31 class TranslateInfoBarDelegate; |
31 class TranslateLanguageList; | 32 class TranslateLanguageList; |
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 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 static std::string GetLanguageCode(const std::string& chrome_locale); | 113 static std::string GetLanguageCode(const std::string& chrome_locale); |
113 | 114 |
114 // Returns true if |language| is supported by the translation server. | 115 // Returns true if |language| is supported by the translation server. |
115 static bool IsSupportedLanguage(const std::string& language); | 116 static bool IsSupportedLanguage(const std::string& language); |
116 | 117 |
117 // The observer class for TranslateManager. | 118 // The observer class for TranslateManager. |
118 class Observer { | 119 class Observer { |
119 public: | 120 public: |
120 virtual void OnLanguageDetection( | 121 virtual void OnLanguageDetection( |
121 const LanguageDetectionDetails& details) = 0; | 122 const LanguageDetectionDetails& details) = 0; |
| 123 virtual void OnTranslateError( |
| 124 const TranslateErrorDetails& details) = 0; |
122 }; | 125 }; |
123 | 126 |
124 // Adds/removes observer. | 127 // Adds/removes observer. |
125 void AddObserver(Observer* obs); | 128 void AddObserver(Observer* obs); |
126 void RemoveObserver(Observer* obs); | 129 void RemoveObserver(Observer* obs); |
127 | 130 |
128 protected: | 131 protected: |
129 TranslateManager(); | 132 TranslateManager(); |
130 | 133 |
131 private: | 134 private: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // preference in |prefs|. | 174 // preference in |prefs|. |
172 void InitAcceptLanguages(PrefService* prefs); | 175 void InitAcceptLanguages(PrefService* prefs); |
173 | 176 |
174 // Fetches the JS translate script (the script that is injected in the page | 177 // Fetches the JS translate script (the script that is injected in the page |
175 // to translate it). | 178 // to translate it). |
176 void RequestTranslateScript(); | 179 void RequestTranslateScript(); |
177 | 180 |
178 // Notifies to the observers when a language is detected. | 181 // Notifies to the observers when a language is detected. |
179 void NotifyLanguageDetection(const LanguageDetectionDetails& details); | 182 void NotifyLanguageDetection(const LanguageDetectionDetails& details); |
180 | 183 |
| 184 // Notifies to the observers when translate failed. |
| 185 void NotifyTranslateError(const TranslateErrorDetails& details); |
| 186 |
181 // Returns the language to translate to. The language returned is the | 187 // Returns the language to translate to. The language returned is the |
182 // first language found in the following list that is supported by the | 188 // first language found in the following list that is supported by the |
183 // translation service: | 189 // translation service: |
184 // the UI language | 190 // the UI language |
185 // the accept-language list | 191 // the accept-language list |
186 // If no language is found then an empty string is returned. | 192 // If no language is found then an empty string is returned. |
187 static std::string GetTargetLanguage(PrefService* prefs); | 193 static std::string GetTargetLanguage(PrefService* prefs); |
188 | 194 |
189 // Returns the different parameters used to decide whether extra shortcuts | 195 // Returns the different parameters used to decide whether extra shortcuts |
190 // are needed. | 196 // are needed. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // List of registered observers. | 231 // List of registered observers. |
226 ObserverList<Observer> observer_list_; | 232 ObserverList<Observer> observer_list_; |
227 | 233 |
228 // An instance of TranslateLanguageList which manages supported language list. | 234 // An instance of TranslateLanguageList which manages supported language list. |
229 scoped_ptr<TranslateLanguageList> language_list_; | 235 scoped_ptr<TranslateLanguageList> language_list_; |
230 | 236 |
231 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 237 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
232 }; | 238 }; |
233 | 239 |
234 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 240 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |