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

Side by Side Diff: mojo/system/core_impl.h

Issue 140403002: Mojo: Add the ability to hook up a channel to the embedder API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 11 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
« no previous file with comments | « mojo/public/system/core_private.cc ('k') | mojo/system/core_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SYSTEM_CORE_IMPL_H_ 5 #ifndef MOJO_SYSTEM_CORE_IMPL_H_
6 #define MOJO_SYSTEM_CORE_IMPL_H_ 6 #define MOJO_SYSTEM_CORE_IMPL_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "mojo/public/system/core_private.h" 13 #include "mojo/public/system/core_private.h"
14 #include "mojo/system/system_impl_export.h" 14 #include "mojo/system/system_impl_export.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 namespace embedder {
19 void Init(); // So it can be friended.
20 }
21
22 namespace system { 18 namespace system {
23 19
24 class CoreImpl; 20 class CoreImpl;
25 class Dispatcher; 21 class Dispatcher;
26 22
27 namespace test {
28 class CoreTestBase;
29 }
30
31 // |CoreImpl| is a singleton object that implements the Mojo system calls. All 23 // |CoreImpl| is a singleton object that implements the Mojo system calls. All
32 // public methods are thread-safe. 24 // public methods are thread-safe.
33 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { 25 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core {
34 public: 26 public:
35 static void Init(); 27 // These methods are only to be used by via the embedder API.
28 CoreImpl();
29 virtual ~CoreImpl();
30 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher);
36 31
37 // |CorePrivate| implementation: 32 // |CorePrivate| implementation:
38 virtual MojoTimeTicks GetTimeTicksNow() OVERRIDE; 33 virtual MojoTimeTicks GetTimeTicksNow() OVERRIDE;
39 virtual MojoResult Close(MojoHandle handle) OVERRIDE; 34 virtual MojoResult Close(MojoHandle handle) OVERRIDE;
40 virtual MojoResult Wait(MojoHandle handle, 35 virtual MojoResult Wait(MojoHandle handle,
41 MojoWaitFlags flags, 36 MojoWaitFlags flags,
42 MojoDeadline deadline) OVERRIDE; 37 MojoDeadline deadline) OVERRIDE;
43 virtual MojoResult WaitMany(const MojoHandle* handles, 38 virtual MojoResult WaitMany(const MojoHandle* handles,
44 const MojoWaitFlags* flags, 39 const MojoWaitFlags* flags,
45 uint32_t num_handles, 40 uint32_t num_handles,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 uint32_t* num_bytes, 73 uint32_t* num_bytes,
79 MojoReadDataFlags flags) OVERRIDE; 74 MojoReadDataFlags flags) OVERRIDE;
80 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, 75 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle,
81 const void** buffer, 76 const void** buffer,
82 uint32_t* buffer_num_bytes, 77 uint32_t* buffer_num_bytes,
83 MojoReadDataFlags flags) OVERRIDE; 78 MojoReadDataFlags flags) OVERRIDE;
84 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, 79 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle,
85 uint32_t num_bytes_read) OVERRIDE; 80 uint32_t num_bytes_read) OVERRIDE;
86 81
87 private: 82 private:
88 friend void embedder::Init();
89 friend class test::CoreTestBase;
90
91 // The |busy| member is used only to deal with functions (in particular 83 // The |busy| member is used only to deal with functions (in particular
92 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it 84 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it
93 // from the handle table, without holding on to the handle table lock. 85 // from the handle table, without holding on to the handle table lock.
94 // 86 //
95 // For example, if |WriteMessage()| is called with a handle to be sent, (under 87 // For example, if |WriteMessage()| is called with a handle to be sent, (under
96 // the handle table lock) it must first check that that handle is not busy (if 88 // the handle table lock) it must first check that that handle is not busy (if
97 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as 89 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as
98 // busy. To avoid deadlock, it should also try to acquire the locks for all 90 // busy. To avoid deadlock, it should also try to acquire the locks for all
99 // the dispatchers for the handles that it is sending (and fail with 91 // the dispatchers for the handles that it is sending (and fail with
100 // |MOJO_RESULT_BUSY| if the attempt fails). At this point, it can release the 92 // |MOJO_RESULT_BUSY| if the attempt fails). At this point, it can release the
(...skipping 15 matching lines...) Expand all
116 struct HandleTableEntry { 108 struct HandleTableEntry {
117 HandleTableEntry(); 109 HandleTableEntry();
118 explicit HandleTableEntry(const scoped_refptr<Dispatcher>& dispatcher); 110 explicit HandleTableEntry(const scoped_refptr<Dispatcher>& dispatcher);
119 ~HandleTableEntry(); 111 ~HandleTableEntry();
120 112
121 scoped_refptr<Dispatcher> dispatcher; 113 scoped_refptr<Dispatcher> dispatcher;
122 bool busy; 114 bool busy;
123 }; 115 };
124 typedef base::hash_map<MojoHandle, HandleTableEntry> HandleTableMap; 116 typedef base::hash_map<MojoHandle, HandleTableEntry> HandleTableMap;
125 117
126 CoreImpl();
127 virtual ~CoreImpl();
128
129 // Looks up the dispatcher for the given handle. Returns null if the handle is 118 // Looks up the dispatcher for the given handle. Returns null if the handle is
130 // invalid. 119 // invalid.
131 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); 120 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
132 121
133 // Assigns a new handle for the given dispatcher (which must be valid); 122 // Assigns a new handle for the given dispatcher (which must be valid);
134 // returns |MOJO_HANDLE_INVALID| on failure (due to hitting resource limits). 123 // returns |MOJO_HANDLE_INVALID| on failure (due to hitting resource limits).
135 // Must be called under |handle_table_lock_|. 124 // Must be called under |handle_table_lock_|.
136 MojoHandle AddDispatcherNoLock(const scoped_refptr<Dispatcher>& dispatcher); 125 MojoHandle AddDispatcherNoLock(const scoped_refptr<Dispatcher>& dispatcher);
137 126
138 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic 127 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic
(...skipping 14 matching lines...) Expand all
153 // --------------------------------------------------------------------------- 142 // ---------------------------------------------------------------------------
154 143
155 DISALLOW_COPY_AND_ASSIGN(CoreImpl); 144 DISALLOW_COPY_AND_ASSIGN(CoreImpl);
156 }; 145 };
157 146
158 } // namespace system 147 } // namespace system
159 148
160 } // namespace mojo 149 } // namespace mojo
161 150
162 #endif // MOJO_SYSTEM_CORE_IMPL_H_ 151 #endif // MOJO_SYSTEM_CORE_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/public/system/core_private.cc ('k') | mojo/system/core_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698