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

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

Issue 12433023: Move chrome/browser/chromeos/process_proxy to chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
6 #define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
7
8 #include <map>
9
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/thread.h"
15 #include "chrome/browser/chromeos/process_proxy/process_proxy.h"
16
17 typedef base::Callback<void(pid_t, const std::string&, const std::string&)>
18 ProcessOutputCallbackWithPid;
19
20 // Keeps track of all created ProcessProxies. It is created lazily and should
21 // live on the FILE thread (where all methods must be called).
22 class ProcessProxyRegistry {
23 public:
24 // Info we need about a ProcessProxy instance.
25 struct ProcessProxyInfo {
26 scoped_refptr<ProcessProxy> proxy;
27 scoped_ptr<base::Thread> watcher_thread;
28 ProcessOutputCallbackWithPid callback;
29 pid_t process_id;
30
31 ProcessProxyInfo();
32 // This is to make map::insert happy, we don't init anything.
33 ProcessProxyInfo(const ProcessProxyInfo& other);
34 ~ProcessProxyInfo();
35 };
36
37 static ProcessProxyRegistry* Get();
38
39 // Starts new ProcessProxy (which starts new process).
40 bool OpenProcess(const std::string& command, pid_t* pid,
41 const ProcessOutputCallbackWithPid& callback);
42 // Sends data to the process with id |pid|.
43 bool SendInput(pid_t pid, const std::string& data);
44 // Stops the process with id |pid|.
45 bool CloseProcess(pid_t pid);
46 // Reports terminal resize to process proxy.
47 bool OnTerminalResize(pid_t pid, int width, int height);
48
49 // Currently used for testing.
50 void SetOutputCallback(const ProcessOutputCallback& callback);
51
52 private:
53 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>;
54
55 ProcessProxyRegistry();
56 ~ProcessProxyRegistry();
57
58 // Gets called when output gets detected.
59 void OnProcessOutput(pid_t pid,
60 ProcessOutputType type,
61 const std::string& data);
62 // Must be called on UI thread. This lives on FILE thread, thus static.
63 // Notifies CroshProcessEventRouter about new process output. Assumes the
64 // event router has already been initialized by someone else.
65 static void DispatchProcessOutputOnUIThread(pid_t pid,
66 const std::string& output_type,
67 const std::string& output);
68
69 // Map of all existing ProcessProxies.
70 std::map<pid_t, ProcessProxyInfo> proxy_map_;
71
72 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry);
73 };
74
75 #endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698