1// Copyright 2013 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_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_
6#define CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_
7
8#include <string>
9
10#include "chrome/browser/extensions/chrome_extension_function.h"
11#include "chrome/browser/signin/screenlock_bridge.h"
12#include "extensions/browser/browser_context_keyed_api_factory.h"
13
14namespace extensions {
15
16class ScreenlockPrivateGetLockedFunction : public ChromeAsyncExtensionFunction {
17 public:
18  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getLocked",
19                             SCREENLOCKPRIVATE_GETLOCKED)
20  ScreenlockPrivateGetLockedFunction();
21  virtual bool RunAsync() OVERRIDE;
22
23 private:
24  virtual ~ScreenlockPrivateGetLockedFunction();
25  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetLockedFunction);
26};
27
28class ScreenlockPrivateSetLockedFunction : public ChromeAsyncExtensionFunction {
29 public:
30  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setLocked",
31                             SCREENLOCKPRIVATE_SETLOCKED)
32  ScreenlockPrivateSetLockedFunction();
33  virtual bool RunAsync() OVERRIDE;
34
35 private:
36  virtual ~ScreenlockPrivateSetLockedFunction();
37  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction);
38};
39
40class ScreenlockPrivateAcceptAuthAttemptFunction
41    : public ChromeSyncExtensionFunction {
42 public:
43  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.acceptAuthAttempt",
44                             SCREENLOCKPRIVATE_ACCEPTAUTHATTEMPT)
45  ScreenlockPrivateAcceptAuthAttemptFunction();
46  virtual bool RunSync() OVERRIDE;
47
48 private:
49  virtual ~ScreenlockPrivateAcceptAuthAttemptFunction();
50  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction);
51};
52
53class ScreenlockPrivateEventRouter : public extensions::BrowserContextKeyedAPI,
54                                     public ScreenlockBridge::Observer {
55 public:
56  explicit ScreenlockPrivateEventRouter(content::BrowserContext* context);
57  virtual ~ScreenlockPrivateEventRouter();
58
59  bool OnAuthAttempted(ScreenlockBridge::LockHandler::AuthType auth_type,
60                       const std::string& value);
61
62  // BrowserContextKeyedAPI
63  static extensions::BrowserContextKeyedAPIFactory<
64      ScreenlockPrivateEventRouter>*
65      GetFactoryInstance();
66  virtual void Shutdown() OVERRIDE;
67
68  // ScreenlockBridge::Observer
69  virtual void OnScreenDidLock() OVERRIDE;
70  virtual void OnScreenDidUnlock() OVERRIDE;
71  virtual void OnFocusedUserChanged(const std::string& user_id) OVERRIDE;
72
73 private:
74  friend class extensions::BrowserContextKeyedAPIFactory<
75      ScreenlockPrivateEventRouter>;
76
77  // BrowserContextKeyedAPI
78  static const char* service_name() {
79    return "ScreenlockPrivateEventRouter";
80  }
81  static const bool kServiceIsNULLWhileTesting = true;
82  static const bool kServiceRedirectedInIncognito = true;
83
84  void DispatchEvent(const std::string& event_name, base::Value* arg);
85
86  content::BrowserContext* browser_context_;
87  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateEventRouter);
88};
89
90}  // namespace extensions
91
92#endif  // CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_
93