Author:
cra...@chromium.org
Date: Wed May 16 11:45:10 2012
New Revision: 137466
Log:
Fixed a possible memory leak and support null pointers in AutomationEventObservers' NotifyEvent.
BUG=None
TEST=functional/apptest.py
Review URL:
https://chromiumcodereview.appspot.com/10386144
Modified:
trunk/src/chrome/browser/automation/automation_event_observers.cc
trunk/src/chrome/browser/automation/automation_event_observers_chromeos.cc
trunk/src/chrome/browser/automation/automation_event_queue.cc
Modified: trunk/src/chrome/browser/automation/automation_event_observers.cc
==============================================================================
--- trunk/src/chrome/browser/automation/automation_event_observers.cc (original)
+++ trunk/src/chrome/browser/automation/automation_event_observers.cc Wed May 16 11:45:10 2012
@@ -29,10 +29,15 @@
void AutomationEventObserver::NotifyEvent(DictionaryValue* value) {
if (event_queue_) {
+ if (!value)
+ value = new DictionaryValue;
+ value->SetInteger("observer_id", GetId());
event_queue_->NotifyEvent(
new AutomationEventQueue::AutomationEvent(
GetId(), value));
event_count_++;
+ } else if (value) {
+ delete value;
}
}
@@ -92,7 +97,6 @@
DictionaryValue* dict = new DictionaryValue;
dict->SetString("type", "raised_event");
dict->SetString("name", dom_op_details->json);
- dict->SetInteger("observer_id", GetId());
NotifyEvent(dict);
}
}
Modified: trunk/src/chrome/browser/automation/automation_event_observers_chromeos.cc
==============================================================================
--- trunk/src/chrome/browser/automation/automation_event_observers_chromeos.cc (original)
+++ trunk/src/chrome/browser/automation/automation_event_observers_chromeos.cc Wed May 16 11:45:10 2012
@@ -38,7 +38,6 @@
void LoginEventObserver::_NotifyLoginEvent(const std::string& error_string) {
DictionaryValue* dict = new DictionaryValue;
dict->SetString("type", "login_event");
- dict->SetInteger("observer_id", GetId());
if (error_string.length())
dict->SetString("error_string", error_string);
NotifyEvent(dict);
Modified: trunk/src/chrome/browser/automation/automation_event_queue.cc
==============================================================================
--- trunk/src/chrome/browser/automation/automation_event_queue.cc (original)
+++ trunk/src/chrome/browser/automation/automation_event_queue.cc Wed May 16 11:45:10 2012
@@ -4,6 +4,7 @@
#include <algorithm>
+#include "base/logging.h"
#include "chrome/browser/automation/automation_event_observers.h"
#include "chrome/browser/automation/automation_event_queue.h"
#include "chrome/browser/automation/automation_provider_json.h"
@@ -74,6 +75,8 @@
void AutomationEventQueue::NotifyEvent(
AutomationEventQueue::AutomationEvent* event) {
+ DCHECK(event);
+ VLOG(2) << "AutomationEventQueue::NotifyEvent id=" << event->GetId();
event_queue_.push_front(event);
CheckReturnEvent();
}
@@ -87,6 +90,7 @@
bool AutomationEventQueue::RemoveObserver(int observer_id) {
if (observers_.find(observer_id) != observers_.end()) {
+ VLOG(2) << "AutomationEventQueue::RemoveObserver id=" << observer_id;
delete observers_[observer_id];
observers_.erase(observer_id);
return true;