Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/translate/translate_manager.h

Issue 14494004: Added the 'Translation Logs' tab to chrome://translate-internals/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: first commit Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/observer_list.h"
17 #include "base/prefs/pref_change_registrar.h" 18 #include "base/prefs/pref_change_registrar.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;
27 struct LanguageDetectionDetails;
26 struct PageTranslatedDetails; 28 struct PageTranslatedDetails;
27 class PrefService; 29 class PrefService;
28 struct ShortcutConfiguration; 30 struct ShortcutConfiguration;
29 class TranslateInfoBarDelegate; 31 class TranslateInfoBarDelegate;
30 32
31 namespace content { 33 namespace content {
32 class WebContents; 34 class WebContents;
33 } 35 }
34 36
35 namespace net { 37 namespace net {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // Returns the language code that can be used with the Translate method for a 105 // Returns the language code that can be used with the Translate method for a
104 // specified |chrome_locale|. 106 // specified |chrome_locale|.
105 static std::string GetLanguageCode(const std::string& chrome_locale); 107 static std::string GetLanguageCode(const std::string& chrome_locale);
106 108
107 // Returns true if |language| is supported by the translation server. 109 // Returns true if |language| is supported by the translation server.
108 static bool IsSupportedLanguage(const std::string& language); 110 static bool IsSupportedLanguage(const std::string& language);
109 111
110 // static const values shared with our browser tests. 112 // static const values shared with our browser tests.
111 static const char kLanguageListCallbackName[]; 113 static const char kLanguageListCallbackName[];
112 static const char kTargetLanguagesKey[]; 114 static const char kTargetLanguagesKey[];
115
116 // The observer class for TranslateManager.
117 class Observer {
118 public:
119 virtual void OnLanguageDetection(
120 const LanguageDetectionDetails& details) = 0;
121 };
122
123 // Adds/removes observer.
124 void AddObserver(Observer* obs);
125 void RemoveObserver(Observer* obs);
126
113 protected: 127 protected:
114 TranslateManager(); 128 TranslateManager();
115 129
116 private: 130 private:
117 friend struct DefaultSingletonTraits<TranslateManager>; 131 friend struct DefaultSingletonTraits<TranslateManager>;
118 132
119 // Structure that describes a translate request. 133 // Structure that describes a translate request.
120 // Translation may be deferred while the translate script is being retrieved 134 // Translation may be deferred while the translate script is being retrieved
121 // from the translate server. 135 // from the translate server.
122 struct PendingRequest { 136 struct PendingRequest {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 const std::string& language); 176 const std::string& language);
163 177
164 // Initializes the |accept_languages_| language table based on the associated 178 // Initializes the |accept_languages_| language table based on the associated
165 // preference in |prefs|. 179 // preference in |prefs|.
166 void InitAcceptLanguages(PrefService* prefs); 180 void InitAcceptLanguages(PrefService* prefs);
167 181
168 // Fetches the JS translate script (the script that is injected in the page 182 // Fetches the JS translate script (the script that is injected in the page
169 // to translate it). 183 // to translate it).
170 void RequestTranslateScript(); 184 void RequestTranslateScript();
171 185
186 // Notifies to the observers when a language is detected.
187 void NotifyLanguageDetection(const LanguageDetectionDetails& details);
188
172 // Returns the language to translate to. The language returned is the 189 // Returns the language to translate to. The language returned is the
173 // first language found in the following list that is supported by the 190 // first language found in the following list that is supported by the
174 // translation service: 191 // translation service:
175 // the UI language 192 // the UI language
176 // the accept-language list 193 // the accept-language list
177 // If no language is found then an empty string is returned. 194 // If no language is found then an empty string is returned.
178 static std::string GetTargetLanguage(PrefService* prefs); 195 static std::string GetTargetLanguage(PrefService* prefs);
179 196
180 // Returns the different parameters used to decide whether extra shortcuts 197 // Returns the different parameters used to decide whether extra shortcuts
181 // are needed. 198 // are needed.
(...skipping 28 matching lines...) Expand all
210 scoped_ptr<net::URLFetcher> language_list_request_pending_; 227 scoped_ptr<net::URLFetcher> language_list_request_pending_;
211 228
212 // The list of pending translate requests. Translate requests are queued when 229 // The list of pending translate requests. Translate requests are queued when
213 // the translate script is not ready and has to be fetched from the translate 230 // the translate script is not ready and has to be fetched from the translate
214 // server. 231 // server.
215 std::vector<PendingRequest> pending_requests_; 232 std::vector<PendingRequest> pending_requests_;
216 233
217 // The languages supported by the translation server. 234 // The languages supported by the translation server.
218 static base::LazyInstance<std::set<std::string> > supported_languages_; 235 static base::LazyInstance<std::set<std::string> > supported_languages_;
219 236
237 // List of registered observers.
238 ObserverList<Observer> observer_list_;
239
220 DISALLOW_COPY_AND_ASSIGN(TranslateManager); 240 DISALLOW_COPY_AND_ASSIGN(TranslateManager);
221 }; 241 };
222 242
223 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ 243 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698