diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 22:37:23 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 22:37:23 +0000 |
commit | 7c77a0b854c5e4222601f9572f2572206eeae7ce (patch) | |
tree | 80488d3737b0ca773413f1a4fc4b3dc49d10c1b0 /mojo/system/dispatcher.cc | |
parent | c3c2a062f121cd6024d564fd0c959601ef8b45df (diff) | |
download | chromium_src-7c77a0b854c5e4222601f9572f2572206eeae7ce.zip chromium_src-7c77a0b854c5e4222601f9572f2572206eeae7ce.tar.gz chromium_src-7c77a0b854c5e4222601f9572f2572206eeae7ce.tar.bz2 |
Mojo: Add hooks for dispatchers to serialize themselves.
Reland (committed r253869, reverted r253876; win64 breakage).
R=yzshen@chromium.org
Review URL: https://codereview.chromium.org/182163002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253947 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system/dispatcher.cc')
-rw-r--r-- | mojo/system/dispatcher.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/mojo/system/dispatcher.cc b/mojo/system/dispatcher.cc index ac02b83..3d970d0 100644 --- a/mojo/system/dispatcher.cc +++ b/mojo/system/dispatcher.cc @@ -28,6 +28,23 @@ DispatcherTransport Dispatcher::CoreImplAccess::TryStartTransport( return DispatcherTransport(dispatcher); } +// static +size_t Dispatcher::MessageInTransitAccess::GetMaximumSerializedSize( + const Dispatcher* dispatcher, + const Channel* channel) { + DCHECK(dispatcher); + return dispatcher->GetMaximumSerializedSize(channel); +} + +// static +size_t Dispatcher::MessageInTransitAccess::SerializeAndClose( + Dispatcher* dispatcher, + void* destination, + Channel* channel) { + DCHECK(dispatcher); + return dispatcher->SerializeAndClose(destination, channel); +} + MojoResult Dispatcher::Close() { base::AutoLock locker(lock_); if (is_closed_) @@ -297,6 +314,23 @@ void Dispatcher::RemoveWaiterImplNoLock(Waiter* /*waiter*/) { // will do something nontrivial. } +size_t Dispatcher::GetMaximumSerializedSizeImplNoLock( + const Channel* /*channel*/) const { + lock_.AssertAcquired(); + DCHECK(!is_closed_); + // By default, serializing isn't supported. + return 0; +} + +size_t Dispatcher::SerializeAndCloseImplNoLock(void* /*destination*/, + Channel* /*channel*/) { + lock_.AssertAcquired(); + DCHECK(is_closed_); + // By default, serializing isn't supported, so just close. + CloseImplNoLock(); + return 0; +} + bool Dispatcher::IsBusyNoLock() const { lock_.AssertAcquired(); DCHECK(!is_closed_); @@ -324,6 +358,39 @@ Dispatcher::CreateEquivalentDispatcherAndCloseNoLock() { return CreateEquivalentDispatcherAndCloseImplNoLock(); } +size_t Dispatcher::GetMaximumSerializedSize(const Channel* channel) const { + DCHECK(channel); + DCHECK(HasOneRef()); + + base::AutoLock locker(lock_); + DCHECK(!is_closed_); + return GetMaximumSerializedSizeImplNoLock(channel); +} + +size_t Dispatcher::SerializeAndClose(void* destination, Channel* channel) { + DCHECK(destination); + DCHECK(channel); + DCHECK(HasOneRef()); + + base::AutoLock locker(lock_); + DCHECK(!is_closed_); + + // We have to call |GetMaximumSerializedSizeImplNoLock()| first, because we + // leave it to |SerializeAndCloseImplNoLock()| to close the thing. + size_t max_size = DCHECK_IS_ON() ? + GetMaximumSerializedSizeImplNoLock(channel) : static_cast<size_t>(-1); + + // Like other |...Close()| methods, we mark ourselves as closed before calling + // the impl. + is_closed_ = true; + // No need to cancel waiters: we shouldn't have any (and shouldn't be in + // |Core|'s handle table. + + size_t size = SerializeAndCloseImplNoLock(destination, channel); + DCHECK_LE(size, max_size); + return size; +} + // DispatcherTransport --------------------------------------------------------- void DispatcherTransport::End() { |