grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 1 | // Copyright 2016 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_WIN_SETTINGS_APP_MONITOR_H_ |
| 6 | #define CHROME_BROWSER_WIN_SETTINGS_APP_MONITOR_H_ |
| 7 | |
| 8 | #include <windows.h> |
| 9 | |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 12 | #include "base/macros.h" |
| 13 | #include "base/memory/weak_ptr.h" |
Patrick Monette | cd3195b | 2017-06-29 00:23:13 | [diff] [blame] | 14 | #include "base/sequence_checker.h" |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 15 | #include "base/strings/string16.h" |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 16 | |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 17 | class AutomationController; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 18 | |
| 19 | // A monitor that watches the Windows Settings app and notifies a delegate of |
| 20 | // particularly interesting events. An asychronous initialization procedure is |
| 21 | // started at instance creation, after which the delegate's |OnInitialized| |
| 22 | // method is invoked. Following successful initilization, the monitor is ready |
| 23 | // to observe the Settings app. |
| 24 | class SettingsAppMonitor { |
| 25 | public: |
| 26 | class Delegate { |
| 27 | public: |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 28 | virtual ~Delegate() = default; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 29 | |
| 30 | // Invoked to indicate that initialization is complete. |result| indicates |
| 31 | // whether or not the operation succeeded and, if not, the reason for |
| 32 | // failure. |
| 33 | virtual void OnInitialized(HRESULT result) = 0; |
| 34 | |
| 35 | // Invoked when the Settings app has received keyboard focus. |
| 36 | virtual void OnAppFocused() = 0; |
| 37 | |
| 38 | // Invoked when the user has invoked the Web browser chooser. |
| 39 | virtual void OnChooserInvoked() = 0; |
| 40 | |
| 41 | // Invoked when the user has chosen a particular Web browser. |
| 42 | virtual void OnBrowserChosen(const base::string16& browser_name) = 0; |
pmonette | b66514b4 | 2016-12-07 20:28:39 | [diff] [blame] | 43 | |
| 44 | // Invoked when the Edge promo has received keyboard focus. |
| 45 | virtual void OnPromoFocused() = 0; |
| 46 | |
| 47 | // Invoked when the user interacts with the Edge promo. |
| 48 | virtual void OnPromoChoiceMade(bool accept_promo) = 0; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // |delegate| must outlive the monitor. |
| 52 | explicit SettingsAppMonitor(Delegate* delegate); |
| 53 | ~SettingsAppMonitor(); |
| 54 | |
| 55 | private: |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 56 | class AutomationControllerDelegate; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 57 | |
| 58 | // Methods for passing actions on to the instance's Delegate. |
| 59 | void OnInitialized(HRESULT result); |
| 60 | void OnAppFocused(); |
| 61 | void OnChooserInvoked(); |
| 62 | void OnBrowserChosen(const base::string16& browser_name); |
pmonette | b66514b4 | 2016-12-07 20:28:39 | [diff] [blame] | 63 | void OnPromoFocused(); |
| 64 | void OnPromoChoiceMade(bool accept_promo); |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 65 | |
Patrick Monette | cd3195b | 2017-06-29 00:23:13 | [diff] [blame] | 66 | SEQUENCE_CHECKER(sequence_checker_); |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 67 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 68 | Delegate* delegate_; |
| 69 | |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 70 | // Allows the use of the UI Automation API. |
| 71 | std::unique_ptr<AutomationController> automation_controller_; |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 72 | |
Patrick Monette | 7ff99e0 | 2018-02-19 17:30:12 | [diff] [blame] | 73 | // Weak pointers are passed to the AutomationControllerDelegate so that it can |
| 74 | // safely call back the monitor from any thread. |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 75 | base::WeakPtrFactory<SettingsAppMonitor> weak_ptr_factory_; |
| 76 | |
| 77 | DISALLOW_COPY_AND_ASSIGN(SettingsAppMonitor); |
| 78 | }; |
| 79 | |
grt | c291eea | 2016-05-26 15:38:48 | [diff] [blame] | 80 | #endif // CHROME_BROWSER_WIN_SETTINGS_APP_MONITOR_H_ |