1 // Copyright 2018 The Chromium Authors. All rights reserved.
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_CHROMEOS_LOGIN_SCREENS_MARKETING_OPT_IN_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_MARKETING_OPT_IN_SCREEN_H_
7 
8 #include <memory>
9 #include <unordered_set>
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/login/screens/base_screen.h"
15 #include "components/prefs/pref_change_registrar.h"
16 
17 namespace chromeos {
18 
19 class MarketingOptInScreenView;
20 
21 // This is Sync settings screen that is displayed as a part of user first
22 // sign-in flow.
23 class MarketingOptInScreen : public BaseScreen {
24  public:
25   using TView = MarketingOptInScreenView;
26 
27   enum class Result { NEXT, NOT_APPLICABLE };
28 
29   // These values are persisted to logs. Entries should not be renumbered and
30   // numeric values should never be reused. Must coincide with the enum
31   // MarketingOptInScreenEvent
32   enum class Event {
33     kUserOptedInWhenDefaultIsOptIn = 0,
34     kUserOptedInWhenDefaultIsOptOut = 1,
35     kUserOptedOutWhenDefaultIsOptIn = 2,
36     kUserOptedOutWhenDefaultIsOptOut = 3,
37     kMaxValue = kUserOptedOutWhenDefaultIsOptOut,
38   };
39 
40   // Whether the geolocation resolve was successful.
41   // These values are persisted to logs. Entries should not be renumbered and
42   // numeric values should never be reused. Must coincide with the enum
43   // MarketingOptInScreenEvent
44   enum class GeolocationEvent {
45     kCouldNotDetermineCountry = 0,
46     kCountrySuccessfullyDetermined = 1,
47     kMaxValue = kCountrySuccessfullyDetermined,
48   };
49 
50   static std::string GetResultString(Result result);
51 
52   using ScreenExitCallback = base::RepeatingCallback<void(Result result)>;
53 
54   MarketingOptInScreen(MarketingOptInScreenView* view,
55                        const ScreenExitCallback& exit_callback);
56   ~MarketingOptInScreen() override;
57 
58   // On "Get Started" button pressed.
59   void OnGetStarted(bool chromebook_email_opt_in);
60 
61   void SetA11yButtonVisibilityForTest(bool shown);
62 
set_exit_callback_for_testing(const ScreenExitCallback & exit_callback)63   void set_exit_callback_for_testing(const ScreenExitCallback& exit_callback) {
64     exit_callback_ = exit_callback;
65   }
66 
get_exit_callback_for_testing()67   const ScreenExitCallback& get_exit_callback_for_testing() {
68     return exit_callback_;
69   }
70 
71  protected:
72   // BaseScreen:
73   bool MaybeSkip(WizardContext* context) override;
74   void ShowImpl() override;
75   void HideImpl() override;
76 
77  private:
78   void OnA11yShelfNavigationButtonPrefChanged();
79 
80   // Checks whether this user is managed.
81   bool IsCurrentUserManaged();
82 
83   // Sets the country to be used if the feature is available in this region.
84   void SetCountryFromTimezoneIfAvailable(const std::string& timezone_id);
85 
IsDefaultOptInCountry()86   bool IsDefaultOptInCountry() {
87     return default_opt_in_countries_.count(country_);
88   }
89 
90   MarketingOptInScreenView* const view_;
91   ScreenExitCallback exit_callback_;
92   std::unique_ptr<PrefChangeRegistrar> active_user_pref_change_registrar_;
93 
94   // Whether the email opt-in toggle is visible.
95   bool email_opt_in_visible_ = false;
96 
97   // Country code. Unknown IFF empty.
98   std::string country_;
99 
100   // Default country list.
101   const std::unordered_set<std::string> default_countries_{"us", "ca", "gb"};
102 
103   // Extended country list. Protected behind the flag:
104   // - kOobeMarketingAdditionalCountriesSupported (DEFAULT_ON)
105   const std::unordered_set<std::string> additional_countries_{
106       "fr", "nl", "fi", "se", "no", "dk", "es", "it", "jp", "au"};
107 
108   // Countries with double opt-in.  Behind the flag:
109   // - kOobeMarketingDoubleOptInCountriesSupported (DEFAULT_OFF)
110   const std::unordered_set<std::string> double_opt_in_countries_{"de"};
111 
112   // Countries in which the toggle will be enabled by default.
113   const std::unordered_set<std::string> default_opt_in_countries_{"us"};
114 
115   base::WeakPtrFactory<MarketingOptInScreen> weak_factory_{this};
116   DISALLOW_COPY_AND_ASSIGN(MarketingOptInScreen);
117 };
118 
119 }  // namespace chromeos
120 
121 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_MARKETING_OPT_IN_SCREEN_H_
122