Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chromeos / process_proxy / process_proxy_registry.h
blob4280ebd2d2d39c22e3787f79fc9035713f6185ef
1 // Copyright (c) 2012 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.
5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
6 #define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
8 #include <map>
10 #include "base/callback.h"
11 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/threading/thread.h"
16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/process_proxy/process_proxy.h"
19 namespace chromeos {
21 typedef base::Callback<void(pid_t, const std::string&, const std::string&)>
22 ProcessOutputCallbackWithPid;
24 // Keeps track of all created ProcessProxies. It is created lazily and should
25 // live on a single thread (where all methods must be called).
26 class CHROMEOS_EXPORT ProcessProxyRegistry : public base::NonThreadSafe {
27 public:
28 // Info we need about a ProcessProxy instance.
29 struct ProcessProxyInfo {
30 scoped_refptr<ProcessProxy> proxy;
31 scoped_ptr<base::Thread> watcher_thread;
32 ProcessOutputCallbackWithPid callback;
33 pid_t process_id;
35 ProcessProxyInfo();
36 // This is to make map::insert happy, we don't init anything.
37 ProcessProxyInfo(const ProcessProxyInfo& other);
38 ~ProcessProxyInfo();
41 static ProcessProxyRegistry* Get();
43 // Starts new ProcessProxy (which starts new process).
44 bool OpenProcess(const std::string& command, pid_t* pid,
45 const ProcessOutputCallbackWithPid& callback);
46 // Sends data to the process with id |pid|.
47 bool SendInput(pid_t pid, const std::string& data);
48 // Stops the process with id |pid|.
49 bool CloseProcess(pid_t pid);
50 // Reports terminal resize to process proxy.
51 bool OnTerminalResize(pid_t pid, int width, int height);
53 // Currently used for testing.
54 void SetOutputCallback(const ProcessOutputCallback& callback);
56 private:
57 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>;
59 ProcessProxyRegistry();
60 ~ProcessProxyRegistry();
62 // Gets called when output gets detected.
63 void OnProcessOutput(pid_t pid,
64 ProcessOutputType type,
65 const std::string& data);
67 // Map of all existing ProcessProxies.
68 std::map<pid_t, ProcessProxyInfo> proxy_map_;
70 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry);
73 } // namespace chromeos
75 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_