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

Side by Side Diff: components/translate/core/browser/translate_manager.h

Issue 224723025: Componentize TranslateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 6 years, 8 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_list.h" 12 #include "base/callback_list.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "components/translate/core/common/translate_errors.h" 16 #include "components/translate/core/common/translate_errors.h"
17 17
18 class GURL; 18 class GURL;
19 class PrefService; 19 class PrefService;
20 class TranslateClient; 20 class TranslateClient;
21 class TranslateDriver; 21 class TranslateDriver;
22 class TranslatePrefs;
22 struct TranslateErrorDetails; 23 struct TranslateErrorDetails;
23 class TranslateTabHelper;
24 24
25 // The TranslateManager class is responsible for showing an info-bar when a page 25 // The TranslateManager class is responsible for showing an info-bar when a page
26 // in a language different than the user language is loaded. It triggers the 26 // in a language different than the user language is loaded. It triggers the
27 // page translation the user requests. 27 // page translation the user requests.
28 // TranslateManager expects its associated TranslateTabHelper to always have a
29 // valid WebContents (i.e. the WebContents is never destroyed within the
30 // lifetime of TranslateManager).
31 28
32 class TranslateManager { 29 class TranslateManager {
33 public: 30 public:
34 // TranslateTabHelper is expected to outlive the TranslateManager. 31 // |translate_client| is expected to outlive the TranslateManager.
35 // |accept_language_pref_name| is the path for the preference for the 32 // |accept_language_pref_name| is the path for the preference for the
36 // accept-languages. 33 // accept-languages.
37 TranslateManager(TranslateTabHelper* helper, 34 TranslateManager(TranslateClient* translate_client,
38 const std::string& accept_language_pref_name); 35 const std::string& accept_language_pref_name);
39 virtual ~TranslateManager(); 36 virtual ~TranslateManager();
40 37
41 // Returns the language to translate to. The language returned is the 38 // Returns the language to translate to. The language returned is the
42 // first language found in the following list that is supported by the 39 // first language found in the following list that is supported by the
43 // translation service: 40 // translation service:
44 // the UI language 41 // the UI language
45 // the accept-language list 42 // the accept-language list
46 // If no language is found then an empty string is returned. 43 // If no language is found then an empty string is returned.
47 static std::string GetTargetLanguage( 44 static std::string GetTargetLanguage(
48 const std::vector<std::string>& accept_languages_list); 45 const std::vector<std::string>& accept_languages_list);
49 46
50 // Returns the language to automatically translate to. |original_language| is 47 // Returns the language to automatically translate to. |original_language| is
51 // the webpage's original language. 48 // the webpage's original language.
52 static std::string GetAutoTargetLanguage(const std::string& original_language, 49 static std::string GetAutoTargetLanguage(const std::string& original_language,
53 PrefService* prefs); 50 TranslatePrefs* translate_prefs);
54 51
55 // Translates the page contents from |source_lang| to |target_lang|. 52 // Translates the page contents from |source_lang| to |target_lang|.
56 // The actual translation might be performed asynchronously if the translate 53 // The actual translation might be performed asynchronously if the translate
57 // script is not yet available. 54 // script is not yet available.
58 void TranslatePage(const std::string& source_lang, 55 void TranslatePage(const std::string& source_lang,
59 const std::string& target_lang, 56 const std::string& target_lang,
60 bool triggered_from_menu); 57 bool triggered_from_menu);
61 58
62 // Starts the translation process for a page in the |page_lang| language. 59 // Starts the translation process for a page in the |page_lang| language.
63 void InitiateTranslation(const std::string& page_lang); 60 void InitiateTranslation(const std::string& page_lang);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // Initiates the translation. 92 // Initiates the translation.
96 void OnTranslateScriptFetchComplete(int page_id, 93 void OnTranslateScriptFetchComplete(int page_id,
97 const std::string& source_lang, 94 const std::string& source_lang,
98 const std::string& target_lang, 95 const std::string& target_lang,
99 bool success, 96 bool success,
100 const std::string& data); 97 const std::string& data);
101 98
102 // Preference name for the Accept-Languages HTTP header. 99 // Preference name for the Accept-Languages HTTP header.
103 std::string accept_languages_pref_name_; 100 std::string accept_languages_pref_name_;
104 101
105 // TODO(droger): Remove all uses of |translate_tab_helper_|, use 102 TranslateClient* translate_client_; // Weak.
106 // TranslateClient and TranslateDriver instead.
107 TranslateTabHelper* translate_tab_helper_; // Weak.
108 TranslateClient* translate_client_; // Weak.
109 TranslateDriver* translate_driver_; // Weak. 103 TranslateDriver* translate_driver_; // Weak.
110 104
111 base::WeakPtrFactory<TranslateManager> weak_method_factory_; 105 base::WeakPtrFactory<TranslateManager> weak_method_factory_;
112 106
113 DISALLOW_COPY_AND_ASSIGN(TranslateManager); 107 DISALLOW_COPY_AND_ASSIGN(TranslateManager);
114 }; 108 };
115 109
116 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ 110 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698