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_CHROMEOS_EXTENSIONS_QUICK_UNLOCK_PRIVATE_QUICK_UNLOCK_PRI
VATE_API_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_QUICK_UNLOCK_PRIVATE_QUICK_UNLOCK_PRI
VATE_API_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
| 11 #include "chrome/common/extensions/api/quick_unlock_private.h" |
| 12 #include "chromeos/login/auth/auth_status_consumer.h" |
| 13 #include "extensions/browser/extension_function.h" |
| 14 |
| 15 namespace chromeos { |
| 16 class ExtendedAuthenticator; |
| 17 } |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 class QuickUnlockPrivateGetAvailableModesFunction |
| 22 : public UIThreadExtensionFunction { |
| 23 public: |
| 24 QuickUnlockPrivateGetAvailableModesFunction(); |
| 25 DECLARE_EXTENSION_FUNCTION("quickUnlockPrivate.getAvailableModes", |
| 26 QUICKUNLOCKPRIVATE_GETAVAILABLEMODES); |
| 27 |
| 28 protected: |
| 29 ~QuickUnlockPrivateGetAvailableModesFunction() override; |
| 30 |
| 31 // ExtensionFunction overrides. |
| 32 ResponseAction Run() override; |
| 33 |
| 34 private: |
| 35 ChromeExtensionFunctionDetails chrome_details_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(QuickUnlockPrivateGetAvailableModesFunction); |
| 38 }; |
| 39 |
| 40 class QuickUnlockPrivateGetActiveModesFunction |
| 41 : public UIThreadExtensionFunction { |
| 42 public: |
| 43 QuickUnlockPrivateGetActiveModesFunction(); |
| 44 DECLARE_EXTENSION_FUNCTION("quickUnlockPrivate.getActiveModes", |
| 45 QUICKUNLOCKPRIVATE_GETACTIVEMODES); |
| 46 |
| 47 protected: |
| 48 ~QuickUnlockPrivateGetActiveModesFunction() override; |
| 49 |
| 50 // ExtensionFunction overrides. |
| 51 ResponseAction Run() override; |
| 52 |
| 53 private: |
| 54 ChromeExtensionFunctionDetails chrome_details_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(QuickUnlockPrivateGetActiveModesFunction); |
| 57 }; |
| 58 |
| 59 class QuickUnlockPrivateSetModesFunction : public UIThreadExtensionFunction, |
| 60 public chromeos::AuthStatusConsumer { |
| 61 public: |
| 62 using AuthenticatorAllocator = |
| 63 base::Callback<chromeos::ExtendedAuthenticator*( |
| 64 chromeos::AuthStatusConsumer* auth_status_consumer)>; |
| 65 using QuickUnlockMode = |
| 66 extensions::api::quick_unlock_private::QuickUnlockMode; |
| 67 using ModesChangedEventHandler = |
| 68 base::Callback<void(const std::vector<QuickUnlockMode>&)>; |
| 69 |
| 70 QuickUnlockPrivateSetModesFunction(); |
| 71 |
| 72 // Use the given |allocator| to create an ExtendedAuthenticator instance. This |
| 73 // lets tests intercept authentication calls. |
| 74 void SetAuthenticatorAllocatorForTesting( |
| 75 const AuthenticatorAllocator& allocator); |
| 76 |
| 77 // The given event handler will be called whenever a |
| 78 // quickUnlockPrivate.onActiveModesChanged event is raised instead of the |
| 79 // default event handling mechanism. |
| 80 void SetModesChangedEventHandlerForTesting( |
| 81 const ModesChangedEventHandler& handler); |
| 82 |
| 83 DECLARE_EXTENSION_FUNCTION("quickUnlockPrivate.setModes", |
| 84 QUICKUNLOCKPRIVATE_SETMODES); |
| 85 |
| 86 protected: |
| 87 ~QuickUnlockPrivateSetModesFunction() override; |
| 88 |
| 89 // ExtensionFunction overrides. |
| 90 ResponseAction Run() override; |
| 91 |
| 92 // AuthStatusConsumer overrides. |
| 93 void OnAuthFailure(const chromeos::AuthFailure& error) override; |
| 94 void OnAuthSuccess(const chromeos::UserContext& user_context) override; |
| 95 |
| 96 void ApplyModeChange(); |
| 97 |
| 98 private: |
| 99 void FireEvent(const std::vector<QuickUnlockMode>& modes); |
| 100 |
| 101 ChromeExtensionFunctionDetails chrome_details_; |
| 102 scoped_refptr<chromeos::ExtendedAuthenticator> extended_authenticator_; |
| 103 std::unique_ptr<api::quick_unlock_private::SetModes::Params> params_; |
| 104 |
| 105 AuthenticatorAllocator authenticator_allocator_; |
| 106 ModesChangedEventHandler modes_changed_handler_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(QuickUnlockPrivateSetModesFunction); |
| 109 }; |
| 110 |
| 111 } // namespace extensions |
| 112 |
| 113 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_QUICK_UNLOCK_PRIVATE_QUICK_UNLOCK_
PRIVATE_API_H_ |
OLD | NEW |