OLD | NEW |
---|---|
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 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ |
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_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/browser/language_state.h" | |
16 #include "components/translate/core/common/translate_errors.h" | 17 #include "components/translate/core/common/translate_errors.h" |
17 | 18 |
18 class GURL; | 19 class GURL; |
19 class PrefService; | 20 class PrefService; |
20 class TranslateClient; | 21 class TranslateClient; |
21 class TranslateDriver; | 22 class TranslateDriver; |
22 class TranslatePrefs; | 23 class TranslatePrefs; |
23 struct TranslateErrorDetails; | 24 struct TranslateErrorDetails; |
24 | 25 |
26 namespace content { | |
27 struct LoadCommittedDetails; | |
28 class NavigationController; | |
29 class WebContents; | |
30 } | |
droger
2014/05/20 07:43:07
Remove all these declarations.
nshaik
2014/05/20 22:33:53
Done.
| |
31 | |
25 // The TranslateManager class is responsible for showing an info-bar when a page | 32 // 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 | 33 // in a language different than the user language is loaded. It triggers the |
27 // page translation the user requests. | 34 // page translation the user requests. |
28 | 35 |
29 class TranslateManager { | 36 class TranslateManager { |
30 public: | 37 public: |
31 // |translate_client| is expected to outlive the TranslateManager. | 38 // |translate_client| is expected to outlive the TranslateManager. |
32 // |accept_language_pref_name| is the path for the preference for the | 39 // |accept_language_pref_name| is the path for the preference for the |
33 // accept-languages. | 40 // accept-languages. |
34 TranslateManager(TranslateClient* translate_client, | 41 TranslateManager(TranslateClient* translate_client, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 // Callback types for translate errors. | 88 // Callback types for translate errors. |
82 typedef base::Callback<void(const TranslateErrorDetails&)> | 89 typedef base::Callback<void(const TranslateErrorDetails&)> |
83 TranslateErrorCallback; | 90 TranslateErrorCallback; |
84 typedef base::CallbackList<void(const TranslateErrorDetails&)> | 91 typedef base::CallbackList<void(const TranslateErrorDetails&)> |
85 TranslateErrorCallbackList; | 92 TranslateErrorCallbackList; |
86 | 93 |
87 // Registers a callback for translate errors. | 94 // Registers a callback for translate errors. |
88 static scoped_ptr<TranslateErrorCallbackList::Subscription> | 95 static scoped_ptr<TranslateErrorCallbackList::Subscription> |
89 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); | 96 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); |
90 | 97 |
98 LanguageState& GetLanguageState(); | |
99 | |
91 private: | 100 private: |
92 // Sends a translation request to the TranslateDriver. | 101 // Sends a translation request to the TranslateDriver. |
93 void DoTranslatePage(const std::string& translate_script, | 102 void DoTranslatePage(const std::string& translate_script, |
94 const std::string& source_lang, | 103 const std::string& source_lang, |
95 const std::string& target_lang); | 104 const std::string& target_lang); |
96 | 105 |
97 // Called when the Translate script has been fetched. | 106 // Called when the Translate script has been fetched. |
98 // Initiates the translation. | 107 // Initiates the translation. |
99 void OnTranslateScriptFetchComplete(int page_id, | 108 void OnTranslateScriptFetchComplete(int page_id, |
100 const std::string& source_lang, | 109 const std::string& source_lang, |
101 const std::string& target_lang, | 110 const std::string& target_lang, |
102 bool success, | 111 bool success, |
103 const std::string& data); | 112 const std::string& data); |
104 | 113 |
105 // Preference name for the Accept-Languages HTTP header. | 114 // Preference name for the Accept-Languages HTTP header. |
106 std::string accept_languages_pref_name_; | 115 std::string accept_languages_pref_name_; |
107 | 116 |
108 TranslateClient* translate_client_; // Weak. | 117 TranslateClient* translate_client_; // Weak. |
109 TranslateDriver* translate_driver_; // Weak. | 118 TranslateDriver* translate_driver_; // Weak. |
110 | 119 |
120 LanguageState language_state_; | |
121 | |
111 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 122 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
112 | 123 |
113 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 124 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
114 }; | 125 }; |
115 | 126 |
116 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ | 127 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ |
OLD | NEW |