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" | |
17 #include "components/translate/core/common/translate_errors.h" | 16 #include "components/translate/core/common/translate_errors.h" |
18 | 17 |
19 class GURL; | 18 class GURL; |
20 class PrefService; | 19 class PrefService; |
21 class TranslateClient; | 20 class TranslateClient; |
22 class TranslateDriver; | 21 class TranslateDriver; |
23 class TranslatePrefs; | 22 class TranslatePrefs; |
24 struct TranslateErrorDetails; | 23 struct TranslateErrorDetails; |
25 | 24 |
26 // 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 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Callback types for translate errors. | 81 // Callback types for translate errors. |
83 typedef base::Callback<void(const TranslateErrorDetails&)> | 82 typedef base::Callback<void(const TranslateErrorDetails&)> |
84 TranslateErrorCallback; | 83 TranslateErrorCallback; |
85 typedef base::CallbackList<void(const TranslateErrorDetails&)> | 84 typedef base::CallbackList<void(const TranslateErrorDetails&)> |
86 TranslateErrorCallbackList; | 85 TranslateErrorCallbackList; |
87 | 86 |
88 // Registers a callback for translate errors. | 87 // Registers a callback for translate errors. |
89 static scoped_ptr<TranslateErrorCallbackList::Subscription> | 88 static scoped_ptr<TranslateErrorCallbackList::Subscription> |
90 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); | 89 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); |
91 | 90 |
92 // Gets the LanguageState associated with the TranslateManager | |
93 LanguageState& GetLanguageState(); | |
94 | |
95 private: | 91 private: |
96 // Sends a translation request to the TranslateDriver. | 92 // Sends a translation request to the TranslateDriver. |
97 void DoTranslatePage(const std::string& translate_script, | 93 void DoTranslatePage(const std::string& translate_script, |
98 const std::string& source_lang, | 94 const std::string& source_lang, |
99 const std::string& target_lang); | 95 const std::string& target_lang); |
100 | 96 |
101 // Called when the Translate script has been fetched. | 97 // Called when the Translate script has been fetched. |
102 // Initiates the translation. | 98 // Initiates the translation. |
103 void OnTranslateScriptFetchComplete(int page_id, | 99 void OnTranslateScriptFetchComplete(int page_id, |
104 const std::string& source_lang, | 100 const std::string& source_lang, |
105 const std::string& target_lang, | 101 const std::string& target_lang, |
106 bool success, | 102 bool success, |
107 const std::string& data); | 103 const std::string& data); |
108 | 104 |
109 // Preference name for the Accept-Languages HTTP header. | 105 // Preference name for the Accept-Languages HTTP header. |
110 std::string accept_languages_pref_name_; | 106 std::string accept_languages_pref_name_; |
111 | 107 |
112 TranslateClient* translate_client_; // Weak. | 108 TranslateClient* translate_client_; // Weak. |
113 TranslateDriver* translate_driver_; // Weak. | 109 TranslateDriver* translate_driver_; // Weak. |
114 | 110 |
115 LanguageState language_state_; | |
116 | |
117 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 111 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
118 | 112 |
119 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 113 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
120 }; | 114 }; |
121 | 115 |
122 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ | 116 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ |
OLD | NEW |