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

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

Issue 501138: Mac: Create a pid->task_t mapping in the browser process. (Closed)
Patch Set: trunglify 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
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>
Mark Mentovai 2009/12/21 19:23:10 C++ system headers come after C system headers.
9
10 #include <mach/mach.h>
11
12 #include "base/lock.h"
13 #include "base/process.h"
14 #include "base/process_util.h"
15 #include "base/singleton.h"
16
17 // On OS X, the mach_port_t of a process is required to collect metrics about
18 // the process. Running |task_for_pid()| is only allowed for privileged code.
19 // However, a process has port rights to all its subprocesses, so let the
20 // browser's child processes send their Mach port to the browser over IPC.
21 // This way, the brower can at least collect metrics of its child processes,
22 // which is what it's most interested in anyway.
23 //
24 // Mach ports can only be sent over Mach IPC, not over the |socketpair()| that
viettrungluu 2009/12/19 07:46:37 I bet you didn't realize that I would object to |s
Mark Mentovai 2009/12/21 19:23:10 I agree with Trung. This should be spelled "not o
25 // the regular IPC system uses. Hence, the child processes open a Mach
26 // connection shortly after launching and ipc their mach data to the browser
Mark Mentovai 2009/12/21 19:23:10 And as long as we're being anal in this paragraph,
27 // process. This data is kept in a global |MachBroker| object.
28 //
29 // Since this data arrives over a separate channel, it is not available
30 // immediately after a child process has been started.
31 class MachBroker : public base::ProcessMetrics::PortProvider {
32 public:
33 // Returns the global MachBroker.
34 static MachBroker* instance();
35
36 struct MachInfo {
37 MachInfo() : mach_task_(MACH_PORT_NULL) {}
38
39 MachInfo& SetTask(mach_port_t task) {
40 mach_task_ = task;
41 return *this;
42 }
43
44 mach_port_t mach_task_;
45 };
46
47 // Adds mach info for a given pid.
48 void RegisterPid(base::ProcessHandle pid, const MachInfo& mach_info);
49
50 // Removes all mappings belonging to |pid| from the broker.
51 void Invalidate(base::ProcessHandle pid);
52
53 // Implement |ProcessMetrics::PortProvider|.
54 virtual mach_port_t TaskForPid(base::ProcessHandle process) const;
55
56 private:
57 // Private constructor.
Mark Mentovai 2009/12/21 19:23:10 This is a "duh" comment.
58 MachBroker() {}
59 friend struct DefaultSingletonTraits<MachBroker>;
60 friend class MachBrokerTest;
61
62 // Stores mach info for every process in the broker.
63 typedef std::map<base::ProcessHandle, MachInfo> MachMap;
64 MachMap mach_map_;
65
66 // Mutex that guards |mach_map_|.
67 mutable Lock lock_;
68
69 DISALLOW_COPY_AND_ASSIGN(MachBroker);
70 };
71
72 #endif // CHROME_BROWSER_MACH_BROKER_H_
73
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698