| OLD | NEW |
| 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 CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ | 5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_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 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "chrome/browser/chromeos/process_proxy/process_proxy.h" | 16 #include "chromeos/chromeos_export.h" |
| 17 #include "chromeos/process_proxy/process_proxy.h" |
| 18 |
| 19 namespace chromeos { |
| 16 | 20 |
| 17 typedef base::Callback<void(pid_t, const std::string&, const std::string&)> | 21 typedef base::Callback<void(pid_t, const std::string&, const std::string&)> |
| 18 ProcessOutputCallbackWithPid; | 22 ProcessOutputCallbackWithPid; |
| 19 | 23 |
| 20 // Keeps track of all created ProcessProxies. It is created lazily and should | 24 // Keeps track of all created ProcessProxies. It is created lazily and should |
| 21 // live on the FILE thread (where all methods must be called). | 25 // live on a single thread (where all methods must be called). |
| 22 class ProcessProxyRegistry { | 26 class CHROMEOS_EXPORT ProcessProxyRegistry : public base::NonThreadSafe { |
| 23 public: | 27 public: |
| 24 // Info we need about a ProcessProxy instance. | 28 // Info we need about a ProcessProxy instance. |
| 25 struct ProcessProxyInfo { | 29 struct ProcessProxyInfo { |
| 26 scoped_refptr<ProcessProxy> proxy; | 30 scoped_refptr<ProcessProxy> proxy; |
| 27 scoped_ptr<base::Thread> watcher_thread; | 31 scoped_ptr<base::Thread> watcher_thread; |
| 28 ProcessOutputCallbackWithPid callback; | 32 ProcessOutputCallbackWithPid callback; |
| 29 pid_t process_id; | 33 pid_t process_id; |
| 30 | 34 |
| 31 ProcessProxyInfo(); | 35 ProcessProxyInfo(); |
| 32 // 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. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 private: | 56 private: |
| 53 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>; | 57 friend struct ::base::DefaultLazyInstanceTraits<ProcessProxyRegistry>; |
| 54 | 58 |
| 55 ProcessProxyRegistry(); | 59 ProcessProxyRegistry(); |
| 56 ~ProcessProxyRegistry(); | 60 ~ProcessProxyRegistry(); |
| 57 | 61 |
| 58 // Gets called when output gets detected. | 62 // Gets called when output gets detected. |
| 59 void OnProcessOutput(pid_t pid, | 63 void OnProcessOutput(pid_t pid, |
| 60 ProcessOutputType type, | 64 ProcessOutputType type, |
| 61 const std::string& data); | 65 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 | 66 |
| 69 // Map of all existing ProcessProxies. | 67 // Map of all existing ProcessProxies. |
| 70 std::map<pid_t, ProcessProxyInfo> proxy_map_; | 68 std::map<pid_t, ProcessProxyInfo> proxy_map_; |
| 71 | 69 |
| 72 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry); | 70 DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry); |
| 73 }; | 71 }; |
| 74 | 72 |
| 75 #endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ | 73 } // namespace chromeos |
| 74 |
| 75 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_ |
| OLD | NEW |