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

Unified Diff: chrome/browser/translate/translate_tab_helper.cc

Issue 166963002: TranslateManager is no longer a singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp
Patch Set: rebase Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/translate/translate_tab_helper.cc
diff --git a/chrome/browser/translate/translate_tab_helper.cc b/chrome/browser/translate/translate_tab_helper.cc
index 35a6b4fbf5c290b392df6245e3512cd24041dd37..40b8a1593e2080629c3d641da28670009100bfdd 100644
--- a/chrome/browser/translate/translate_tab_helper.cc
+++ b/chrome/browser/translate/translate_tab_helper.cc
@@ -27,8 +27,8 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(TranslateTabHelper);
TranslateTabHelper::TranslateTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
- translate_driver_(&web_contents->GetController()) {
-}
+ translate_driver_(&web_contents->GetController()),
+ translate_manager_(this) {}
TranslateTabHelper::~TranslateTabHelper() {
}
@@ -55,8 +55,21 @@ TranslateAcceptLanguages* TranslateTabHelper::GetTranslateAcceptLanguages(
return TranslateAcceptLanguagesFactory::GetForBrowserContext(browser_context);
}
+// static
+TranslateManager* TranslateTabHelper::GetManagerFromWebContents(
+ content::WebContents* web_contents) {
+ return FromWebContents(web_contents)->GetTranslateManager();
blundell 2014/02/17 15:26:28 This should short-circuit out if the TranslateTabH
droger 2014/02/17 16:52:48 Done.
+}
+
+TranslateManager* TranslateTabHelper::GetTranslateManager() {
+ return &translate_manager_;
+}
+
+content::WebContents* TranslateTabHelper::GetWebContents() {
+ return content::WebContentsObserver::web_contents();
blundell 2014/02/17 15:26:28 Can't this body just be web_contents()?
droger 2014/02/17 16:52:48 Done.
+}
+
void TranslateTabHelper::ShowTranslateUI(TranslateTabHelper::TranslateStep step,
- content::WebContents* web_contents,
const std::string source_language,
const std::string target_language,
TranslateErrors::Type error_type) {
@@ -71,16 +84,16 @@ void TranslateTabHelper::ShowTranslateUI(TranslateTabHelper::TranslateStep step,
if (!GetLanguageState().HasLanguageChanged())
return;
}
- ShowBubble(web_contents, step, error_type);
+ ShowBubble(step, error_type);
return;
}
// Infobar UI.
Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext());
Profile* original_profile = profile->GetOriginalProfile();
TranslateInfoBarDelegate::Create(step != BEFORE_TRANSLATE,
- web_contents,
+ web_contents(),
step,
source_language,
target_language,
@@ -135,21 +148,20 @@ void TranslateTabHelper::OnPageTranslated(int32 page_id,
content::Details<PageTranslatedDetails>(&details));
}
-void TranslateTabHelper::ShowBubble(content::WebContents* web_contents,
- TranslateTabHelper::TranslateStep step,
+void TranslateTabHelper::ShowBubble(TranslateTabHelper::TranslateStep step,
TranslateErrors::Type error_type) {
// The bubble is implemented only on the desktop platforms.
#if !defined(OS_ANDROID) && !defined(OS_IOS)
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
// |browser| might be NULL when testing. In this case, Show(...) should be
// called because the implementation for testing is used.
if (!browser) {
- TranslateBubbleFactory::Show(NULL, web_contents, step, error_type);
+ TranslateBubbleFactory::Show(NULL, web_contents(), step, error_type);
return;
}
- if (web_contents != browser->tab_strip_model()->GetActiveWebContents())
+ if (web_contents() != browser->tab_strip_model()->GetActiveWebContents())
return;
// This ShowBubble function is also used for upating the existing bubble.
@@ -170,7 +182,7 @@ void TranslateTabHelper::ShowBubble(content::WebContents* web_contents,
}
TranslateBubbleFactory::Show(
- browser->window(), web_contents, step, error_type);
+ browser->window(), web_contents(), step, error_type);
#else
NOTREACHED();
#endif

Powered by Google App Engine
This is Rietveld 408576698