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

Side by Side Diff: chrome/browser/automation/automation_event_queue.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
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h"
7 #include "chrome/browser/automation/automation_event_observers.h" 8 #include "chrome/browser/automation/automation_event_observers.h"
8 #include "chrome/browser/automation/automation_event_queue.h" 9 #include "chrome/browser/automation/automation_event_queue.h"
9 #include "chrome/browser/automation/automation_provider_json.h" 10 #include "chrome/browser/automation/automation_provider_json.h"
10 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
12 13
13 AutomationEventQueue::CompareObserverId::CompareObserverId(int id) : id_(id) {} 14 AutomationEventQueue::CompareObserverId::CompareObserverId(int id) : id_(id) {}
14 15
15 bool AutomationEventQueue::CompareObserverId::operator()( 16 bool AutomationEventQueue::CompareObserverId::operator()(
16 AutomationEvent* event) const { 17 AutomationEvent* event) const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 CompareObserverId(observer_id)); 68 CompareObserverId(observer_id));
68 if (it != event_queue_.rend()) { 69 if (it != event_queue_.rend()) {
69 event = *it; 70 event = *it;
70 event_queue_.remove(event); 71 event_queue_.remove(event);
71 } 72 }
72 return event; 73 return event;
73 } 74 }
74 75
75 void AutomationEventQueue::NotifyEvent( 76 void AutomationEventQueue::NotifyEvent(
76 AutomationEventQueue::AutomationEvent* event) { 77 AutomationEventQueue::AutomationEvent* event) {
78 DCHECK(event);
79 VLOG(2) << "AutomationEventQueue::NotifyEvent id=" << event->GetId();
77 event_queue_.push_front(event); 80 event_queue_.push_front(event);
78 CheckReturnEvent(); 81 CheckReturnEvent();
79 } 82 }
80 83
81 int AutomationEventQueue::AddObserver(AutomationEventObserver* observer) { 84 int AutomationEventQueue::AddObserver(AutomationEventObserver* observer) {
82 int id = observer_id_count_++; 85 int id = observer_id_count_++;
83 observer->Init(id); 86 observer->Init(id);
84 observers_[id] = observer; 87 observers_[id] = observer;
85 return id; 88 return id;
86 } 89 }
87 90
88 bool AutomationEventQueue::RemoveObserver(int observer_id) { 91 bool AutomationEventQueue::RemoveObserver(int observer_id) {
89 if (observers_.find(observer_id) != observers_.end()) { 92 if (observers_.find(observer_id) != observers_.end()) {
93 VLOG(2) << "AutomationEventQueue::RemoveObserver id=" << observer_id;
90 delete observers_[observer_id]; 94 delete observers_[observer_id];
91 observers_.erase(observer_id); 95 observers_.erase(observer_id);
92 return true; 96 return true;
93 } 97 }
94 return false; 98 return false;
95 } 99 }
96 100
97 void AutomationEventQueue::ClearObservers() { 101 void AutomationEventQueue::ClearObservers() {
98 std::map<int, AutomationEventObserver*>::iterator it; 102 std::map<int, AutomationEventObserver*>::iterator it;
99 for (it = observers_.begin(); it != observers_.end(); it++) { 103 for (it = observers_.begin(); it != observers_.end(); it++) {
(...skipping 18 matching lines...) Expand all
118 if (event) { 122 if (event) {
119 wait_automation_reply_->SendSuccess(event->GetValue()); 123 wait_automation_reply_->SendSuccess(event->GetValue());
120 wait_automation_reply_.reset(); 124 wait_automation_reply_.reset();
121 wait_observer_id_ = -1; 125 wait_observer_id_ = -1;
122 delete event; 126 delete event;
123 return true; 127 return true;
124 } 128 }
125 } 129 }
126 return false; 130 return false;
127 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698