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

Side by Side Diff: chrome/browser/mach_broker_mac.h

Issue 466088: Revert 34146 - A place to store the pid>mach_port_t mapping.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years 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
« no previous file with comments | « chrome/browser/child_process_launcher.cc ('k') | chrome/browser/mach_broker_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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_MACH_BROKER_H_
6 #define CHROME_BROWSER_MACH_BROKER_H_
7
8 #include <map>
9
10 #include <mach/mach.h>
11
12 #include "base/lock.h"
13 #include "base/process.h"
14 #include "base/singleton.h"
15
16 // On OS X, the mach_port_t of a process is required to collect metrics about
17 // the process. Running |task_for_pid()| is only allowed for priviledged code.
18 // However, a process has port rights to all its subprocesses, so let the
19 // browser's child processes send their mach_port_t to the browser over IPC.
20 // This way, the brower can at least collect metrics of its child processes,
21 // which is what it's most interested in anyway.
22 //
23 // mach_port_ts can only be sent over mach ipc, not over the socketpair that
24 // the regular ipc system uses. Hence, the child processes open a mach
25 // connection shortly after launching and ipc their mach data to the browser
26 // process. This data is kept in a global |MachBroker| object.
27 //
28 // Due to this data arriving over a separate channel, it is not available
29 // immediately after a child process has been started.
30 class MachBroker {
31 public:
32 // Returns the global MachBroker.
33 static MachBroker* instance();
34
35 // Returns the mach task belonging to |pid|, or 0 if no mach task is
36 // registered for |pid|.
37 mach_port_t MachTaskForPid(base::ProcessHandle pid) const;
38
39 // Returns the mach host belonging to |pid|, or 0 if no mach task is
40 // registered for |pid|.
41 mach_port_t MachHostForPid(base::ProcessHandle pid) const;
42
43 struct MachInfo {
44 MachInfo() : mach_task_(0), mach_host_(0) {}
45
46 MachInfo& SetTask(mach_port_t task) {
47 mach_task_ = task;
48 return *this;
49 }
50
51 MachInfo& SetHost(mach_port_t host) {
52 mach_host_ = host;
53 return *this;
54 }
55
56 mach_port_t mach_task_;
57 mach_port_t mach_host_;
58 };
59
60 // Adds mach info for a given pid.
61 void RegisterPid(base::ProcessHandle pid, const MachInfo& mach_info);
62
63 // Removes all mappings belonging to |pid| from the broker.
64 void Invalidate(base::ProcessHandle pid);
65
66 private:
67 // Private constructor.
68 MachBroker();
69 friend struct DefaultSingletonTraits<MachBroker>;
70 friend class MachBrokerTest;
71
72 // Stores
73 typedef std::map<base::ProcessHandle, MachInfo> MachMap;
74 MachMap mach_map_;
75
76 // Mutex that guards |mach_map_|.
77 mutable Lock lock_;
78 };
79
80 #endif // CHROME_BROWSER_MACH_BROKER_H_
81
OLDNEW
« no previous file with comments | « chrome/browser/child_process_launcher.cc ('k') | chrome/browser/mach_broker_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698