summaryrefslogtreecommitdiffstats
path: root/mojo/system/raw_channel_posix.cc
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-21 19:22:22 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-21 19:22:22 +0000
commit0e47224e384538d0f06e64e7f12e6847c22618ed (patch)
tree03f14743effce82bd41c02c3d4b871fa68ec1c2a /mojo/system/raw_channel_posix.cc
parentaafb5903c8a2b8fc896f46fc47e5a1d1ced834e9 (diff)
downloadchromium_src-0e47224e384538d0f06e64e7f12e6847c22618ed.zip
chromium_src-0e47224e384538d0f06e64e7f12e6847c22618ed.tar.gz
chromium_src-0e47224e384538d0f06e64e7f12e6847c22618ed.tar.bz2
Mojo: Convert MessageInTransit* -> scoped_ptr<MessageInTransit>, part 1.
R=yzshen@chromium.org Review URL: https://codereview.chromium.org/170013003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252607 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system/raw_channel_posix.cc')
-rw-r--r--mojo/system/raw_channel_posix.cc24
1 files changed, 10 insertions, 14 deletions
diff --git a/mojo/system/raw_channel_posix.cc b/mojo/system/raw_channel_posix.cc
index 9c187b5..433ea4f 100644
--- a/mojo/system/raw_channel_posix.cc
+++ b/mojo/system/raw_channel_posix.cc
@@ -21,6 +21,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "mojo/system/embedder/platform_handle.h"
#include "mojo/system/message_in_transit.h"
@@ -43,7 +44,7 @@ class RawChannelPosix : public RawChannel,
// |RawChannel| implementation:
virtual bool Init() OVERRIDE;
virtual void Shutdown() OVERRIDE;
- virtual bool WriteMessage(MessageInTransit* message) OVERRIDE;
+ virtual bool WriteMessage(scoped_ptr<MessageInTransit> message) OVERRIDE;
private:
// |base::MessageLoopForIO::Watcher| implementation:
@@ -83,6 +84,8 @@ class RawChannelPosix : public RawChannel,
base::Lock write_lock_; // Protects the following members.
bool write_stopped_;
+ // TODO(vtl): When C++11 is available, switch this to a deque of
+ // |scoped_ptr|/|unique_ptr|s.
std::deque<MessageInTransit*> write_message_queue_;
size_t write_message_offset_;
// This is used for posting tasks from write threads to the I/O thread. It
@@ -162,19 +165,17 @@ void RawChannelPosix::Shutdown() {
}
// Reminder: This must be thread-safe, and takes ownership of |message|.
-bool RawChannelPosix::WriteMessage(MessageInTransit* message) {
+bool RawChannelPosix::WriteMessage(scoped_ptr<MessageInTransit> message) {
base::AutoLock locker(write_lock_);
- if (write_stopped_) {
- delete message;
+ if (write_stopped_)
return false;
- }
if (!write_message_queue_.empty()) {
- write_message_queue_.push_back(message);
+ write_message_queue_.push_back(message.release());
return true;
}
- write_message_queue_.push_front(message);
+ write_message_queue_.push_front(message.release());
DCHECK_EQ(write_message_offset_, 0u);
bool result = WriteFrontMessageNoLock();
DCHECK(result || write_message_queue_.empty());
@@ -384,8 +385,8 @@ bool RawChannelPosix::WriteFrontMessageNoLock() {
// Complete write.
DCHECK_EQ(static_cast<size_t>(bytes_written), bytes_to_write);
write_message_queue_.pop_front();
- write_message_offset_ = 0;
delete message;
+ write_message_offset_ = 0;
}
return true;
@@ -396,12 +397,7 @@ void RawChannelPosix::CancelPendingWritesNoLock() {
DCHECK(!write_stopped_);
write_stopped_ = true;
- for (std::deque<MessageInTransit*>::iterator it =
- write_message_queue_.begin(); it != write_message_queue_.end();
- ++it) {
- delete *it;
- }
- write_message_queue_.clear();
+ STLDeleteElements(&write_message_queue_);
}
} // namespace