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

Side by Side Diff: chrome/browser/ui/android/infobars/translate_compact_infobar.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ 5 #ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_
6 #define CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ 6 #define CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_
7 7
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "chrome/browser/translate/chrome_translate_client.h" 10 #include "chrome/browser/translate/chrome_translate_client.h"
11 #include "chrome/browser/ui/android/infobars/infobar_android.h" 11 #include "chrome/browser/ui/android/infobars/infobar_android.h"
12 #include "components/translate/content/browser/content_translate_driver.h" 12 #include "components/translate/core/browser/translate_infobar_delegate.h"
13 #include "components/translate/core/browser/translate_step.h"
14 #include "components/translate/core/common/translate_errors.h"
13 15
14 namespace translate { 16 namespace translate {
15 class TranslateInfoBarDelegate; 17 class TranslateInfoBarDelegate;
16 } 18 }
17 19
18 class TranslateCompactInfoBar 20 class TranslateCompactInfoBar
19 : public InfoBarAndroid, 21 : public InfoBarAndroid,
20 public translate::ContentTranslateDriver::Observer { 22 public translate::TranslateInfoBarDelegate::Responder {
21 public: 23 public:
22 explicit TranslateCompactInfoBar( 24 explicit TranslateCompactInfoBar(
23 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate); 25 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate);
24 ~TranslateCompactInfoBar() override; 26 ~TranslateCompactInfoBar() override;
25 27
26 // JNI method specific to string settings in translate. 28 // JNI method specific to string settings in translate.
27 void ApplyStringTranslateOption( 29 void ApplyStringTranslateOption(
28 JNIEnv* env, 30 JNIEnv* env,
29 const base::android::JavaParamRef<jobject>& obj, 31 const base::android::JavaParamRef<jobject>& obj,
30 int option, 32 int option,
31 const base::android::JavaParamRef<jstring>& value); 33 const base::android::JavaParamRef<jstring>& value);
32 34
33 // JNI method specific to boolean settings in translate. 35 // JNI method specific to boolean settings in translate.
34 void ApplyBoolTranslateOption(JNIEnv* env, 36 void ApplyBoolTranslateOption(JNIEnv* env,
35 const base::android::JavaParamRef<jobject>& obj, 37 const base::android::JavaParamRef<jobject>& obj,
36 int option, 38 int option,
37 jboolean value); 39 jboolean value);
38 40
39 // Check whether we should automatically trigger "Always Translate". 41 // Check whether we should automatically trigger "Always Translate".
40 bool ShouldAutoAlwaysTranslate(); 42 bool ShouldAutoAlwaysTranslate();
41 43
42 // Check whether we should automatically trigger "Never Translate Language". 44 // Check whether we should automatically trigger "Never Translate Language".
43 jboolean ShouldAutoNeverTranslate( 45 jboolean ShouldAutoNeverTranslate(
44 JNIEnv* env, 46 JNIEnv* env,
45 const base::android::JavaParamRef<jobject>& obj); 47 const base::android::JavaParamRef<jobject>& obj);
46 48
47 // ContentTranslateDriver::Observer implementation. 49 // TranslateInfoBarDelegate::Responder implementation.
48 void OnPageTranslated(const std::string& original_lang, 50 void ActionOnStep(translate::TranslateStep step,
groby-ooo-7-16 2017/05/20 21:30:39 Who is notifying the ContentTranslateDriver now?
Leo 2017/05/21 04:15:20 This method is used when ContentTranslateDriver fi
49 const std::string& translated_lang, 51 translate::TranslateErrors::Type error_type) override;
50 translate::TranslateErrors::Type error_type) override; 52 bool Declined() override;
51 53
52 private: 54 private:
53 // InfoBarAndroid: 55 // InfoBarAndroid:
54 base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar( 56 base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
55 JNIEnv* env) override; 57 JNIEnv* env) override;
56 void ProcessButton(int action) override; 58 void ProcessButton(int action) override;
57 void SetJavaInfoBar( 59 void SetJavaInfoBar(
58 const base::android::JavaRef<jobject>& java_info_bar) override; 60 const base::android::JavaRef<jobject>& java_info_bar) override;
59 61
60 translate::TranslateInfoBarDelegate* GetDelegate(); 62 translate::TranslateInfoBarDelegate* GetDelegate();
61 translate::ContentTranslateDriver* translate_driver_; 63
64 // Bits for trace user actions.
65 unsigned int action_flags_;
groby-ooo-7-16 2017/05/20 21:30:39 This should be of type ActionFlag if you use the e
napper 2017/05/21 23:24:16 I think the int type is correct here, since the en
Leo 2017/05/22 09:08:10 After a little discuss offline with Jon. Seems the
groby-ooo-7-16 2017/05/22 14:34:11 You are of course right about the int - sorry abou
groby-ooo-7-16 2017/05/22 14:34:11 No need to refactor if it introduces many other is
66
67 // User action flags to record what the user has done in each session.
68 enum ActionFlag {
69 FLAG_NONE = 0,
70 FLAG_TRANSLATE = 1 << 0,
71 FLAG_REVERT = 1 << 1,
72 FLAG_ALWAYS_TRANSLATE = 1 << 2,
73 FLAG_NEVER_LANGUAGE = 1 << 3,
74 FLAG_NEVER_SITE = 1 << 4,
75 };
62 76
63 // If number of consecutive translations is equal to this number, infobar will 77 // If number of consecutive translations is equal to this number, infobar will
64 // automatically trigger "Always Translate". 78 // automatically trigger "Always Translate".
65 const int kAcceptCountThreshold = 5; 79 const int kAcceptCountThreshold = 5;
66 // If number of consecutive denied is equal to this number, infobar will 80 // If number of consecutive denied is equal to this number, infobar will
67 // automatically trigger "Never Translate Language". 81 // automatically trigger "Never Translate Language".
68 const int kDeniedCountThreshold = 7; 82 const int kDeniedCountThreshold = 7;
69 83
70 DISALLOW_COPY_AND_ASSIGN(TranslateCompactInfoBar); 84 DISALLOW_COPY_AND_ASSIGN(TranslateCompactInfoBar);
71 }; 85 };
72 86
73 // Registers the native methods through JNI. 87 // Registers the native methods through JNI.
74 bool RegisterTranslateCompactInfoBar(JNIEnv* env); 88 bool RegisterTranslateCompactInfoBar(JNIEnv* env);
75 89
76 #endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_ 90 #endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_TRANSLATE_COMPACT_INFOBAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698