• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/memory/singleton.h"
12 #include "third_party/cros/chromeos_login.h"
13 
14 namespace chromeos {
15 
16 // This interface defines the interaction with the ChromeOS login library APIs.
17 class LoginLibrary {
18  public:
19   class Delegate {
20    public:
21     virtual void OnComplete(bool value) = 0;
22   };
23 
~LoginLibrary()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   virtual void RequestRetrievePolicy(RetrievePolicyCallback callback,
36                                      void* delegate_string) = 0;
37 
38   // Start fetch the value associated with |name|, if its present.
39   // When fetching is done/failed, |callback| is called to pass back the fetch
40   // results. If fetching is successful, |callback| will be called with
41   // true for |success| and property's name, value and signature filled in
42   // Property struct. Otherwise, |success| would be false.
43   virtual void RequestRetrieveProperty(const std::string& name,
44                                        RetrievePropertyCallback callback,
45                                        void* user_data) = 0;
46 
47   virtual void RequestStorePolicy(const std::string& policy,
48                                   StorePolicyCallback callback,
49                                   void* delegate_bool) = 0;
50 
51   // Attempts to issue a signed async request to store |name|=|value|.
52   // |signature| must by a SHA1 with RSA encryption signature over the string
53   // "name=value" with the owner's private key.
54   //  Returns true if the attempt was successfully started.
55   //  callback->Run() will be called when the operation is complete.
56   virtual bool StorePropertyAsync(const std::string& name,
57                                   const std::string& value,
58                                   const std::vector<uint8>& signature,
59                                   Delegate* callback) = 0;
60 
61   // Attempts to issue a signed async request to whitelist |email|.
62   // |signature| must by a SHA1 with RSA encryption signature over |email|
63   // with the owner's private key.
64   //  Returns true if the attempt was successfully started.
65   //  callback->Run() will be called when the operation is complete.
66   virtual bool WhitelistAsync(const std::string& email,
67                               const std::vector<uint8>& signature,
68                               Delegate* callback) = 0;
69 
70   // Attempts to issue a signed async request to remove |email| from the
71   // whitelist of users allowed to log in to this machine.
72   // |signature| must by a SHA1 with RSA encryption signature over |email|
73   // with the owner's private key.
74   //  Returns true if the attempt was successfully started.
75   //  callback->Run() will be called when the operation is complete.
76   virtual bool UnwhitelistAsync(const std::string& email,
77                                 const std::vector<uint8>& signature,
78                                 Delegate* callback) = 0;
79 
80   // DEPRECATED.  We have re-implemented owner-signed settings by fetching
81   // and caching a policy, and then pulling values from there.  This is all
82   // handled at the SignedSettings layer, so anyone using this stuff directly
83   // should not be doing so anymore.
84   //
85   // Retrieves the user white list. Note the call is for display purpose only.
86   // To determine if an email is white listed, you MUST use CheckWhitelist.
87   //  Returns true if the request is successfully dispatched.
88   virtual bool EnumerateWhitelisted(std::vector<std::string>* whitelisted) = 0;
89 
90   // Tells the session manager to start a logged-in session for the user
91   // |user_email|.  |unique_id| is meant to be used when we have a non-human-
92   // readable unique identifier by which we distinguish users (to deal with
93   // potential email address changes over time).
94   virtual bool StartSession(const std::string& user_email,
95                             const std::string& unique_id /* unused */) = 0;
96 
97   // Tells the session manager to terminate the current logged-in session.
98   // In the event that we ever support multiple simultaneous user sessions,
99   // This will tell the session manager to terminate the session for the user
100   // indicated by |unique_id|.
101   virtual bool StopSession(const std::string& unique_id /* unused */) = 0;
102 
103   // Restarts the Enterprise Daemon.
104   virtual bool RestartEntd() = 0;
105 
106   // Restarts the job with specified command line string.
107   virtual bool RestartJob(int pid, const std::string& command_line) = 0;
108 
109   // Factory function, creates a new instance and returns ownership.
110   // For normal usage, access the singleton via CrosLibrary::Get().
111   static LoginLibrary* GetImpl(bool stub);
112 };
113 
114 }  // namespace chromeos
115 
116 #endif  // CHROME_BROWSER_CHROMEOS_CROS_LOGIN_LIBRARY_H_
117