Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / mojo / system / core.h
bloba8f3b175fb0b71e0102d12bd99d86308e3b5efdd
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
3 // found in the LICENSE file.
5 #ifndef MOJO_SYSTEM_CORE_H_
6 #define MOJO_SYSTEM_CORE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "mojo/public/c/system/buffer.h"
13 #include "mojo/public/c/system/data_pipe.h"
14 #include "mojo/public/c/system/message_pipe.h"
15 #include "mojo/public/c/system/types.h"
16 #include "mojo/system/handle_table.h"
17 #include "mojo/system/mapping_table.h"
18 #include "mojo/system/system_impl_export.h"
20 namespace mojo {
21 namespace system {
23 class Dispatcher;
25 // |Core| is an object that implements the Mojo system calls. All public methods
26 // are thread-safe.
27 class MOJO_SYSTEM_IMPL_EXPORT Core {
28 public:
29 // These methods are only to be used by via the embedder API (and internally).
30 Core();
31 virtual ~Core();
33 // Adds |dispatcher| to the handle table, returning the handle for it. Returns
34 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full.
35 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher);
37 // Looks up the dispatcher for the given handle. Returns null if the handle is
38 // invalid.
39 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
41 // System calls implementation.
42 MojoTimeTicks GetTimeTicksNow();
43 MojoResult Close(MojoHandle handle);
44 MojoResult Wait(MojoHandle handle,
45 MojoWaitFlags flags,
46 MojoDeadline deadline);
47 MojoResult WaitMany(const MojoHandle* handles,
48 const MojoWaitFlags* flags,
49 uint32_t num_handles,
50 MojoDeadline deadline);
51 MojoResult CreateMessagePipe(MojoHandle* message_pipe_handle0,
52 MojoHandle* message_pipe_handle1);
53 MojoResult WriteMessage(MojoHandle message_pipe_handle,
54 const void* bytes,
55 uint32_t num_bytes,
56 const MojoHandle* handles,
57 uint32_t num_handles,
58 MojoWriteMessageFlags flags);
59 MojoResult ReadMessage(MojoHandle message_pipe_handle,
60 void* bytes,
61 uint32_t* num_bytes,
62 MojoHandle* handles,
63 uint32_t* num_handles,
64 MojoReadMessageFlags flags);
65 MojoResult CreateDataPipe(const MojoCreateDataPipeOptions* options,
66 MojoHandle* data_pipe_producer_handle,
67 MojoHandle* data_pipe_consumer_handle);
68 MojoResult WriteData(MojoHandle data_pipe_producer_handle,
69 const void* elements,
70 uint32_t* num_bytes,
71 MojoWriteDataFlags flags);
72 MojoResult BeginWriteData(MojoHandle data_pipe_producer_handle,
73 void** buffer,
74 uint32_t* buffer_num_bytes,
75 MojoWriteDataFlags flags);
76 MojoResult EndWriteData(MojoHandle data_pipe_producer_handle,
77 uint32_t num_bytes_written);
78 MojoResult ReadData(MojoHandle data_pipe_consumer_handle,
79 void* elements,
80 uint32_t* num_bytes,
81 MojoReadDataFlags flags);
82 MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle,
83 const void** buffer,
84 uint32_t* buffer_num_bytes,
85 MojoReadDataFlags flags);
86 MojoResult EndReadData(MojoHandle data_pipe_consumer_handle,
87 uint32_t num_bytes_read);
88 MojoResult CreateSharedBuffer(const MojoCreateSharedBufferOptions* options,
89 uint64_t num_bytes,
90 MojoHandle* shared_buffer_handle);
91 MojoResult DuplicateBufferHandle(
92 MojoHandle buffer_handle,
93 const MojoDuplicateBufferHandleOptions* options,
94 MojoHandle* new_buffer_handle);
95 MojoResult MapBuffer(MojoHandle buffer_handle,
96 uint64_t offset,
97 uint64_t num_bytes,
98 void** buffer,
99 MojoMapBufferFlags flags);
100 MojoResult UnmapBuffer(void* buffer);
102 private:
103 friend bool internal::ShutdownCheckNoLeaks(Core*);
105 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic
106 // validation of arguments.
107 MojoResult WaitManyInternal(const MojoHandle* handles,
108 const MojoWaitFlags* flags,
109 uint32_t num_handles,
110 MojoDeadline deadline);
112 // ---------------------------------------------------------------------------
114 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we
115 // had them).
116 base::Lock handle_table_lock_; // Protects |handle_table_|.
117 HandleTable handle_table_;
119 base::Lock mapping_table_lock_; // Protects |mapping_table_|.
120 MappingTable mapping_table_;
122 // ---------------------------------------------------------------------------
124 DISALLOW_COPY_AND_ASSIGN(Core);
127 } // namespace system
128 } // namespace mojo
130 #endif // MOJO_SYSTEM_CORE_H_