Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: chrome/browser/automation/automation_event_observers.cc

Issue 10386144: Fixed a possible memory leak and support null pointers in AutomationEventObservers' NotifyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/automation/automation_event_observers_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/automation/automation_event_observers.h" 9 #include "chrome/browser/automation/automation_event_observers.h"
10 #include "chrome/browser/automation/automation_event_queue.h" 10 #include "chrome/browser/automation/automation_event_queue.h"
(...skipping 10 matching lines...) Expand all
21 : event_queue_(event_queue), 21 : event_queue_(event_queue),
22 recurring_(recurring), 22 recurring_(recurring),
23 observer_id_(-1), 23 observer_id_(-1),
24 event_count_(0) { 24 event_count_(0) {
25 DCHECK(event_queue_ != NULL); 25 DCHECK(event_queue_ != NULL);
26 } 26 }
27 27
28 AutomationEventObserver::~AutomationEventObserver() {} 28 AutomationEventObserver::~AutomationEventObserver() {}
29 29
30 void AutomationEventObserver::NotifyEvent(DictionaryValue* value) { 30 void AutomationEventObserver::NotifyEvent(DictionaryValue* value) {
31 if (event_queue_) { 31 if (event_queue_) {
dennis_jeffrey 2012/05/16 16:55:42 Will "value" get deleted on the "true" branch of t
craigdh 2012/05/16 17:00:55 Yes. On "true" the AutomationEventQueue takes owne
32 if (!value)
33 value = new DictionaryValue;
dennis_jeffrey 2012/05/16 16:55:42 Is this check needed? It looks like both callers
craigdh 2012/05/16 17:00:55 Right now NULL is not being passed, but is because
34 value->SetInteger("observer_id", GetId());
32 event_queue_->NotifyEvent( 35 event_queue_->NotifyEvent(
33 new AutomationEventQueue::AutomationEvent( 36 new AutomationEventQueue::AutomationEvent(
34 GetId(), value)); 37 GetId(), value));
35 event_count_++; 38 event_count_++;
39 } else if (value) {
40 delete value;
36 } 41 }
37 } 42 }
38 43
39 void AutomationEventObserver::Init(int observer_id) { 44 void AutomationEventObserver::Init(int observer_id) {
40 observer_id_ = observer_id; 45 observer_id_ = observer_id;
41 } 46 }
42 47
43 int AutomationEventObserver::GetId() const { 48 int AutomationEventObserver::GetId() const {
44 return observer_id_; 49 return observer_id_;
45 } 50 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { 90 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) {
86 content::Details<content::DomOperationNotificationDetails> dom_op_details( 91 content::Details<content::DomOperationNotificationDetails> dom_op_details(
87 details); 92 details);
88 if ((dom_op_details->automation_id == automation_id_ || 93 if ((dom_op_details->automation_id == automation_id_ ||
89 automation_id_ == -1) && 94 automation_id_ == -1) &&
90 (event_name_.length() == 0 || 95 (event_name_.length() == 0 ||
91 event_name_.compare(dom_op_details->json) == 0)) { 96 event_name_.compare(dom_op_details->json) == 0)) {
92 DictionaryValue* dict = new DictionaryValue; 97 DictionaryValue* dict = new DictionaryValue;
93 dict->SetString("type", "raised_event"); 98 dict->SetString("type", "raised_event");
94 dict->SetString("name", dom_op_details->json); 99 dict->SetString("name", dom_op_details->json);
95 dict->SetInteger("observer_id", GetId());
96 NotifyEvent(dict); 100 NotifyEvent(dict);
97 } 101 }
98 } 102 }
99 // Nothing should happen after RemoveIfDone() as it may delete the object. 103 // Nothing should happen after RemoveIfDone() as it may delete the object.
100 RemoveIfDone(); 104 RemoveIfDone();
101 } 105 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/automation_event_observers_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698