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

Side by Side Diff: mojo/edk/system/handle_table.h

Issue 2915013006: Add a Mojo MemoryDumpProvider. (Closed)
Patch Set: compile error. Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ 5 #ifndef MOJO_EDK_SYSTEM_HANDLE_TABLE_H_
6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ 6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/synchronization/lock.h"
15 #include "base/trace_event/memory_dump_provider.h"
14 #include "mojo/edk/system/dispatcher.h" 16 #include "mojo/edk/system/dispatcher.h"
15 #include "mojo/public/c/system/types.h" 17 #include "mojo/public/c/system/types.h"
16 18
17 namespace mojo { 19 namespace mojo {
18 namespace edk { 20 namespace edk {
19 21
20 class HandleTable { 22 class HandleTable : public base::trace_event::MemoryDumpProvider {
21 public: 23 public:
22 HandleTable(); 24 HandleTable();
23 ~HandleTable(); 25 ~HandleTable() override;
26
27 // HandleTable is thread-hostile. All access should be gated by GetLock().
28 base::Lock& GetLock();
24 29
25 MojoHandle AddDispatcher(scoped_refptr<Dispatcher> dispatcher); 30 MojoHandle AddDispatcher(scoped_refptr<Dispatcher> dispatcher);
26 31
27 // Inserts multiple dispatchers received from message transit, populating 32 // Inserts multiple dispatchers received from message transit, populating
28 // |handles| with their newly allocated handles. Returns |true| on success. 33 // |handles| with their newly allocated handles. Returns |true| on success.
29 bool AddDispatchersFromTransit( 34 bool AddDispatchersFromTransit(
30 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, 35 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers,
31 MojoHandle* handles); 36 MojoHandle* handles);
32 37
33 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle) const; 38 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle) const;
34 MojoResult GetAndRemoveDispatcher(MojoHandle, 39 MojoResult GetAndRemoveDispatcher(MojoHandle,
35 scoped_refptr<Dispatcher>* dispatcher); 40 scoped_refptr<Dispatcher>* dispatcher);
36 41
37 // Marks handles as busy and populates |dispatchers|. Returns MOJO_RESULT_BUSY 42 // Marks handles as busy and populates |dispatchers|. Returns MOJO_RESULT_BUSY
38 // if any of the handles are already in transit; MOJO_RESULT_INVALID_ARGUMENT 43 // if any of the handles are already in transit; MOJO_RESULT_INVALID_ARGUMENT
39 // if any of the handles are invalid; or MOJO_RESULT_OK if successful. 44 // if any of the handles are invalid; or MOJO_RESULT_OK if successful.
40 MojoResult BeginTransit( 45 MojoResult BeginTransit(
41 const MojoHandle* handles, 46 const MojoHandle* handles,
42 uint32_t num_handles, 47 uint32_t num_handles,
43 std::vector<Dispatcher::DispatcherInTransit>* dispatchers); 48 std::vector<Dispatcher::DispatcherInTransit>* dispatchers);
44 49
45 void CompleteTransitAndClose( 50 void CompleteTransitAndClose(
46 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); 51 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers);
47 void CancelTransit( 52 void CancelTransit(
48 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers); 53 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers);
49 54
50 void GetActiveHandlesForTest(std::vector<MojoHandle> *handles); 55 void GetActiveHandlesForTest(std::vector<MojoHandle> *handles);
51 56
52 private: 57 private:
58 // MemoryDumpProvider implementation.
59 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
60 base::trace_event::ProcessMemoryDump* pmd) override;
61
53 struct Entry { 62 struct Entry {
54 Entry(); 63 Entry();
55 explicit Entry(scoped_refptr<Dispatcher> dispatcher); 64 explicit Entry(scoped_refptr<Dispatcher> dispatcher);
56 Entry(const Entry& other); 65 Entry(const Entry& other);
57 ~Entry(); 66 ~Entry();
58 67
59 scoped_refptr<Dispatcher> dispatcher; 68 scoped_refptr<Dispatcher> dispatcher;
60 bool busy = false; 69 bool busy = false;
61 }; 70 };
62 71
63 using HandleMap = base::hash_map<MojoHandle, Entry>; 72 using HandleMap = base::hash_map<MojoHandle, Entry>;
64 73
65 HandleMap handles_; 74 HandleMap handles_;
75 base::Lock lock_;
66 76
67 uint32_t next_available_handle_ = 1; 77 uint32_t next_available_handle_ = 1;
68 78
69 DISALLOW_COPY_AND_ASSIGN(HandleTable); 79 DISALLOW_COPY_AND_ASSIGN(HandleTable);
70 }; 80 };
71 81
72 } // namespace edk 82 } // namespace edk
73 } // namespace mojo 83 } // namespace mojo
74 84
75 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ 85 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698