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

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

Issue 14846026: [Translate] When reloading a page Wait until some content has actually been re-loaded before trigg… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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>
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void ClearTranslateScript() { translate_script_.clear(); } 79 void ClearTranslateScript() { translate_script_.clear(); }
80 80
81 // content::NotificationObserver implementation: 81 // content::NotificationObserver implementation:
82 virtual void Observe(int type, 82 virtual void Observe(int type,
83 const content::NotificationSource& source, 83 const content::NotificationSource& source,
84 const content::NotificationDetails& details) OVERRIDE; 84 const content::NotificationDetails& details) OVERRIDE;
85 85
86 // net::URLFetcherDelegate implementation: 86 // net::URLFetcherDelegate implementation:
87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
88 88
89 // Used by unit-tests to override the default delay after which the translate 89 // Used by unit-tests to override some defaults
MAD 2013/05/09 14:05:24 Comments text should fill the line as much as poss
Miguel Garcia 2013/05/10 12:00:02 Done.
90 // Delay after which the translate
MAD 2013/05/09 14:05:24 Delay -> delay.
Miguel Garcia 2013/05/10 12:00:02 Done.
90 // script is fetched again from the translation server. 91 // script is fetched again from the translation server.
91 void set_translate_script_expiration_delay(int delay_ms) { 92 void set_translate_script_expiration_delay(int delay_ms) {
92 translate_script_expiration_delay_ = 93 translate_script_expiration_delay_ =
93 base::TimeDelta::FromMilliseconds(delay_ms); 94 base::TimeDelta::FromMilliseconds(delay_ms);
94 } 95 }
95 96
97 // Number of attempts before waiting for a page to be full reloaded.
MAD 2013/05/09 14:05:24 full -> fully
Miguel Garcia 2013/05/10 12:00:02 Done.
98 void set_translate_max_reload_attemps(int attempts) {
99 max_reload_check_attempts_ = attempts;
100 }
101
96 // Returns true if the URL can be translated. 102 // Returns true if the URL can be translated.
97 static bool IsTranslatableURL(const GURL& url); 103 static bool IsTranslatableURL(const GURL& url);
98 104
99 // Fills |languages| with the list of languages that the translate server can 105 // Fills |languages| with the list of languages that the translate server can
100 // translate to and from. 106 // translate to and from.
101 static void GetSupportedLanguages(std::vector<std::string>* languages); 107 static void GetSupportedLanguages(std::vector<std::string>* languages);
102 108
103 // Returns the language code that can be used with the Translate method for a 109 // Returns the language code that can be used with the Translate method for a
104 // specified |chrome_locale|. 110 // specified |chrome_locale|.
105 static std::string GetLanguageCode(const std::string& chrome_locale); 111 static std::string GetLanguageCode(const std::string& chrome_locale);
(...skipping 29 matching lines...) Expand all
135 // in case we failed to get them from the server, or didn't get them just yet. 141 // in case we failed to get them from the server, or didn't get them just yet.
136 static void InitSupportedLanguages(); 142 static void InitSupportedLanguages();
137 143
138 // Starts the translation process on |tab| containing the page in the 144 // Starts the translation process on |tab| containing the page in the
139 // |page_lang| language. 145 // |page_lang| language.
140 void InitiateTranslation(content::WebContents* web_contents, 146 void InitiateTranslation(content::WebContents* web_contents,
141 const std::string& page_lang); 147 const std::string& page_lang);
142 148
143 // If the tab identified by |process_id| and |render_id| has been closed, this 149 // If the tab identified by |process_id| and |render_id| has been closed, this
144 // does nothing, otherwise it calls InitiateTranslation. 150 // does nothing, otherwise it calls InitiateTranslation.
145 void InitiateTranslationPosted(int process_id, 151 void InitiateTranslationPosted(int process_id, int render_id,
146 int render_id, 152 const std::string& page_lang, int attempt);
147 const std::string& page_lang);
148 153
149 // Sends a translation request to the RenderView of |web_contents|. 154 // Sends a translation request to the RenderView of |web_contents|.
150 void DoTranslatePage(content::WebContents* web_contents, 155 void DoTranslatePage(content::WebContents* web_contents,
151 const std::string& translate_script, 156 const std::string& translate_script,
152 const std::string& source_lang, 157 const std::string& source_lang,
153 const std::string& target_lang); 158 const std::string& target_lang);
154 159
155 // Shows the after translate or error infobar depending on the details. 160 // Shows the after translate or error infobar depending on the details.
156 void PageTranslated(content::WebContents* web_contents, 161 void PageTranslated(content::WebContents* web_contents,
157 PageTranslatedDetails* details); 162 PageTranslatedDetails* details);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 200
196 base::WeakPtrFactory<TranslateManager> weak_method_factory_; 201 base::WeakPtrFactory<TranslateManager> weak_method_factory_;
197 202
198 // The JS injected in the page to do the translation. 203 // The JS injected in the page to do the translation.
199 std::string translate_script_; 204 std::string translate_script_;
200 205
201 // Delay after which the translate script is fetched again 206 // Delay after which the translate script is fetched again
202 // from the translate server. 207 // from the translate server.
203 base::TimeDelta translate_script_expiration_delay_; 208 base::TimeDelta translate_script_expiration_delay_;
204 209
210 // Max number of attempts before checking if a page has been
MAD 2013/05/09 14:05:24 Should fit on a single line. You could also add s
Miguel Garcia 2013/05/10 12:00:53 Done, added a case in the reload test as well On
211 // reloaded.
212 int max_reload_check_attempts_;
213
205 // Set when the translate JS is currently being retrieved. NULL otherwise. 214 // Set when the translate JS is currently being retrieved. NULL otherwise.
206 scoped_ptr<net::URLFetcher> translate_script_request_pending_; 215 scoped_ptr<net::URLFetcher> translate_script_request_pending_;
207 216
208 // Set when the list of languages is currently being retrieved. 217 // Set when the list of languages is currently being retrieved.
209 // NULL otherwise. 218 // NULL otherwise.
210 scoped_ptr<net::URLFetcher> language_list_request_pending_; 219 scoped_ptr<net::URLFetcher> language_list_request_pending_;
211 220
212 // The list of pending translate requests. Translate requests are queued when 221 // 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 222 // the translate script is not ready and has to be fetched from the translate
214 // server. 223 // server.
215 std::vector<PendingRequest> pending_requests_; 224 std::vector<PendingRequest> pending_requests_;
216 225
217 // The languages supported by the translation server. 226 // The languages supported by the translation server.
218 static base::LazyInstance<std::set<std::string> > supported_languages_; 227 static base::LazyInstance<std::set<std::string> > supported_languages_;
219 228
220 DISALLOW_COPY_AND_ASSIGN(TranslateManager); 229 DISALLOW_COPY_AND_ASSIGN(TranslateManager);
221 }; 230 };
222 231
223 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ 232 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/translate/translate_manager.cc » ('j') | chrome/browser/translate/translate_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698