| Index: mojo/edk/system/raw_channel.h
|
| diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel.h b/mojo/edk/system/raw_channel.h
|
| similarity index 82%
|
| copy from third_party/mojo/src/mojo/edk/system/raw_channel.h
|
| copy to mojo/edk/system/raw_channel.h
|
| index cbcc1b3fc63d543ad03560161d57f611a3e83490..901ba760a75cbb26f29f8feef04475da3638bec0 100644
|
| --- a/third_party/mojo/src/mojo/edk/system/raw_channel.h
|
| +++ b/mojo/edk/system/raw_channel.h
|
| @@ -22,7 +22,7 @@ class MessageLoopForIO;
|
| }
|
|
|
| namespace mojo {
|
| -namespace system {
|
| +namespace edk {
|
|
|
| // |RawChannel| is an interface and base class for objects that wrap an OS
|
| // "pipe". It presents the following interface to users:
|
| @@ -41,9 +41,6 @@ namespace system {
|
| // on which |Init()| is called).
|
| class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| public:
|
| - // This object may be destroyed on any thread (if |Init()| was called, after
|
| - // |Shutdown()| was called).
|
| - virtual ~RawChannel();
|
|
|
| // The |Delegate| is only accessed on the same thread as the message loop
|
| // (passed in on creation).
|
| @@ -67,7 +64,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // |Shutdown()| and then (if desired) destroy it.
|
| virtual void OnReadMessage(
|
| const MessageInTransit::View& message_view,
|
| - embedder::ScopedPlatformHandleVectorPtr platform_handles) = 0;
|
| + ScopedPlatformHandleVectorPtr platform_handles) = 0;
|
|
|
| // Called when there's a (fatal) error. This may call the |RawChannel|'s
|
| // |Shutdown()| and then (if desired) destroy it.
|
| @@ -84,7 +81,12 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // Static factory method. |handle| should be a handle to a
|
| // (platform-appropriate) bidirectional communication channel (e.g., a socket
|
| // on POSIX, a named pipe on Windows).
|
| - static scoped_ptr<RawChannel> Create(embedder::ScopedPlatformHandle handle);
|
| + static RawChannel* Create(ScopedPlatformHandle handle);
|
| +
|
| + // Returns the amount of space needed in the |MessageInTransit|'s
|
| + // |TransportData|'s "platform handle table" per platform handle (to be
|
| + // attached to a message). (This amount may be zero.)
|
| + static size_t GetSerializedPlatformHandleSize();
|
|
|
| // This must be called (on an I/O thread) before this object is used. Does
|
| // *not* take ownership of |delegate|. Both the I/O thread and |delegate| must
|
| @@ -95,6 +97,19 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // This must be called (on the I/O thread) before this object is destroyed.
|
| void Shutdown();
|
|
|
| + // Returns the platform handle for the pipe synchronously.
|
| +
|
| +
|
| + // Flushes all pending writes synchronously.
|
| +
|
| +
|
| + // TODO(jam): change above to write it to shared memory and return handle as
|
| + // writing synchronously won't work for lots of pending data.
|
| + // Returns any partially read data.
|
| + // NOTE: After calling this, consider the channel shutdown and don't call into
|
| + // it anymore
|
| + ScopedPlatformHandle ReleaseHandle(std::vector<char>* read_buffer);
|
| +
|
| // Writes the given message (or schedules it to be written). |message| must
|
| // have no |Dispatcher|s still attached (i.e.,
|
| // |SerializeAndCloseDispatchers()| should have been called). This method is
|
| @@ -107,10 +122,12 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // becomes empty (or something like that).
|
| bool IsWriteBufferEmpty();
|
|
|
| - // Returns the amount of space needed in the |MessageInTransit|'s
|
| - // |TransportData|'s "platform handle table" per platform handle (to be
|
| - // attached to a message). (This amount may be zero.)
|
| - virtual size_t GetSerializedPlatformHandleSize() const = 0;
|
| + bool IsReadBufferEmpty();
|
| +
|
| + void SetInitialReadBufferData(char* data, size_t size);
|
| +
|
| + // Checks if this RawChannel is the other endpoint to |other|.
|
| + bool IsOtherEndOf(RawChannel* other);
|
|
|
| protected:
|
| // Result of I/O operations.
|
| @@ -132,6 +149,14 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
|
|
| void GetBuffer(char** addr, size_t* size);
|
|
|
| + void Reset() {num_valid_bytes_ = 0; }
|
| +
|
| + // temp for debugging
|
| + // TODO(jam): pass in a cleaner way to ReleaseHandle, just like shutdown
|
| + // case.
|
| + char* buffer() { return &buffer_[0]; }
|
| + size_t num_valid_bytes() {return num_valid_bytes_;}
|
| +
|
| private:
|
| friend class RawChannel;
|
|
|
| @@ -152,7 +177,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| size_t size;
|
| };
|
|
|
| - explicit WriteBuffer(size_t serialized_platform_handle_size);
|
| + WriteBuffer();
|
| ~WriteBuffer();
|
|
|
| // Returns true if there are (more) platform handles to be sent (from the
|
| @@ -170,7 +195,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // |PlatformHandle::CloseIfNecessary()| isn't const (and actually modifies
|
| // state).
|
| void GetPlatformHandlesToSend(size_t* num_platform_handles,
|
| - embedder::PlatformHandle** platform_handles,
|
| + PlatformHandle** platform_handles,
|
| void** serialization_data);
|
|
|
| // Gets buffers to be written. These buffers will always come from the front
|
| @@ -179,10 +204,23 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // |OnWriteCompletedNoLock()|.
|
| void GetBuffers(std::vector<Buffer>* buffers) const;
|
|
|
| - private:
|
| +
|
| +
|
| +
|
| +
|
| + // temp for testing
|
| + size_t queue_size() {return message_queue_.Size();}
|
| +
|
| + // TODO(jam): better way of giving buffer on release handle
|
| + MessageInTransitQueue* message_queue() { return &message_queue_; }
|
| +
|
| +
|
| +
|
| + // TODO JAM REMOVE AND ADD METHODS
|
| +// private:
|
| friend class RawChannel;
|
|
|
| - const size_t serialized_platform_handle_size_;
|
| + size_t serialized_platform_handle_size_;
|
|
|
| MessageInTransitQueue message_queue_;
|
| // Platform handles are sent before the message data, but doing so may
|
| @@ -199,6 +237,11 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
|
|
| RawChannel();
|
|
|
| + // Shutdown must be called on the IO thread. This object deletes itself once
|
| + // it's flushed all pending writes and insured that the other side of the pipe
|
| + // read them.
|
| + virtual ~RawChannel();
|
| +
|
| // |result| must not be |IO_PENDING|. Must be called on the I/O thread WITHOUT
|
| // |write_lock_| held. This object may be destroyed by this call.
|
| void OnReadCompleted(IOResult io_result, size_t bytes_read);
|
| @@ -210,6 +253,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
|
|
| base::MessageLoopForIO* message_loop_for_io() { return message_loop_for_io_; }
|
| base::Lock& write_lock() { return write_lock_; }
|
| + base::Lock& read_lock() { return read_lock_; }
|
|
|
| // Should only be called on the I/O thread.
|
| ReadBuffer* read_buffer() { return read_buffer_.get(); }
|
| @@ -234,6 +278,13 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| virtual bool OnReadMessageForRawChannel(
|
| const MessageInTransit::View& message_view);
|
|
|
| + virtual PlatformHandle HandleForDebuggingNoLock() = 0;
|
| +
|
| + // Implementation must write any pending messages synchronously.
|
| + // TODO(jam): change to return shared memory with pending serialized msgs.
|
| + virtual ScopedPlatformHandle ReleaseHandleNoLock(
|
| + std::vector<char>* read_buffer) = 0;
|
| +
|
| // Reads into |read_buffer()|.
|
| // This class guarantees that:
|
| // - the area indicated by |GetBuffer()| will stay valid until read completion
|
| @@ -256,7 +307,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // called when |num_platform_handles| is nonzero. Returns null if the
|
| // |num_platform_handles| handles are not available. Only called on the I/O
|
| // thread (without |write_lock_| held).
|
| - virtual embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles(
|
| + virtual ScopedPlatformHandleVectorPtr GetReadPlatformHandles(
|
| size_t num_platform_handles,
|
| const void* platform_handle_table) = 0;
|
|
|
| @@ -289,7 +340,11 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| virtual void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer,
|
| scoped_ptr<WriteBuffer> write_buffer) = 0;
|
|
|
| + void SendQueuedMessagesNoLock();
|
| +
|
| private:
|
| + friend class base::DeleteHelper<RawChannel>;
|
| +
|
| // Converts an |IO_FAILED_...| for a read to a |Delegate::Error|.
|
| static Delegate::Error ReadIOResultToError(IOResult io_result);
|
|
|
| @@ -297,6 +352,8 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| // |write_lock_| held. This object may be destroyed by this call.
|
| void CallOnError(Delegate::Error error);
|
|
|
| + void LockAndCallOnError(Delegate::Error error);
|
| +
|
| // If |io_result| is |IO_SUCCESS|, updates the write buffer and schedules a
|
| // write operation to run later if there is more to write. If |io_result| is
|
| // failure or any other error occurs, cancels pending writes and returns
|
| @@ -306,19 +363,46 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| size_t platform_handles_written,
|
| size_t bytes_written);
|
|
|
| + // Helper method to dispatch messages from the read buffer.
|
| + // |did_dispatch_message| is true iff it dispatched any messages.
|
| + // |stop_dispatching| is set to true if the code calling this should stop
|
| + // dispatching, either because we hit an erorr or the delegate shutdown the
|
| + // channel.
|
| + void DispatchMessages(bool* did_dispatch_message, bool* stop_dispatching);
|
| +
|
| // Set in |Init()| and never changed (hence usable on any thread without
|
| // locking):
|
| base::MessageLoopForIO* message_loop_for_io_;
|
|
|
| +
|
| +
|
| +
|
| +
|
| + // TODO(jam): one lock only....
|
| +
|
| +
|
| +
|
| +
|
| // Only used on the I/O thread:
|
| - Delegate* delegate_;
|
| +
|
| bool* set_on_shutdown_;
|
| +
|
| + base::Lock read_lock_; // Protects read_buffer_.
|
| + // This is usually only accessed on IO thread, except when ReleaseHandle is
|
| + // called.
|
| scoped_ptr<ReadBuffer> read_buffer_;
|
| + // ditto: usually used on io thread except ReleaseHandle
|
| + Delegate* delegate_;
|
| +
|
| + // If grabbing both locks, grab read first.
|
|
|
| base::Lock write_lock_; // Protects the following members.
|
| + bool write_ready_;
|
| bool write_stopped_;
|
| scoped_ptr<WriteBuffer> write_buffer_;
|
|
|
| + bool error_occurred_;
|
| +
|
| // This is used for posting tasks from write threads to the I/O thread. It
|
| // must only be accessed under |write_lock_|. The weak pointers it produces
|
| // are only used/invalidated on the I/O thread.
|
| @@ -327,7 +411,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel {
|
| MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel);
|
| };
|
|
|
| -} // namespace system
|
| +} // namespace edk
|
| } // namespace mojo
|
|
|
| #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_
|
|
|