| OLD | NEW |
| (Empty) | |
| 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 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_piece.h" |
| 15 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_checker.h" |
| 17 |
| 18 namespace shell_integration { |
| 19 namespace win { |
| 20 |
| 21 // A monitor that watches the Windows Settings app and notifies a delegate of |
| 22 // particularly interesting events. An asychronous initialization procedure is |
| 23 // started at instance creation, after which the delegate's |OnInitialized| |
| 24 // method is invoked. Following successful initilization, the monitor is ready |
| 25 // to observe the Settings app. |
| 26 class SettingsAppMonitor { |
| 27 public: |
| 28 class Delegate { |
| 29 public: |
| 30 virtual ~Delegate() {} |
| 31 |
| 32 // Invoked to indicate that initialization is complete. |result| indicates |
| 33 // whether or not the operation succeeded and, if not, the reason for |
| 34 // failure. |
| 35 virtual void OnInitialized(HRESULT result) = 0; |
| 36 |
| 37 // Invoked when the Settings app has received keyboard focus. |
| 38 virtual void OnAppFocused() = 0; |
| 39 |
| 40 // Invoked when the user has invoked the Web browser chooser. |
| 41 virtual void OnChooserInvoked() = 0; |
| 42 |
| 43 // Invoked when the user has chosen a particular Web browser. |
| 44 virtual void OnBrowserChosen(const base::string16& browser_name) = 0; |
| 45 }; |
| 46 |
| 47 // |delegate| must outlive the monitor. |
| 48 explicit SettingsAppMonitor(Delegate* delegate); |
| 49 ~SettingsAppMonitor(); |
| 50 |
| 51 private: |
| 52 class Context; |
| 53 |
| 54 // Methods for passing actions on to the instance's Delegate. |
| 55 void OnInitialized(HRESULT result); |
| 56 void OnAppFocused(); |
| 57 void OnChooserInvoked(); |
| 58 void OnBrowserChosen(const base::string16& browser_name); |
| 59 |
| 60 base::ThreadChecker thread_checker_; |
| 61 Delegate* delegate_; |
| 62 |
| 63 // A thread in the COM MTA in which automation calls are made. |
| 64 base::Thread automation_thread_; |
| 65 |
| 66 // A pointer to the context object that lives on the automation thread. |
| 67 base::WeakPtr<Context> context_; |
| 68 |
| 69 // A factory for the weak pointer handed to |context_|, through which |
| 70 // notifications to the delegate are passed. |
| 71 base::WeakPtrFactory<SettingsAppMonitor> weak_ptr_factory_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(SettingsAppMonitor); |
| 74 }; |
| 75 |
| 76 } // namespace win |
| 77 } // namespace shell_integration |
| 78 |
| 79 #endif // CHROME_BROWSER_WIN_SETTINGS_APP_MONITOR_H_ |
| OLD | NEW |