blob: 9fb0fb62e51242346b5fca1b9dc16838536b1e68 [file] [log] [blame]
grtc291eea2016-05-26 15:38:481// 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 Monette7ff99e02018-02-19 17:30:1210#include <memory>
11
grtc291eea2016-05-26 15:38:4812#include "base/macros.h"
13#include "base/memory/weak_ptr.h"
Patrick Monettecd3195b2017-06-29 00:23:1314#include "base/sequence_checker.h"
grtc291eea2016-05-26 15:38:4815#include "base/strings/string16.h"
grtc291eea2016-05-26 15:38:4816
Patrick Monette7ff99e02018-02-19 17:30:1217class AutomationController;
grtc291eea2016-05-26 15:38:4818
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.
24class SettingsAppMonitor {
25 public:
26 class Delegate {
27 public:
Patrick Monette7ff99e02018-02-19 17:30:1228 virtual ~Delegate() = default;
grtc291eea2016-05-26 15:38:4829
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;
pmonetteb66514b42016-12-07 20:28:3943
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;
grtc291eea2016-05-26 15:38:4849 };
50
51 // |delegate| must outlive the monitor.
52 explicit SettingsAppMonitor(Delegate* delegate);
53 ~SettingsAppMonitor();
54
55 private:
Patrick Monette7ff99e02018-02-19 17:30:1256 class AutomationControllerDelegate;
grtc291eea2016-05-26 15:38:4857
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);
pmonetteb66514b42016-12-07 20:28:3963 void OnPromoFocused();
64 void OnPromoChoiceMade(bool accept_promo);
grtc291eea2016-05-26 15:38:4865
Patrick Monettecd3195b2017-06-29 00:23:1366 SEQUENCE_CHECKER(sequence_checker_);
Patrick Monette7ff99e02018-02-19 17:30:1267
grtc291eea2016-05-26 15:38:4868 Delegate* delegate_;
69
Patrick Monette7ff99e02018-02-19 17:30:1270 // Allows the use of the UI Automation API.
71 std::unique_ptr<AutomationController> automation_controller_;
grtc291eea2016-05-26 15:38:4872
Patrick Monette7ff99e02018-02-19 17:30:1273 // Weak pointers are passed to the AutomationControllerDelegate so that it can
74 // safely call back the monitor from any thread.
grtc291eea2016-05-26 15:38:4875 base::WeakPtrFactory<SettingsAppMonitor> weak_ptr_factory_;
76
77 DISALLOW_COPY_AND_ASSIGN(SettingsAppMonitor);
78};
79
grtc291eea2016-05-26 15:38:4880#endif // CHROME_BROWSER_WIN_SETTINGS_APP_MONITOR_H_