login_library.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2010 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_CROS_LOGIN_LIBRARY_H_
6#define CHROME_BROWSER_CHROMEOS_CROS_LOGIN_LIBRARY_H_
7#pragma once
8
9#include <string>
10
11#include "base/singleton.h"
12#include "third_party/cros/chromeos_login.h"
13
14namespace chromeos {
15
16// This interface defines the interaction with the ChromeOS login library APIs.
17class LoginLibrary {
18 public:
19  class Delegate {
20   public:
21    virtual void OnComplete(bool value) = 0;
22  };
23
24  virtual ~LoginLibrary() {}
25  // Requests that the Upstart signal login-prompt-ready be emitted.
26  virtual bool EmitLoginPromptReady() = 0;
27
28  // Check whether or not |email| is present on the whitelist.
29  // If so, we return true and store the signature passed when |email| was
30  // whitelisted in |OUT_signature|.
31  // If not, we return false and don't touch the output parameter.
32  virtual bool CheckWhitelist(const std::string& email,
33                              std::vector<uint8>* OUT_signature) = 0;
34
35  // Fetch the value associated with |name|, if its present.
36  // If so, we return true, store the info in |OUT_value|, and store the
37  // signature passed when the property was initially stored in |OUT_signature|.
38  // If not, we return false and don't touch the output parameters.
39  virtual bool RetrieveProperty(const std::string& name,
40                                std::string* OUT_value,
41                                std::vector<uint8>* OUT_signature) = 0;
42
43  // Attempts to issue a signed async request to store |name|=|value|.
44  // |signature| must by a SHA1 with RSA encryption signature over the string
45  // "name=value" with the owner's private key.
46  //  Returns true if the attempt was successfully started.
47  //  callback->Run() will be called when the operation is complete.
48  virtual bool StorePropertyAsync(const std::string& name,
49                                  const std::string& value,
50                                  const std::vector<uint8>& signature,
51                                  Delegate* callback) = 0;
52
53  // Attempts to issue a signed async request to whitelist |email|.
54  // |signature| must by a SHA1 with RSA encryption signature over |email|
55  // with the owner's private key.
56  //  Returns true if the attempt was successfully started.
57  //  callback->Run() will be called when the operation is complete.
58  virtual bool WhitelistAsync(const std::string& email,
59                              const std::vector<uint8>& signature,
60                              Delegate* callback) = 0;
61
62  // Attempts to issue a signed async request to remove |email| from the
63  // whitelist of users allowed to log in to this machine.
64  // |signature| must by a SHA1 with RSA encryption signature over |email|
65  // with the owner's private key.
66  //  Returns true if the attempt was successfully started.
67  //  callback->Run() will be called when the operation is complete.
68  virtual bool UnwhitelistAsync(const std::string& email,
69                                const std::vector<uint8>& signature,
70                                Delegate* callback) = 0;
71
72  // Retrieves the user white list. Note the call is for display purpose only.
73  // To determine if an email is white listed, you MUST use CheckWhitelist.
74  //  Returns true if the request is successfully dispatched.
75  virtual bool EnumerateWhitelisted(std::vector<std::string>* whitelisted) = 0;
76
77  // Tells the session manager to start a logged-in session for the user
78  // |user_email|.  |unique_id| is meant to be used when we have a non-human-
79  // readable unique identifier by which we distinguish users (to deal with
80  // potential email address changes over time).
81  virtual bool StartSession(const std::string& user_email,
82                            const std::string& unique_id /* unused */) = 0;
83
84  // Tells the session manager to terminate the current logged-in session.
85  // In the event that we ever support multiple simultaneous user sessions,
86  // This will tell the session manager to terminate the session for the user
87  // indicated by |unique_id|.
88  virtual bool StopSession(const std::string& unique_id /* unused */) = 0;
89
90  // Restarts the Enterprise Daemon.
91  virtual bool RestartEntd() = 0;
92
93  // Restarts the job with specified command line string.
94  virtual bool RestartJob(int pid, const std::string& command_line) = 0;
95
96  // Factory function, creates a new instance and returns ownership.
97  // For normal usage, access the singleton via CrosLibrary::Get().
98  static LoginLibrary* GetImpl(bool stub);
99};
100
101}  // namespace chromeos
102
103#endif  // CHROME_BROWSER_CHROMEOS_CROS_LOGIN_LIBRARY_H_
104