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 |
25 // The TranslateManager class is responsible for showing an info-bar when a page | 26 // 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... |
81 // Callback types for translate errors. | 82 // Callback types for translate errors. |
82 typedef base::Callback<void(const TranslateErrorDetails&)> | 83 typedef base::Callback<void(const TranslateErrorDetails&)> |
83 TranslateErrorCallback; | 84 TranslateErrorCallback; |
84 typedef base::CallbackList<void(const TranslateErrorDetails&)> | 85 typedef base::CallbackList<void(const TranslateErrorDetails&)> |
85 TranslateErrorCallbackList; | 86 TranslateErrorCallbackList; |
86 | 87 |
87 // Registers a callback for translate errors. | 88 // Registers a callback for translate errors. |
88 static scoped_ptr<TranslateErrorCallbackList::Subscription> | 89 static scoped_ptr<TranslateErrorCallbackList::Subscription> |
89 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); | 90 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); |
90 | 91 |
| 92 // Gets the LanguageState associated with the TranslateManager |
| 93 LanguageState& GetLanguageState(); |
| 94 |
91 private: | 95 private: |
92 // Sends a translation request to the TranslateDriver. | 96 // Sends a translation request to the TranslateDriver. |
93 void DoTranslatePage(const std::string& translate_script, | 97 void DoTranslatePage(const std::string& translate_script, |
94 const std::string& source_lang, | 98 const std::string& source_lang, |
95 const std::string& target_lang); | 99 const std::string& target_lang); |
96 | 100 |
97 // Called when the Translate script has been fetched. | 101 // Called when the Translate script has been fetched. |
98 // Initiates the translation. | 102 // Initiates the translation. |
99 void OnTranslateScriptFetchComplete(int page_id, | 103 void OnTranslateScriptFetchComplete(int page_id, |
100 const std::string& source_lang, | 104 const std::string& source_lang, |
101 const std::string& target_lang, | 105 const std::string& target_lang, |
102 bool success, | 106 bool success, |
103 const std::string& data); | 107 const std::string& data); |
104 | 108 |
105 // Preference name for the Accept-Languages HTTP header. | 109 // Preference name for the Accept-Languages HTTP header. |
106 std::string accept_languages_pref_name_; | 110 std::string accept_languages_pref_name_; |
107 | 111 |
108 TranslateClient* translate_client_; // Weak. | 112 TranslateClient* translate_client_; // Weak. |
109 TranslateDriver* translate_driver_; // Weak. | 113 TranslateDriver* translate_driver_; // Weak. |
110 | 114 |
| 115 LanguageState language_state_; |
| 116 |
111 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 117 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
112 | 118 |
113 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 119 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
114 }; | 120 }; |
115 | 121 |
116 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ | 122 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_MANAGER_H_ |
OLD | NEW |