summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 04:30:47 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 04:30:47 +0000
commit2984f1ca64a63ed179348f6a88133e06c117dd8b (patch)
treeedf03eca1ece65cdfd845baa7771147166a0360b /chrome
parentefbbc4e910ffc6bfa364b6663143ac39930759fb (diff)
downloadchromium_src-2984f1ca64a63ed179348f6a88133e06c117dd8b.zip
chromium_src-2984f1ca64a63ed179348f6a88133e06c117dd8b.tar.gz
chromium_src-2984f1ca64a63ed179348f6a88133e06c117dd8b.tar.bz2
Switch IPC classes over to using ObjectWatcher instead of MessageLoop::WatchObject.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/ipc_channel.cc58
-rw-r--r--chrome/common/ipc_channel.h23
-rw-r--r--chrome/common/ipc_channel_proxy.h9
-rw-r--r--chrome/common/ipc_logging.cc27
-rw-r--r--chrome/common/ipc_logging.h23
-rw-r--r--chrome/common/message_router.h1
-rw-r--r--chrome/common/resource_dispatcher.cc1
-rw-r--r--chrome/renderer/net/render_dns_master.cc1
8 files changed, 52 insertions, 91 deletions
diff --git a/chrome/common/ipc_channel.cc b/chrome/common/ipc_channel.cc
index d469736..96b0f9b 100644
--- a/chrome/common/ipc_channel.cc
+++ b/chrome/common/ipc_channel.cc
@@ -74,8 +74,8 @@ Channel::Channel(const wstring& channel_id, Mode mode, Listener* listener)
void Channel::Close() {
// make sure we are no longer watching the pipe events
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
- MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent, NULL);
+ input_state_.watcher.StopWatching();
+ output_state_.watcher.StopWatching();
if (pipe_ != INVALID_HANDLE_VALUE) {
CloseHandle(pipe_);
@@ -193,7 +193,7 @@ bool Channel::Connect() {
// to OnObjectSignaled that this is the special initialization signal.
SetEvent(input_state_.overlapped.hEvent);
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, this);
+ input_state_.watcher.StartWatching(input_state_.overlapped.hEvent, this);
}
if (!waiting_connect_)
@@ -203,7 +203,7 @@ bool Channel::Connect() {
bool Channel::ProcessConnection() {
input_state_.is_pending = false;
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
+ input_state_.watcher.StopWatching();
// Do we have a client connected to our pipe?
DCHECK(pipe_ != INVALID_HANDLE_VALUE);
@@ -220,7 +220,7 @@ bool Channel::ProcessConnection() {
switch (err) {
case ERROR_IO_PENDING:
input_state_.is_pending = true;
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, this);
+ input_state_.watcher.StartWatching(input_state_.overlapped.hEvent, this);
break;
case ERROR_PIPE_CONNECTED:
waiting_connect_ = false;
@@ -236,7 +236,7 @@ bool Channel::ProcessConnection() {
bool Channel::ProcessIncomingMessages() {
DWORD bytes_read = 0;
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
+ input_state_.watcher.StopWatching();
if (input_state_.is_pending) {
input_state_.is_pending = false;
@@ -268,8 +268,8 @@ bool Channel::ProcessIncomingMessages() {
if (!ok) {
DWORD err = GetLastError();
if (err == ERROR_IO_PENDING) {
- MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent,
- this);
+ input_state_.watcher.StartWatching(
+ input_state_.overlapped.hEvent, this);
input_state_.is_pending = true;
return true;
}
@@ -332,7 +332,7 @@ bool Channel::ProcessOutgoingMessages() {
DWORD bytes_written;
if (output_state_.is_pending) {
- MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent, NULL);
+ output_state_.watcher.StopWatching();
output_state_.is_pending = false;
BOOL ok = GetOverlappedResult(pipe_,
&output_state_.overlapped,
@@ -361,8 +361,8 @@ bool Channel::ProcessOutgoingMessages() {
if (!ok) {
DWORD err = GetLastError();
if (err == ERROR_IO_PENDING) {
- MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent,
- this);
+ output_state_.watcher.StartWatching(
+ output_state_.overlapped.hEvent, this);
output_state_.is_pending = true;
#ifdef IPC_MESSAGE_DEBUG_EXTRA
@@ -389,42 +389,6 @@ bool Channel::ProcessOutgoingMessages() {
return true;
}
-bool Channel::ProcessPendingMessages(DWORD max_wait_msec) {
- return false;
- // TODO(darin): this code is broken and leads to busy waiting
-#if 0
- DCHECK(max_wait_msec <= 0x7FFFFFFF || max_wait_msec == INFINITE);
-
- HANDLE events[] = {
- input_state_.overlapped.hEvent,
- output_state_.overlapped.hEvent
- };
- // Only deal with output messages if we have a connection on which to send
- const int wait_count = waiting_connect_ ? 1 : 2;
- DCHECK(wait_count <= _countof(events));
-
- if (max_wait_msec) {
- DWORD result = WaitForMultipleObjects(wait_count, events, FALSE,
- max_wait_msec);
- if (result == WAIT_TIMEOUT)
- return true;
- }
-
- bool rv = true;
- for (int i = 0; i < wait_count; ++i) {
- if (WaitForSingleObject(events[i], 0) == WAIT_OBJECT_0) {
- if (i == 0 && processing_incoming_) {
- rv = false;
- DLOG(WARNING) << "Would recurse into ProcessIncomingMessages";
- } else {
- OnObjectSignaled(events[i]);
- }
- }
- }
- return rv;
-#endif
-}
-
void Channel::OnObjectSignaled(HANDLE object) {
bool ok;
if (object == input_state_.overlapped.hEvent) {
diff --git a/chrome/common/ipc_channel.h b/chrome/common/ipc_channel.h
index bf71e02..0e63a7b 100644
--- a/chrome/common/ipc_channel.h
+++ b/chrome/common/ipc_channel.h
@@ -27,19 +27,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_COMMON_IPC_CHANNEL_H__
-#define CHROME_COMMON_IPC_CHANNEL_H__
+#ifndef CHROME_COMMON_IPC_CHANNEL_H_
+#define CHROME_COMMON_IPC_CHANNEL_H_
#include <queue>
-#include "base/message_loop.h"
+#include "base/object_watcher.h"
#include "chrome/common/ipc_message.h"
namespace IPC {
//------------------------------------------------------------------------------
-class Channel : public MessageLoop::Watcher,
+class Channel : public base::ObjectWatcher::Delegate,
public Message::Sender {
// Security tests need access to the pipe handle.
friend class ChannelTest;
@@ -113,15 +113,6 @@ class Channel : public MessageLoop::Watcher,
//
virtual bool Send(Message* message);
- // Process any pending incoming and outgoing messages. Wait for at most
- // max_wait_msec for pending messages if there are none. Returns true if
- // there were no pending messages or if pending messages were successfully
- // processed. Returns false if there are pending messages that cannot be
- // processed for some reason (e.g., because ProcessIncomingMessages would be
- // re-entered).
- // TODO(darin): Need a better way of dealing with the recursion problem.
- bool ProcessPendingMessages(DWORD max_wait_msec);
-
private:
const std::wstring PipeName(const std::wstring& channel_id) const;
bool CreatePipe(const std::wstring& channel_id, Mode mode);
@@ -129,10 +120,9 @@ class Channel : public MessageLoop::Watcher,
bool ProcessIncomingMessages();
bool ProcessOutgoingMessages();
- // MessageLoop::Watcher implementation
+ // ObjectWatcher::Delegate implementation
virtual void OnObjectSignaled(HANDLE object);
- private:
enum {
BUF_SIZE = 4096
};
@@ -140,6 +130,7 @@ class Channel : public MessageLoop::Watcher,
struct State {
State();
~State();
+ base::ObjectWatcher watcher;
OVERLAPPED overlapped;
bool is_pending;
};
@@ -184,4 +175,4 @@ class Channel : public MessageLoop::Watcher,
}
-#endif // CHROME_COMMON_IPC_CHANNEL_H__
+#endif // CHROME_COMMON_IPC_CHANNEL_H_
diff --git a/chrome/common/ipc_channel_proxy.h b/chrome/common/ipc_channel_proxy.h
index ca8abb4..bb7d817 100644
--- a/chrome/common/ipc_channel_proxy.h
+++ b/chrome/common/ipc_channel_proxy.h
@@ -27,14 +27,17 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_COMMON_IPC_CHANNEL_PROXY_H__
-#define CHROME_COMMON_IPC_CHANNEL_PROXY_H__
+#ifndef CHROME_COMMON_IPC_CHANNEL_PROXY_H_
+#define CHROME_COMMON_IPC_CHANNEL_PROXY_H_
#include <vector>
+
#include "base/lock.h"
#include "base/ref_counted.h"
#include "chrome/common/ipc_channel.h"
+class MessageLoop;
+
namespace IPC {
//-----------------------------------------------------------------------------
@@ -216,4 +219,4 @@ class ChannelProxy : public Message::Sender {
} // namespace IPC
-#endif // CHROME_COMMON_IPC_CHANNEL_PROXY_H__
+#endif // CHROME_COMMON_IPC_CHANNEL_PROXY_H_
diff --git a/chrome/common/ipc_logging.cc b/chrome/common/ipc_logging.cc
index 58933e4..3c7e7dc 100644
--- a/chrome/common/ipc_logging.cc
+++ b/chrome/common/ipc_logging.cc
@@ -31,6 +31,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/thread.h"
#include "base/time.h"
@@ -42,15 +43,19 @@
#ifdef IPC_MESSAGE_LOG_ENABLED
+// IPC::Logging is allocated as a singleton, so we don't need any kind of
+// special retention program.
+template <>
+struct RunnableMethodTraits<IPC::Logging> {
+ static void RetainCallee(IPC::Logging*) {}
+ static void ReleaseCallee(IPC::Logging*) {}
+};
+
namespace IPC {
const wchar_t kLoggingEventName[] = L"ChromeIPCLog.%d";
const int kLogSendDelayMs = 100;
-scoped_refptr<Logging> Logging::current_;
-
-Lock Logging::logger_lock_;
-
Logging::Logging()
: logging_event_on_(NULL),
logging_event_off_(NULL),
@@ -86,24 +91,18 @@ Logging::Logging()
}
Logging::~Logging() {
+ watcher_.StopWatching();
CloseHandle(logging_event_on_);
CloseHandle(logging_event_off_);
}
Logging* Logging::current() {
- AutoLock lock(logger_lock_);
-
- if (!current_.get())
- current_ = new Logging();
-
- return current_;
+ return Singleton<Logging>::get();
}
void Logging::RegisterWaitForEvent(bool enabled) {
- MessageLoop::current()->WatchObject(
- enabled ? logging_event_off_ : logging_event_on_, NULL);
-
- MessageLoop::current()->WatchObject(
+ watcher_.StopWatching();
+ watcher_.StartWatching(
enabled ? logging_event_on_ : logging_event_off_, this);
}
diff --git a/chrome/common/ipc_logging.h b/chrome/common/ipc_logging.h
index 7fa2be4..9173cd7 100644
--- a/chrome/common/ipc_logging.h
+++ b/chrome/common/ipc_logging.h
@@ -27,15 +27,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_COMMON_IPC_LOGGING_H__
-#define CHROME_COMMON_IPC_LOGGING_H__
+#ifndef CHROME_COMMON_IPC_LOGGING_H_
+#define CHROME_COMMON_IPC_LOGGING_H_
#include "base/lock.h"
-#include "base/message_loop.h"
+#include "base/object_watcher.h"
+#include "base/singleton.h"
#include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
#ifdef IPC_MESSAGE_LOG_ENABLED
+class MessageLoop;
+
namespace IPC {
class Message;
@@ -43,8 +46,7 @@ class Message;
// One instance per process. Needs to be created on the main thread (the UI
// thread in the browser) but OnPreDispatchMessage/OnPostDispatchMessage
// can be called on other threads.
-class Logging : public base::RefCounted<Logging>,
- public MessageLoop::Watcher {
+class Logging : public base::ObjectWatcher::Delegate {
public:
// Implemented by consumers of log messages.
class Consumer {
@@ -85,10 +87,11 @@ class Logging : public base::RefCounted<Logging>,
static void GetMessageText(uint16 type, std::wstring* name,
const Message* message, std::wstring* params);
- // MessageLoop::Watcher
+ // ObjectWatcher::Delegate implementation
void OnObjectSignaled(HANDLE object);
private:
+ friend struct DefaultSingletonTraits<IPC::Logging>;
Logging();
std::wstring GetEventName(int browser_pid, bool enabled);
@@ -97,6 +100,8 @@ class Logging : public base::RefCounted<Logging>,
void RegisterWaitForEvent(bool enabled);
+ base::ObjectWatcher watcher_;
+
HANDLE logging_event_on_;
HANDLE logging_event_off_;
bool enabled_;
@@ -108,14 +113,10 @@ class Logging : public base::RefCounted<Logging>,
MessageLoop* main_thread_;
Consumer* consumer_;
-
- static scoped_refptr<Logging> current_;
-
- static Lock logger_lock_;
};
} // namespace IPC
#endif // IPC_MESSAGE_LOG_ENABLED
-#endif // CHROME_COMMON_IPC_LOGGING_H__
+#endif // CHROME_COMMON_IPC_LOGGING_H_
diff --git a/chrome/common/message_router.h b/chrome/common/message_router.h
index a5fabf4..0558646 100644
--- a/chrome/common/message_router.h
+++ b/chrome/common/message_router.h
@@ -30,6 +30,7 @@
#ifndef CHROME_COMMON_MESSAGE_ROUTER_H__
#define CHROME_COMMON_MESSAGE_ROUTER_H__
+#include "base/id_map.h"
#include "chrome/common/ipc_channel.h"
// The MessageRouter handles all incoming messages sent to it by routing them
diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc
index d8d1171..4d6ce22 100644
--- a/chrome/common/resource_dispatcher.cc
+++ b/chrome/common/resource_dispatcher.cc
@@ -32,6 +32,7 @@
#include "chrome/common/resource_dispatcher.h"
#include "base/basictypes.h"
+#include "base/message_loop.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "chrome/common/render_messages.h"
diff --git a/chrome/renderer/net/render_dns_master.cc b/chrome/renderer/net/render_dns_master.cc
index 01f8c78..507c816 100644
--- a/chrome/renderer/net/render_dns_master.cc
+++ b/chrome/renderer/net/render_dns_master.cc
@@ -35,6 +35,7 @@
#include <ctype.h>
#include "base/logging.h"
+#include "base/message_loop.h"
#include "chrome/common/net/dns.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/net/render_dns_queue.h"