summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 08:34:08 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-09 08:34:08 +0000
commit2de755222010708f16ea99af9e3dc2cfe41f96cf (patch)
tree7c2789878bf6fcfe00e8a39e43832479f5b89e11
parent0e48e9dc55bd35d15db0476fbcf1c3529a5fa8de (diff)
downloadchromium_src-2de755222010708f16ea99af9e3dc2cfe41f96cf.zip
chromium_src-2de755222010708f16ea99af9e3dc2cfe41f96cf.tar.gz
chromium_src-2de755222010708f16ea99af9e3dc2cfe41f96cf.tar.bz2
rollback r625 because it made things slower
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@631 0039d316-1c4b-4281-b951-d872f2087c98
-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
7 files changed, 91 insertions, 51 deletions
diff --git a/chrome/common/ipc_channel.cc b/chrome/common/ipc_channel.cc
index 96b0f9b..d469736 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
- input_state_.watcher.StopWatching();
- output_state_.watcher.StopWatching();
+ MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
+ MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent, NULL);
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);
- input_state_.watcher.StartWatching(input_state_.overlapped.hEvent, this);
+ MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, this);
}
if (!waiting_connect_)
@@ -203,7 +203,7 @@ bool Channel::Connect() {
bool Channel::ProcessConnection() {
input_state_.is_pending = false;
- input_state_.watcher.StopWatching();
+ MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
// 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;
- input_state_.watcher.StartWatching(input_state_.overlapped.hEvent, this);
+ MessageLoop::current()->WatchObject(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;
- input_state_.watcher.StopWatching();
+ MessageLoop::current()->WatchObject(input_state_.overlapped.hEvent, NULL);
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) {
- input_state_.watcher.StartWatching(
- input_state_.overlapped.hEvent, this);
+ MessageLoop::current()->WatchObject(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) {
- output_state_.watcher.StopWatching();
+ MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent, NULL);
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) {
- output_state_.watcher.StartWatching(
- output_state_.overlapped.hEvent, this);
+ MessageLoop::current()->WatchObject(output_state_.overlapped.hEvent,
+ this);
output_state_.is_pending = true;
#ifdef IPC_MESSAGE_DEBUG_EXTRA
@@ -389,6 +389,42 @@ 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 0e63a7b..bf71e02 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/object_watcher.h"
+#include "base/message_loop.h"
#include "chrome/common/ipc_message.h"
namespace IPC {
//------------------------------------------------------------------------------
-class Channel : public base::ObjectWatcher::Delegate,
+class Channel : public MessageLoop::Watcher,
public Message::Sender {
// Security tests need access to the pipe handle.
friend class ChannelTest;
@@ -113,6 +113,15 @@ class Channel : public base::ObjectWatcher::Delegate,
//
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);
@@ -120,9 +129,10 @@ class Channel : public base::ObjectWatcher::Delegate,
bool ProcessIncomingMessages();
bool ProcessOutgoingMessages();
- // ObjectWatcher::Delegate implementation
+ // MessageLoop::Watcher implementation
virtual void OnObjectSignaled(HANDLE object);
+ private:
enum {
BUF_SIZE = 4096
};
@@ -130,7 +140,6 @@ class Channel : public base::ObjectWatcher::Delegate,
struct State {
State();
~State();
- base::ObjectWatcher watcher;
OVERLAPPED overlapped;
bool is_pending;
};
@@ -175,4 +184,4 @@ class Channel : public base::ObjectWatcher::Delegate,
}
-#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 bb7d817..ca8abb4 100644
--- a/chrome/common/ipc_channel_proxy.h
+++ b/chrome/common/ipc_channel_proxy.h
@@ -27,17 +27,14 @@
// (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 {
//-----------------------------------------------------------------------------
@@ -219,4 +216,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 3c7e7dc..58933e4 100644
--- a/chrome/common/ipc_logging.cc
+++ b/chrome/common/ipc_logging.cc
@@ -31,7 +31,6 @@
#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"
@@ -43,19 +42,15 @@
#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),
@@ -91,18 +86,24 @@ Logging::Logging()
}
Logging::~Logging() {
- watcher_.StopWatching();
CloseHandle(logging_event_on_);
CloseHandle(logging_event_off_);
}
Logging* Logging::current() {
- return Singleton<Logging>::get();
+ AutoLock lock(logger_lock_);
+
+ if (!current_.get())
+ current_ = new Logging();
+
+ return current_;
}
void Logging::RegisterWaitForEvent(bool enabled) {
- watcher_.StopWatching();
- watcher_.StartWatching(
+ MessageLoop::current()->WatchObject(
+ enabled ? logging_event_off_ : logging_event_on_, NULL);
+
+ MessageLoop::current()->WatchObject(
enabled ? logging_event_on_ : logging_event_off_, this);
}
diff --git a/chrome/common/ipc_logging.h b/chrome/common/ipc_logging.h
index 9173cd7..7fa2be4 100644
--- a/chrome/common/ipc_logging.h
+++ b/chrome/common/ipc_logging.h
@@ -27,18 +27,15 @@
// (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/object_watcher.h"
-#include "base/singleton.h"
+#include "base/message_loop.h"
#include "chrome/common/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED.
#ifdef IPC_MESSAGE_LOG_ENABLED
-class MessageLoop;
-
namespace IPC {
class Message;
@@ -46,7 +43,8 @@ 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::ObjectWatcher::Delegate {
+class Logging : public base::RefCounted<Logging>,
+ public MessageLoop::Watcher {
public:
// Implemented by consumers of log messages.
class Consumer {
@@ -87,11 +85,10 @@ class Logging : public base::ObjectWatcher::Delegate {
static void GetMessageText(uint16 type, std::wstring* name,
const Message* message, std::wstring* params);
- // ObjectWatcher::Delegate implementation
+ // MessageLoop::Watcher
void OnObjectSignaled(HANDLE object);
private:
- friend struct DefaultSingletonTraits<IPC::Logging>;
Logging();
std::wstring GetEventName(int browser_pid, bool enabled);
@@ -100,8 +97,6 @@ class Logging : public base::ObjectWatcher::Delegate {
void RegisterWaitForEvent(bool enabled);
- base::ObjectWatcher watcher_;
-
HANDLE logging_event_on_;
HANDLE logging_event_off_;
bool enabled_;
@@ -113,10 +108,14 @@ class Logging : public base::ObjectWatcher::Delegate {
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 0558646..a5fabf4 100644
--- a/chrome/common/message_router.h
+++ b/chrome/common/message_router.h
@@ -30,7 +30,6 @@
#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 4d6ce22..d8d1171 100644
--- a/chrome/common/resource_dispatcher.cc
+++ b/chrome/common/resource_dispatcher.cc
@@ -32,7 +32,6 @@
#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"