| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "webkit/support/test_webmessageportchannel.h" | 5 #include "webkit/support/test_webmessageportchannel.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 10 #include "base/task.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel
Client.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel
Client.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 12 | 13 |
| 13 using WebKit::WebMessagePortChannel; | 14 using WebKit::WebMessagePortChannel; |
| 14 using WebKit::WebMessagePortChannelArray; | 15 using WebKit::WebMessagePortChannelArray; |
| 15 using WebKit::WebMessagePortChannelClient; | 16 using WebKit::WebMessagePortChannelClient; |
| 16 using WebKit::WebString; | 17 using WebKit::WebString; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 void TestWebMessagePortChannel::entangle(WebMessagePortChannel* remote) { | 60 void TestWebMessagePortChannel::entangle(WebMessagePortChannel* remote) { |
| 60 remote_ = static_cast<TestWebMessagePortChannel*>(remote); | 61 remote_ = static_cast<TestWebMessagePortChannel*>(remote); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void TestWebMessagePortChannel::postMessage(const WebString& data, | 64 void TestWebMessagePortChannel::postMessage(const WebString& data, |
| 64 WebMessagePortChannelArray* ports) { | 65 WebMessagePortChannelArray* ports) { |
| 65 if (remote_ == NULL) | 66 if (remote_ == NULL) |
| 66 return; | 67 return; |
| 67 MessageLoop::current()->PostTask( | 68 MessageLoop::current()->PostTask( |
| 68 FROM_HERE, | 69 FROM_HERE, |
| 69 NewRunnableMethod(remote_.get(), | 70 base::Bind(&TestWebMessagePortChannel::queueMessage, remote_.get(), |
| 70 &TestWebMessagePortChannel::queueMessage, | 71 new Message(data, ports))); |
| 71 new Message(data, ports))); | |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool TestWebMessagePortChannel::tryGetMessage(WebString* data, | 74 bool TestWebMessagePortChannel::tryGetMessage(WebString* data, |
| 75 WebMessagePortChannelArray& ports) { | 75 WebMessagePortChannelArray& ports) { |
| 76 if (message_queue_.empty()) | 76 if (message_queue_.empty()) |
| 77 return false; | 77 return false; |
| 78 scoped_ptr<Message> message(message_queue_.front()); | 78 scoped_ptr<Message> message(message_queue_.front()); |
| 79 message_queue_.pop(); | 79 message_queue_.pop(); |
| 80 *data = message->data(); | 80 *data = message->data(); |
| 81 if (WebMessagePortChannelArray* message_ports = message->ports()) | 81 if (WebMessagePortChannelArray* message_ports = message->ports()) |
| 82 ports.swap(*message_ports); | 82 ports.swap(*message_ports); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void TestWebMessagePortChannel::queueMessage(Message* message) { | 86 void TestWebMessagePortChannel::queueMessage(Message* message) { |
| 87 bool was_empty = message_queue_.empty(); | 87 bool was_empty = message_queue_.empty(); |
| 88 message_queue_.push(message); | 88 message_queue_.push(message); |
| 89 if (client_ && was_empty) | 89 if (client_ && was_empty) |
| 90 client_->messageAvailable(); | 90 client_->messageAvailable(); |
| 91 } | 91 } |
| OLD | NEW |