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

Side by Side Diff: components/translate/content/browser/content_translate_driver.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/translate/content/browser/content_translate_driver.h" 5 #include "components/translate/content/browser/content_translate_driver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
9 #include "components/translate/content/common/translate_messages.h" 12 #include "components/translate/content/common/translate_messages.h"
10 #include "components/translate/core/browser/translate_download_manager.h" 13 #include "components/translate/core/browser/translate_download_manager.h"
11 #include "components/translate/core/browser/translate_manager.h" 14 #include "components/translate/core/browser/translate_manager.h"
12 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/page_navigator.h" 19 #include "content/public/browser/page_navigator.h"
17 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 int attempt) { 57 int attempt) {
55 if (translate_manager_->GetLanguageState().translation_pending()) 58 if (translate_manager_->GetLanguageState().translation_pending())
56 return; 59 return;
57 60
58 // During a reload we need web content to be available before the 61 // During a reload we need web content to be available before the
59 // translate script is executed. Otherwise we will run the translate script on 62 // translate script is executed. Otherwise we will run the translate script on
60 // an empty DOM which will fail. Therefore we wait a bit to see if the page 63 // an empty DOM which will fail. Therefore we wait a bit to see if the page
61 // has finished. 64 // has finished.
62 if (web_contents()->IsLoading() && attempt < max_reload_check_attempts_) { 65 if (web_contents()->IsLoading() && attempt < max_reload_check_attempts_) {
63 int backoff = attempt * kMaxTranslateLoadCheckAttempts; 66 int backoff = attempt * kMaxTranslateLoadCheckAttempts;
64 base::MessageLoop::current()->PostDelayedTask( 67 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
65 FROM_HERE, 68 FROM_HERE,
66 base::Bind(&ContentTranslateDriver::InitiateTranslation, 69 base::Bind(&ContentTranslateDriver::InitiateTranslation,
67 weak_pointer_factory_.GetWeakPtr(), 70 weak_pointer_factory_.GetWeakPtr(), page_lang, attempt + 1),
68 page_lang,
69 attempt + 1),
70 base::TimeDelta::FromMilliseconds(backoff)); 71 base::TimeDelta::FromMilliseconds(backoff));
71 return; 72 return;
72 } 73 }
73 74
74 translate_manager_->InitiateTranslation( 75 translate_manager_->InitiateTranslation(
75 translate::TranslateDownloadManager::GetLanguageCode(page_lang)); 76 translate::TranslateDownloadManager::GetLanguageCode(page_lang));
76 } 77 }
77 78
78 // TranslateDriver methods 79 // TranslateDriver methods
79 80
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return; 191 return;
191 } 192 }
192 193
193 if (!translate_manager_->GetLanguageState().page_needs_translation()) 194 if (!translate_manager_->GetLanguageState().page_needs_translation())
194 return; 195 return;
195 196
196 // Note that we delay it as the ordering of the processing of this callback 197 // Note that we delay it as the ordering of the processing of this callback
197 // by WebContentsObservers is undefined and might result in the current 198 // by WebContentsObservers is undefined and might result in the current
198 // infobars being removed. Since the translation initiation process might add 199 // infobars being removed. Since the translation initiation process might add
199 // an infobar, it must be done after that. 200 // an infobar, it must be done after that.
200 base::MessageLoop::current()->PostTask( 201 base::ThreadTaskRunnerHandle::Get()->PostTask(
201 FROM_HERE, 202 FROM_HERE,
202 base::Bind(&ContentTranslateDriver::InitiateTranslation, 203 base::Bind(&ContentTranslateDriver::InitiateTranslation,
203 weak_pointer_factory_.GetWeakPtr(), 204 weak_pointer_factory_.GetWeakPtr(),
204 translate_manager_->GetLanguageState().original_language(), 205 translate_manager_->GetLanguageState().original_language(),
205 0)); 206 0));
206 } 207 }
207 208
208 void ContentTranslateDriver::DidNavigateAnyFrame( 209 void ContentTranslateDriver::DidNavigateAnyFrame(
209 content::RenderFrameHost* render_frame_host, 210 content::RenderFrameHost* render_frame_host,
210 const content::LoadCommittedDetails& details, 211 const content::LoadCommittedDetails& details,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 TranslateErrors::Type error_type) { 254 TranslateErrors::Type error_type) {
254 translate_manager_->PageTranslated( 255 translate_manager_->PageTranslated(
255 original_lang, translated_lang, error_type); 256 original_lang, translated_lang, error_type);
256 FOR_EACH_OBSERVER( 257 FOR_EACH_OBSERVER(
257 Observer, 258 Observer,
258 observer_list_, 259 observer_list_,
259 OnPageTranslated(original_lang, translated_lang, error_type)); 260 OnPageTranslated(original_lang, translated_lang, error_type));
260 } 261 }
261 262
262 } // namespace translate 263 } // namespace translate
OLDNEW
« no previous file with comments | « components/tracing/child_trace_message_filter.cc ('k') | components/translate/content/renderer/translate_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698