Skip to content

Commit

Permalink
GTTF: Make automation provider recognize more IPC error conditions
Browse files Browse the repository at this point in the history
1) Report IPC message deserialization errors in "delay reply" handlers.
2) Handle those errors in automation provider.

BUG=77875
Review URL: http://codereview.chromium.org/6675047

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79980 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
phajdan.jr@chromium.org committed Mar 31, 2011
1 parent d4a952f commit 1e92769
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions chrome/browser/automation/automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ void AutomationProvider::OnChannelConnected(int pid) {

bool AutomationProvider::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
bool deserialize_success = true;
IPC_BEGIN_MESSAGE_MAP_EX(AutomationProvider, message, deserialize_success)
#if !defined(OS_MACOSX)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
WindowSimulateDrag)
Expand Down Expand Up @@ -407,8 +408,10 @@ bool AutomationProvider::OnMessageReceived(const IPC::Message& message) {
OnRunUnloadHandlers)
IPC_MESSAGE_HANDLER(AutomationMsg_SetZoomLevel, OnSetZoomLevel)
#endif // defined(OS_WIN)
IPC_MESSAGE_UNHANDLED(handled = false;OnUnhandledMessage())
IPC_END_MESSAGE_MAP()
IPC_MESSAGE_UNHANDLED(handled = false; OnUnhandledMessage())
IPC_END_MESSAGE_MAP_EX()
if (!deserialize_success)
OnMessageDeserializationFailure();
return handled;
}

Expand All @@ -425,6 +428,12 @@ void AutomationProvider::OnUnhandledMessage() {
channel_->Close();
}

void AutomationProvider::OnMessageDeserializationFailure() {
LOG(ERROR) << "Failed to deserialize IPC message. "
<< "Closing the automation channel.";
channel_->Close();
}

// This task just adds another task to the event queue. This is useful if
// you want to ensure that any tasks added to the event queue after this one
// have already been processed by the time |task| is run.
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/automation/automation_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class AutomationProvider
// Returns NULL on failure.
RenderViewHost* GetViewForTab(int tab_handle);

// Called on IPC message deserialization failure. Prints an error message
// and closes the IPC channel.
void OnMessageDeserializationFailure();

scoped_ptr<AutomationAutocompleteEditTracker> autocomplete_edit_tracker_;
scoped_ptr<AutomationBrowserTracker> browser_tracker_;
scoped_ptr<InitialLoadObserver> initial_load_observer_;
Expand Down
9 changes: 7 additions & 2 deletions chrome/browser/automation/testing_automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ void TestingAutomationProvider::Observe(NotificationType type,
bool TestingAutomationProvider::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(TestingAutomationProvider, message)
bool deserialize_success = true;
IPC_BEGIN_MESSAGE_MAP_EX(TestingAutomationProvider,
message,
deserialize_success)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
CloseBrowserAsync)
Expand Down Expand Up @@ -382,7 +385,9 @@ bool TestingAutomationProvider::OnMessageReceived(

IPC_MESSAGE_UNHANDLED(
handled = AutomationProvider::OnMessageReceived(message))
IPC_END_MESSAGE_MAP()
IPC_END_MESSAGE_MAP_EX()
if (!deserialize_success)
OnMessageDeserializationFailure();
return handled;
}

Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ LogFunctionMap g_log_function_mapping;

#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
case msg_class::ID: \
msg_class::DispatchDelayReply(&ipc_message__, obj, &member_func); \
msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, &member_func); \
break;

#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
Expand Down

0 comments on commit 1e92769

Please sign in to comment.