Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chromeos/process_proxy/process_proxy_registry.h

Issue 1258193002: User MessageLoopForIO::WatchFileDescriptor in proces_output_watcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ 5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
6 #define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ 6 #define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "chromeos/chromeos_export.h" 17 #include "chromeos/chromeos_export.h"
17 #include "chromeos/process_proxy/process_proxy.h" 18 #include "chromeos/process_proxy/process_proxy.h"
18 19
19 namespace chromeos { 20 namespace chromeos {
20 21
21 typedef base::Callback<void(pid_t, const std::string&, const std::string&)> 22 typedef base::Callback<void(pid_t, const std::string&, const std::string&)>
22 ProcessOutputCallbackWithPid; 23 ProcessOutputCallbackWithPid;
23 24
24 // Keeps track of all created ProcessProxies. It is created lazily and should 25 // 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 // live on a single thread (where all methods must be called).
26 class CHROMEOS_EXPORT ProcessProxyRegistry : public base::NonThreadSafe { 27 class CHROMEOS_EXPORT ProcessProxyRegistry : public base::NonThreadSafe {
27 public: 28 public:
28 // Info we need about a ProcessProxy instance. 29 // Info we need about a ProcessProxy instance.
29 struct ProcessProxyInfo { 30 struct ProcessProxyInfo {
30 scoped_refptr<ProcessProxy> proxy; 31 scoped_refptr<ProcessProxy> proxy;
31 scoped_ptr<base::Thread> watcher_thread;
32 ProcessOutputCallbackWithPid callback; 32 ProcessOutputCallbackWithPid callback;
33 pid_t process_id; 33 pid_t process_id;
34 34
35 ProcessProxyInfo(); 35 ProcessProxyInfo();
36 // This is to make map::insert happy, we don't init anything. 36 // This is to make map::insert happy, we don't init anything.
37 ProcessProxyInfo(const ProcessProxyInfo& other); 37 ProcessProxyInfo(const ProcessProxyInfo& other);
38 ~ProcessProxyInfo(); 38 ~ProcessProxyInfo();
39 }; 39 };
40 40
41 static ProcessProxyRegistry* Get(); 41 static ProcessProxyRegistry* Get();
42 42
43 // Starts new ProcessProxy (which starts new process). 43 // Starts new ProcessProxy (which starts new process).
44 bool OpenProcess(const std::string& command, pid_t* pid, 44 bool OpenProcess(const std::string& command, pid_t* pid,
45 const ProcessOutputCallbackWithPid& callback); 45 const ProcessOutputCallbackWithPid& callback);
46 // Sends data to the process with id |pid|. 46 // Sends data to the process with id |pid|.
47 bool SendInput(pid_t pid, const std::string& data); 47 bool SendInput(pid_t pid, const std::string& data);
48 // Stops the process with id |pid|. 48 // Stops the process with id |pid|.
49 bool CloseProcess(pid_t pid); 49 bool CloseProcess(pid_t pid);
50 // Reports terminal resize to process proxy. 50 // Reports terminal resize to process proxy.
51 bool OnTerminalResize(pid_t pid, int width, int height); 51 bool OnTerminalResize(pid_t pid, int width, int height);
52 52
53 // Shuts down registry, closing all associated processed.
54 void ShutDown();
55
53 // Currently used for testing. 56 // Currently used for testing.
54 void SetOutputCallback(const ProcessOutputCallback& callback); 57 void SetOutputCallback(const ProcessOutputCallback& callback);
55 58
56 private: 59 private:
57 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>; 60 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>;
58 61
59 ProcessProxyRegistry(); 62 ProcessProxyRegistry();
60 ~ProcessProxyRegistry(); 63 ~ProcessProxyRegistry();
61 64
62 // Gets called when output gets detected. 65 // Gets called when output gets detected.
63 void OnProcessOutput(pid_t pid, 66 void OnProcessOutput(pid_t pid,
64 ProcessOutputType type, 67 ProcessOutputType type,
65 const std::string& data); 68 const std::string& data);
66 69
70 bool EnsureWatcherThreadStarted();
71
67 // Map of all existing ProcessProxies. 72 // Map of all existing ProcessProxies.
68 std::map<pid_t, ProcessProxyInfo> proxy_map_; 73 std::map<pid_t, ProcessProxyInfo> proxy_map_;
69 74
75 scoped_ptr<base::Thread> watcher_thread_;
76
70 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry); 77 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry);
71 }; 78 };
72 79
73 } // namespace chromeos 80 } // namespace chromeos
74 81
75 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ 82 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
OLDNEW
« no previous file with comments | « chromeos/process_proxy/process_proxy.cc ('k') | chromeos/process_proxy/process_proxy_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698