Index: chrome/browser/translate/translate_manager.h |
diff --git a/chrome/browser/translate/translate_manager.h b/chrome/browser/translate/translate_manager.h |
index b3e779a5962ea703409f214d1246092f0311ebba..07172a8cd3b55502469e3cfa4b0e14e891242049 100644 |
--- a/chrome/browser/translate/translate_manager.h |
+++ b/chrome/browser/translate/translate_manager.h |
@@ -16,11 +16,11 @@ |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
-template <typename T> struct DefaultSingletonTraits; |
class GURL; |
struct PageTranslatedDetails; |
class PrefService; |
struct TranslateErrorDetails; |
+class TranslateTabHelper; |
namespace content { |
class WebContents; |
@@ -29,13 +29,11 @@ class WebContents; |
// The TranslateManager class is responsible for showing an info-bar when a page |
// in a language different than the user language is loaded. It triggers the |
// page translation the user requests. |
-// It is a singleton. |
class TranslateManager : public content::NotificationObserver { |
public: |
- // Returns the singleton instance. |
- static TranslateManager* GetInstance(); |
- |
+ // TranslateTabHelper is expected to outlive the TranslateManager. |
+ explicit TranslateManager(TranslateTabHelper* helper); |
virtual ~TranslateManager(); |
// Returns true if the URL can be translated. |
@@ -57,18 +55,16 @@ class TranslateManager : public content::NotificationObserver { |
// Translates the page contents from |source_lang| to |target_lang|. |
// The actual translation might be performed asynchronously if the translate |
// script is not yet available. |
- void TranslatePage(content::WebContents* web_contents, |
- const std::string& source_lang, |
+ void TranslatePage(const std::string& source_lang, |
const std::string& target_lang); |
- // Reverts the contents of the page in |web_contents| to its original |
- // language. |
- void RevertTranslation(content::WebContents* web_contents); |
+ // Reverts the contents of the page to its original language. |
+ void RevertTranslation(); |
// Reports to the Google translate server that a page language was incorrectly |
// detected. This call is initiated by the user selecting the "report" menu |
// under options in the translate infobar. |
- void ReportLanguageDetectionError(content::WebContents* web_contents); |
+ void ReportLanguageDetectionError(); |
// content::NotificationObserver implementation: |
virtual void Observe(int type, |
@@ -90,44 +86,26 @@ class TranslateManager : public content::NotificationObserver { |
static scoped_ptr<TranslateErrorCallbackList::Subscription> |
RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); |
- protected: |
- TranslateManager(); |
- |
private: |
- friend struct DefaultSingletonTraits<TranslateManager>; |
- |
- // Structure that describes a translate request. |
- // Translation may be deferred while the translate script is being retrieved |
- // from the translate server. |
- struct PendingRequest { |
- int render_process_id; |
- int render_view_id; |
- int page_id; |
- std::string source_lang; |
- std::string target_lang; |
- }; |
- |
- // Starts the translation process on |tab| containing the page in the |
- // |page_lang| language. |
- void InitiateTranslation(content::WebContents* web_contents, |
- const std::string& page_lang); |
- |
- // If the tab identified by |process_id| and |render_id| has been closed, this |
- // does nothing, otherwise it calls InitiateTranslation. |
- void InitiateTranslationPosted(int process_id, int render_id, |
- const std::string& page_lang, int attempt); |
- |
- // Sends a translation request to the RenderView of |web_contents|. |
- void DoTranslatePage(content::WebContents* web_contents, |
- const std::string& translate_script, |
+ // Starts the translation process for a page in the |page_lang| language. |
+ void InitiateTranslation(const std::string& page_lang); |
+ |
+ // Initiates translation once the page is finished loading. |
+ void InitiateTranslationPosted(const std::string& page_lang, int attempt); |
+ |
+ // Sends a translation request to the RenderView. |
+ void DoTranslatePage(const std::string& translate_script, |
const std::string& source_lang, |
const std::string& target_lang); |
// Shows the after translate or error infobar depending on the details. |
- void PageTranslated(content::WebContents* web_contents, |
- PageTranslatedDetails* details); |
+ void PageTranslated(PageTranslatedDetails* details); |
- void OnTranslateScriptFetchComplete(PendingRequest request, |
+ // Called when the Translate script has been fetched. |
+ // Initiates the translation. |
+ void OnTranslateScriptFetchComplete(int page_id, |
+ const std::string& source_lang, |
+ const std::string& target_lang, |
bool success, |
const std::string& data); |
@@ -136,6 +114,8 @@ class TranslateManager : public content::NotificationObserver { |
// Max number of attempts before checking if a page has been reloaded. |
int max_reload_check_attempts_; |
+ TranslateTabHelper* translate_tab_helper_; // Weak |
MAD
2014/02/18 20:29:12
Please add a '.' at the end of the comment.
droger
2014/02/19 09:17:29
Done.
|
+ |
base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
DISALLOW_COPY_AND_ASSIGN(TranslateManager); |