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

Side by Side Diff: extensions/renderer/event_bindings.cc

Issue 2252373002: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « extensions/common/value_counter.cc ('k') | extensions/renderer/i18n_custom_bindings.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/event_bindings.h" 5 #include "extensions/renderer/event_bindings.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Add a filter to |event_name| in |extension_id|, returning true if it 119 // Add a filter to |event_name| in |extension_id|, returning true if it
120 // was the first filter for that event in that extension. 120 // was the first filter for that event in that extension.
121 bool AddFilter(const std::string& event_name, 121 bool AddFilter(const std::string& event_name,
122 const std::string& extension_id, 122 const std::string& extension_id,
123 const base::DictionaryValue& filter) { 123 const base::DictionaryValue& filter) {
124 FilteredEventListenerKey key(extension_id, event_name); 124 FilteredEventListenerKey key(extension_id, event_name);
125 FilteredEventListenerCounts& all_counts = g_filtered_listener_counts.Get(); 125 FilteredEventListenerCounts& all_counts = g_filtered_listener_counts.Get();
126 FilteredEventListenerCounts::const_iterator counts = all_counts.find(key); 126 FilteredEventListenerCounts::const_iterator counts = all_counts.find(key);
127 if (counts == all_counts.end()) { 127 if (counts == all_counts.end()) {
128 counts = 128 counts =
129 all_counts 129 all_counts.insert(std::make_pair(key, base::MakeUnique<ValueCounter>()))
130 .insert(std::make_pair(key, base::WrapUnique(new ValueCounter())))
131 .first; 130 .first;
132 } 131 }
133 return counts->second->Add(filter); 132 return counts->second->Add(filter);
134 } 133 }
135 134
136 // Remove a filter from |event_name| in |extension_id|, returning true if it 135 // Remove a filter from |event_name| in |extension_id|, returning true if it
137 // was the last filter for that event in that extension. 136 // was the last filter for that event in that extension.
138 bool RemoveFilter(const std::string& event_name, 137 bool RemoveFilter(const std::string& event_name,
139 const std::string& extension_id, 138 const std::string& extension_id,
140 base::DictionaryValue* filter) { 139 base::DictionaryValue* filter) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 for (MatcherIDs::iterator it = matched_event_filters.begin(); 339 for (MatcherIDs::iterator it = matched_event_filters.begin();
341 it != matched_event_filters.end(); 340 it != matched_event_filters.end();
342 ++it) { 341 ++it) {
343 array->Set(v8::Integer::New(isolate, i++), v8::Integer::New(isolate, *it)); 342 array->Set(v8::Integer::New(isolate, i++), v8::Integer::New(isolate, *it));
344 } 343 }
345 args.GetReturnValue().Set(array); 344 args.GetReturnValue().Set(array);
346 } 345 }
347 346
348 std::unique_ptr<EventMatcher> EventBindings::ParseEventMatcher( 347 std::unique_ptr<EventMatcher> EventBindings::ParseEventMatcher(
349 std::unique_ptr<base::DictionaryValue> filter) { 348 std::unique_ptr<base::DictionaryValue> filter) {
350 return base::WrapUnique(new EventMatcher( 349 return base::MakeUnique<EventMatcher>(
351 std::move(filter), context()->GetRenderFrame()->GetRoutingID())); 350 std::move(filter), context()->GetRenderFrame()->GetRoutingID());
352 } 351 }
353 352
354 void EventBindings::OnInvalidated() { 353 void EventBindings::OnInvalidated() {
355 // Detach all attached events that weren't attached. Iterate over a copy 354 // Detach all attached events that weren't attached. Iterate over a copy
356 // because it will be mutated. 355 // because it will be mutated.
357 std::set<std::string> attached_event_names_safe = attached_event_names_; 356 std::set<std::string> attached_event_names_safe = attached_event_names_;
358 for (const std::string& event_name : attached_event_names_safe) { 357 for (const std::string& event_name : attached_event_names_safe) {
359 DetachEvent(event_name, false /* is_manual */); 358 DetachEvent(event_name, false /* is_manual */);
360 } 359 }
361 DCHECK(attached_event_names_.empty()) 360 DCHECK(attached_event_names_.empty())
362 << "Events cannot be attached during invalidation"; 361 << "Events cannot be attached during invalidation";
363 362
364 // Same for filtered events. 363 // Same for filtered events.
365 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; 364 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_;
366 for (int matcher_id : attached_matcher_ids_safe) { 365 for (int matcher_id : attached_matcher_ids_safe) {
367 DetachFilteredEvent(matcher_id, false /* is_manual */); 366 DetachFilteredEvent(matcher_id, false /* is_manual */);
368 } 367 }
369 DCHECK(attached_matcher_ids_.empty()) 368 DCHECK(attached_matcher_ids_.empty())
370 << "Filtered events cannot be attached during invalidation"; 369 << "Filtered events cannot be attached during invalidation";
371 } 370 }
372 371
373 } // namespace extensions 372 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/value_counter.cc ('k') | extensions/renderer/i18n_custom_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698