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

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

Issue 166963002: TranslateManager is no longer a singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp
Patch Set: Review comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/translate/translate_bubble_model.h" 11 #include "chrome/browser/ui/translate/translate_bubble_model.h"
12 #include "components/translate/content/browser/content_translate_driver.h" 12 #include "components/translate/content/browser/content_translate_driver.h"
13 #include "components/translate/core/common/translate_errors.h" 13 #include "components/translate/core/common/translate_errors.h"
14 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_contents_user_data.h" 15 #include "content/public/browser/web_contents_user_data.h"
16 16
17 namespace content { 17 namespace content {
18 class BrowserContext; 18 class BrowserContext;
19 class WebContents; 19 class WebContents;
20 } 20 }
21 21
22 struct LanguageDetectionDetails; 22 struct LanguageDetectionDetails;
23 class PrefService; 23 class PrefService;
24 class TranslateAcceptLanguages; 24 class TranslateAcceptLanguages;
25 class TranslatePrefs; 25 class TranslatePrefs;
26 class TranslateManager;
26 27
27 class TranslateTabHelper 28 class TranslateTabHelper
28 : public content::WebContentsObserver, 29 : public content::WebContentsObserver,
29 public content::WebContentsUserData<TranslateTabHelper> { 30 public content::WebContentsUserData<TranslateTabHelper> {
30 public: 31 public:
31 virtual ~TranslateTabHelper(); 32 virtual ~TranslateTabHelper();
32 33
33 // Gets the LanguageState associated with the page. 34 // Gets the LanguageState associated with the page.
34 LanguageState& GetLanguageState(); 35 LanguageState& GetLanguageState();
35 36
36 // Returns the ContentTranslateDriver instance associated with this 37 // Returns the ContentTranslateDriver instance associated with this
37 // WebContents. 38 // WebContents.
38 ContentTranslateDriver& translate_driver() { return translate_driver_; } 39 ContentTranslateDriver& translate_driver() { return translate_driver_; }
39 40
40 // Helper method to return a new TranslatePrefs instance. 41 // Helper method to return a new TranslatePrefs instance.
41 static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs); 42 static scoped_ptr<TranslatePrefs> CreateTranslatePrefs(PrefService* prefs);
42 43
43 // Helper method to return the TranslateAcceptLanguages instance associated 44 // Helper method to return the TranslateAcceptLanguages instance associated
44 // with |browser_context|. 45 // with |browser_context|.
45 static TranslateAcceptLanguages* GetTranslateAcceptLanguages( 46 static TranslateAcceptLanguages* GetTranslateAcceptLanguages(
46 content::BrowserContext* browser_context); 47 content::BrowserContext* browser_context);
47 48
49 // Helper method to return the TranslateManager instance associated with
50 // |web_contents|.
blundell 2014/02/18 09:21:46 , or NULL if there is no such associated instance.
51 static TranslateManager* GetManagerFromWebContents(
52 content::WebContents* web_contents);
53
54 // Gets the associated TranslateManager.
55 TranslateManager* GetTranslateManager();
56
57 // Gets the associated WebContents.
blundell 2014/02/18 09:21:46 Returns NULL if the WebContents is being destroyed
58 content::WebContents* GetWebContents();
59
48 // Denotes which state the user is in with respect to translate. 60 // Denotes which state the user is in with respect to translate.
49 enum TranslateStep { 61 enum TranslateStep {
50 BEFORE_TRANSLATE, 62 BEFORE_TRANSLATE,
51 TRANSLATING, 63 TRANSLATING,
52 AFTER_TRANSLATE, 64 AFTER_TRANSLATE,
53 TRANSLATE_ERROR 65 TRANSLATE_ERROR
54 }; 66 };
55 67
56 // Called when the embedder should present UI to the user corresponding to the 68 // Called when the embedder should present UI to the user corresponding to the
57 // user's current |step|. 69 // user's current |step|.
58 void ShowTranslateUI(TranslateStep step, 70 void ShowTranslateUI(TranslateStep step,
59 content::WebContents* web_contents,
60 const std::string source_language, 71 const std::string source_language,
61 const std::string target_language, 72 const std::string target_language,
62 TranslateErrors::Type error_type); 73 TranslateErrors::Type error_type);
63 74
64 private: 75 private:
65 explicit TranslateTabHelper(content::WebContents* web_contents); 76 explicit TranslateTabHelper(content::WebContents* web_contents);
66 friend class content::WebContentsUserData<TranslateTabHelper>; 77 friend class content::WebContentsUserData<TranslateTabHelper>;
67 78
68 // content::WebContentsObserver implementation. 79 // content::WebContentsObserver implementation.
69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
70 virtual void DidNavigateAnyFrame( 81 virtual void DidNavigateAnyFrame(
71 const content::LoadCommittedDetails& details, 82 const content::LoadCommittedDetails& details,
72 const content::FrameNavigateParams& params) OVERRIDE; 83 const content::FrameNavigateParams& params) OVERRIDE;
84 virtual void WebContentsDestroyed(
85 content::WebContents* web_contents) OVERRIDE;
73 86
74 void OnLanguageDetermined(const LanguageDetectionDetails& details, 87 void OnLanguageDetermined(const LanguageDetectionDetails& details,
75 bool page_needs_translation); 88 bool page_needs_translation);
76 void OnPageTranslated(int32 page_id, 89 void OnPageTranslated(int32 page_id,
77 const std::string& original_lang, 90 const std::string& original_lang,
78 const std::string& translated_lang, 91 const std::string& translated_lang,
79 TranslateErrors::Type error_type); 92 TranslateErrors::Type error_type);
80 93
81 // Shows the translate bubble. 94 // Shows the translate bubble.
82 void ShowBubble(content::WebContents* web_contents, 95 void ShowBubble(TranslateStep step, TranslateErrors::Type error_type);
83 TranslateStep step,
84 TranslateErrors::Type error_type);
85 96
86 ContentTranslateDriver translate_driver_; 97 ContentTranslateDriver translate_driver_;
98 scoped_ptr<TranslateManager> translate_manager_;
87 99
88 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper); 100 DISALLOW_COPY_AND_ASSIGN(TranslateTabHelper);
89 }; 101 };
90 102
91 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_ 103 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698