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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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 #include "chrome/browser/translate/translate_manager.h" 5 #include "chrome/browser/translate/translate_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 // When doing a page reload, TAB_LANGUAGE_DETERMINED is not sent, 198 // When doing a page reload, TAB_LANGUAGE_DETERMINED is not sent,
199 // so the translation needs to be explicitly initiated, but only when the 199 // so the translation needs to be explicitly initiated, but only when the
200 // page needs translation. 200 // page needs translation.
201 if (!translate_tab_helper->language_state().page_needs_translation()) 201 if (!translate_tab_helper->language_state().page_needs_translation())
202 return; 202 return;
203 // Note that we delay it as the TranslateManager gets this notification 203 // Note that we delay it as the TranslateManager gets this notification
204 // before the WebContents and the WebContents processing might remove the 204 // before the WebContents and the WebContents processing might remove the
205 // current infobars. Since InitTranslation might add an infobar, it must 205 // current infobars. Since InitTranslation might add an infobar, it must
206 // be done after that. 206 // be done after that.
207 MessageLoop::current()->PostTask(FROM_HERE, 207 base::MessageLoop::current()->PostTask(FROM_HERE,
208 base::Bind( 208 base::Bind(
209 &TranslateManager::InitiateTranslationPosted, 209 &TranslateManager::InitiateTranslationPosted,
210 weak_method_factory_.GetWeakPtr(), 210 weak_method_factory_.GetWeakPtr(),
211 controller->GetWebContents()->GetRenderProcessHost()->GetID(), 211 controller->GetWebContents()->GetRenderProcessHost()->GetID(),
212 controller->GetWebContents()->GetRenderViewHost()->GetRoutingID(), 212 controller->GetWebContents()->GetRenderViewHost()->GetRoutingID(),
213 translate_tab_helper->language_state().original_language(), 0)); 213 translate_tab_helper->language_state().original_language(), 0));
214 break; 214 break;
215 } 215 }
216 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: { 216 case chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED: {
217 const LanguageDetectionDetails* lang_det_details = 217 const LanguageDetectionDetails* lang_det_details =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 std::string api_key = google_apis::GetAPIKey(); 291 std::string api_key = google_apis::GetAPIKey();
292 argument += net::EscapeQueryParamValue(api_key, true); 292 argument += net::EscapeQueryParamValue(api_key, true);
293 argument += "');\n"; 293 argument += "');\n";
294 std::string data; 294 std::string data;
295 source->GetResponseAsString(&data); 295 source->GetResponseAsString(&data);
296 translate_script_ += argument + data; 296 translate_script_ += argument + data;
297 297
298 // We'll expire the cached script after some time, to make sure long 298 // We'll expire the cached script after some time, to make sure long
299 // running browsers still get fixes that might get pushed with newer 299 // running browsers still get fixes that might get pushed with newer
300 // scripts. 300 // scripts.
301 MessageLoop::current()->PostDelayedTask(FROM_HERE, 301 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
302 base::Bind(&TranslateManager::ClearTranslateScript, 302 base::Bind(&TranslateManager::ClearTranslateScript,
303 weak_method_factory_.GetWeakPtr()), 303 weak_method_factory_.GetWeakPtr()),
304 translate_script_expiration_delay_); 304 translate_script_expiration_delay_);
305 } 305 }
306 // Process any pending requests. 306 // Process any pending requests.
307 std::vector<PendingRequest>::const_iterator iter; 307 std::vector<PendingRequest>::const_iterator iter;
308 for (iter = pending_requests_.begin(); iter != pending_requests_.end(); 308 for (iter = pending_requests_.begin(); iter != pending_requests_.end();
309 ++iter) { 309 ++iter) {
310 const PendingRequest& request = *iter; 310 const PendingRequest& request = *iter;
311 WebContents* web_contents = 311 WebContents* web_contents =
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 TranslateTabHelper::FromWebContents(web_contents); 489 TranslateTabHelper::FromWebContents(web_contents);
490 if (translate_tab_helper->language_state().translation_pending()) 490 if (translate_tab_helper->language_state().translation_pending())
491 return; 491 return;
492 492
493 // During a reload we need web content to be available before the 493 // During a reload we need web content to be available before the
494 // translate script is executed. Otherwise we will run the translate script on 494 // translate script is executed. Otherwise we will run the translate script on
495 // an empty DOM which will fail. Therefore we wait a bit to see if the page 495 // an empty DOM which will fail. Therefore we wait a bit to see if the page
496 // has finished. 496 // has finished.
497 if ((web_contents->IsLoading()) && attempt < kMaxTranslateLoadCheckAttempts) { 497 if ((web_contents->IsLoading()) && attempt < kMaxTranslateLoadCheckAttempts) {
498 int backoff = attempt * max_reload_check_attempts_; 498 int backoff = attempt * max_reload_check_attempts_;
499 MessageLoop::current()->PostDelayedTask( 499 base::MessageLoop::current()->PostDelayedTask(
500 FROM_HERE, base::Bind(&TranslateManager::InitiateTranslationPosted, 500 FROM_HERE, base::Bind(&TranslateManager::InitiateTranslationPosted,
501 weak_method_factory_.GetWeakPtr(), process_id, 501 weak_method_factory_.GetWeakPtr(), process_id,
502 render_id, page_lang, ++attempt), 502 render_id, page_lang, ++attempt),
503 base::TimeDelta::FromMilliseconds(backoff)); 503 base::TimeDelta::FromMilliseconds(backoff));
504 return; 504 return;
505 } 505 }
506 506
507 InitiateTranslation(web_contents, GetLanguageCode(page_lang)); 507 InitiateTranslation(web_contents, GetLanguageCode(page_lang));
508 } 508 }
509 509
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // reason so we are more aggressive showing the shortcuts for never translate. 803 // reason so we are more aggressive showing the shortcuts for never translate.
804 #if defined(OS_ANDROID) 804 #if defined(OS_ANDROID)
805 config.never_translate_min_count = 1; 805 config.never_translate_min_count = 1;
806 #else 806 #else
807 config.never_translate_min_count = 3; 807 config.never_translate_min_count = 3;
808 #endif // defined(OS_ANDROID) 808 #endif // defined(OS_ANDROID)
809 809
810 config.always_translate_min_count = 3; 810 config.always_translate_min_count = 3;
811 return config; 811 return config;
812 } 812 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_syncable_service_unittest.cc ('k') | chrome/browser/translate/translate_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698