Wenyu Fu | f358b90 | 2023-09-26 23:52:42 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_ANDROID_HATS_SURVEY_CLIENT_ANDROID_H_ |
| 6 | #define CHROME_BROWSER_UI_ANDROID_HATS_SURVEY_CLIENT_ANDROID_H_ |
| 7 | |
| 8 | #include <jni.h> |
Peter Kasting | a486324 | 2024-12-23 00:19:43 | [diff] [blame] | 9 | |
Wenyu Fu | f358b90 | 2023-09-26 23:52:42 | [diff] [blame] | 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "base/android/jni_android.h" |
| 14 | #include "base/functional/callback_helpers.h" |
Wenyu Fu | f358b90 | 2023-09-26 23:52:42 | [diff] [blame] | 15 | #include "chrome/browser/ui/android/hats/survey_ui_delegate_android.h" |
| 16 | #include "chrome/browser/ui/hats/survey_config.h" |
| 17 | |
| 18 | using base::android::JavaParamRef; |
| 19 | using base::android::JavaRef; |
| 20 | |
Antonio Gomes | 6309393 | 2025-05-21 17:57:08 | [diff] [blame] | 21 | class Profile; |
| 22 | |
Wenyu Fu | f358b90 | 2023-09-26 23:52:42 | [diff] [blame] | 23 | namespace ui { |
| 24 | class WindowAndroid; |
| 25 | } // namespace ui |
| 26 | |
| 27 | namespace hats { |
| 28 | |
| 29 | // Key-value mapping type for survey's product specific bits data. |
| 30 | typedef std::map<std::string, bool> SurveyBitsData; |
| 31 | |
| 32 | // Key-value mapping type for survey's product specific string data. |
| 33 | typedef std::map<std::string, std::string> SurveyStringData; |
| 34 | |
| 35 | // C++ equivalent of Java SurveyClient. |
| 36 | class SurveyClientAndroid { |
| 37 | public: |
Florian Jacky | 308b357 | 2024-01-22 10:00:54 | [diff] [blame] | 38 | explicit SurveyClientAndroid( |
| 39 | const std::string& trigger, |
| 40 | SurveyUiDelegateAndroid* ui_delegate, |
| 41 | Profile* profile, |
Kamil Jarosz | 15e087e | 2025-05-16 13:11:39 | [diff] [blame] | 42 | const std::optional<std::string>& supplied_trigger_id, |
| 43 | ui::WindowAndroid* window); |
Wenyu Fu | f358b90 | 2023-09-26 23:52:42 | [diff] [blame] | 44 | |
| 45 | SurveyClientAndroid(const SurveyClientAndroid&) = delete; |
| 46 | SurveyClientAndroid& operator=(const SurveyClientAndroid&) = delete; |
| 47 | |
| 48 | ~SurveyClientAndroid(); |
| 49 | |
| 50 | // Launch the survey with identifier if appropriate. Similar interface to |
| 51 | // |HatsService::LaunchSurvey|. |
| 52 | void LaunchSurvey(ui::WindowAndroid* window, |
| 53 | const SurveyBitsData& product_specific_bits_data = {}, |
| 54 | const SurveyStringData& product_specific_string_data = {}); |
| 55 | |
| 56 | // Destroy the instance and clean up the dependencies. |
| 57 | void Destroy(); |
| 58 | |
| 59 | private: |
| 60 | std::unique_ptr<SurveyUiDelegateAndroid> ui_delegate_; |
| 61 | base::android::ScopedJavaGlobalRef<jobject> jobj_; |
| 62 | }; |
| 63 | |
| 64 | } // namespace hats |
| 65 | |
| 66 | #endif // CHROME_BROWSER_UI_ANDROID_HATS_SURVEY_CLIENT_ANDROID_H_ |