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

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

Issue 2894553002: Replace OnPageTranslate Obsever by a responder of delegate. (Closed)
Patch Set: fix Created 3 years, 7 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
OLDNEW
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_INFOBAR_DELEGATE_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 19 matching lines...) Expand all
30 namespace translate { 30 namespace translate {
31 31
32 // Feature flag for "Translate Compact Infobar UI" project. 32 // Feature flag for "Translate Compact Infobar UI" project.
33 extern const base::Feature kTranslateCompactUI; 33 extern const base::Feature kTranslateCompactUI;
34 34
35 class TranslateDriver; 35 class TranslateDriver;
36 class TranslateManager; 36 class TranslateManager;
37 37
38 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { 38 class TranslateInfoBarDelegate : public infobars::InfoBarDelegate {
39 public: 39 public:
40 // A responder to handle different translate steps' UI changes.
groby-ooo-7-16 2017/05/20 21:30:39 If I remember correctly, you don't need this class
Leo 2017/05/21 04:15:20 I think the fact you described is the original lo
41 class Responder {
groby-ooo-7-16 2017/05/20 21:30:39 We usually call those "Observer"
Leo 2017/05/22 09:08:10 Thanks for questioning the class name, I have stru
42 public:
43 // Handles UI changes on the translate step given.
44 virtual void ActionOnStep(translate::TranslateStep step,
groby-ooo-7-16 2017/05/20 21:30:39 Suggested name: OnTranslateStepChanged() That's c
Leo 2017/05/22 09:08:10 Thanks, Done.
45 TranslateErrors::Type error_type){};
46 // Return whether user declined translate service.
groby-ooo-7-16 2017/05/20 21:30:39 Does "declined" include dismissing the infobar, or
Leo 2017/05/22 09:08:10 "declined" here is just a flag used to evaluate us
groby-ooo-7-16 2017/05/22 14:34:11 Thank you - the reason I asked was that we use "De
47 virtual bool Declined();
48
49 protected:
50 virtual ~Responder() {}
51 };
52
40 static const size_t kNoIndex; 53 static const size_t kNoIndex;
41 54
42 ~TranslateInfoBarDelegate() override; 55 ~TranslateInfoBarDelegate() override;
43 56
44 // Factory method to create a translate infobar. |error_type| must be 57 // Factory method to create a translate infobar. |error_type| must be
45 // specified iff |step| == TRANSLATION_ERROR. For other translate steps, 58 // specified iff |step| == TRANSLATION_ERROR. For other translate steps,
46 // |original_language| and |target_language| must be ASCII language codes 59 // |original_language| and |target_language| must be ASCII language codes
47 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports 60 // (e.g. "en", "fr", etc.) for languages the TranslateManager supports
48 // translating. The lone exception is when the user initiates translation 61 // translating. The lone exception is when the user initiates translation
49 // from the context menu, in which case it's legal to call this with 62 // from the context menu, in which case it's legal to call this with
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // been translate to <lang2> from <lang1>."). It is ignored if 188 // been translate to <lang2> from <lang1>."). It is ignored if
176 // |autodetermined_source_language| is true. 189 // |autodetermined_source_language| is true.
177 static void GetAfterTranslateStrings(std::vector<base::string16>* strings, 190 static void GetAfterTranslateStrings(std::vector<base::string16>* strings,
178 bool* swap_languages, 191 bool* swap_languages,
179 bool autodetermined_source_language); 192 bool autodetermined_source_language);
180 193
181 // Gets the TranslateDriver associated with this object. 194 // Gets the TranslateDriver associated with this object.
182 // May return NULL if the driver has been destroyed. 195 // May return NULL if the driver has been destroyed.
183 TranslateDriver* GetTranslateDriver(); 196 TranslateDriver* GetTranslateDriver();
184 197
198 // Set a responder.
199 void SetResponder(Responder* responder);
200
185 protected: 201 protected:
186 TranslateInfoBarDelegate( 202 TranslateInfoBarDelegate(
187 const base::WeakPtr<TranslateManager>& translate_manager, 203 const base::WeakPtr<TranslateManager>& translate_manager,
188 bool is_off_the_record, 204 bool is_off_the_record,
189 translate::TranslateStep step, 205 translate::TranslateStep step,
190 const std::string& original_language, 206 const std::string& original_language,
191 const std::string& target_language, 207 const std::string& target_language,
192 TranslateErrors::Type error_type, 208 TranslateErrors::Type error_type,
193 bool triggered_from_menu); 209 bool triggered_from_menu);
194 210
(...skipping 17 matching lines...) Expand all
212 // The error that occurred when trying to translate (NONE if no error). 228 // The error that occurred when trying to translate (NONE if no error).
213 TranslateErrors::Type error_type_; 229 TranslateErrors::Type error_type_;
214 230
215 // The translation related preferences. 231 // The translation related preferences.
216 std::unique_ptr<TranslatePrefs> prefs_; 232 std::unique_ptr<TranslatePrefs> prefs_;
217 233
218 // Whether the translation was triggered via a menu click vs automatically 234 // Whether the translation was triggered via a menu click vs automatically
219 // (due to language detection, preferences...) 235 // (due to language detection, preferences...)
220 bool triggered_from_menu_; 236 bool triggered_from_menu_;
221 237
238 // A responder to handle front-end changes on different steps.
239 // It's only used when we try to reuse the existing UI.
240 Responder* responder_;
241
222 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); 242 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate);
223 }; 243 };
224 244
225 } // namespace translate 245 } // namespace translate
226 246
227 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ 247 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698