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

Side by Side Diff: extensions/browser/event_router.cc

Issue 2523913003: Fix bugs in filtered event removal code (Closed)
Patch Set: sync @tott Created 4 years 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/browser/event_router.h ('k') | extensions/browser/event_router_unittest.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 "extensions/browser/event_router.h" 5 #include "extensions/browser/event_router.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 #include <utility> 10 #include <utility>
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 void EventRouter::AddFilterToEvent(const std::string& event_name, 390 void EventRouter::AddFilterToEvent(const std::string& event_name,
391 const std::string& extension_id, 391 const std::string& extension_id,
392 const DictionaryValue* filter) { 392 const DictionaryValue* filter) {
393 ExtensionPrefs::ScopedDictionaryUpdate update( 393 ExtensionPrefs::ScopedDictionaryUpdate update(
394 extension_prefs_, extension_id, kFilteredEvents); 394 extension_prefs_, extension_id, kFilteredEvents);
395 DictionaryValue* filtered_events = update.Get(); 395 DictionaryValue* filtered_events = update.Get();
396 if (!filtered_events) 396 if (!filtered_events)
397 filtered_events = update.Create(); 397 filtered_events = update.Create();
398 398
399 ListValue* filter_list = nullptr; 399 ListValue* filter_list = nullptr;
400 if (!filtered_events->GetList(event_name, &filter_list)) { 400 if (!filtered_events->GetListWithoutPathExpansion(event_name, &filter_list)) {
401 filter_list = new ListValue; 401 filter_list = new ListValue;
402 filtered_events->SetWithoutPathExpansion(event_name, 402 filtered_events->SetWithoutPathExpansion(event_name,
403 base::WrapUnique(filter_list)); 403 base::WrapUnique(filter_list));
404 } 404 }
405 405
406 filter_list->Append(filter->CreateDeepCopy()); 406 filter_list->Append(filter->CreateDeepCopy());
407 } 407 }
408 408
409 void EventRouter::RemoveFilterFromEvent(const std::string& event_name, 409 void EventRouter::RemoveFilterFromEvent(const std::string& event_name,
410 const std::string& extension_id, 410 const std::string& extension_id,
411 const DictionaryValue* filter) { 411 const DictionaryValue* filter) {
412 ExtensionPrefs::ScopedDictionaryUpdate update( 412 ExtensionPrefs::ScopedDictionaryUpdate update(
413 extension_prefs_, extension_id, kFilteredEvents); 413 extension_prefs_, extension_id, kFilteredEvents);
414 DictionaryValue* filtered_events = update.Get(); 414 DictionaryValue* filtered_events = update.Get();
415 ListValue* filter_list = NULL; 415 ListValue* filter_list = NULL;
416 if (!filtered_events || 416 if (!filtered_events ||
417 !filtered_events->GetListWithoutPathExpansion(event_name, &filter_list)) { 417 !filtered_events->GetListWithoutPathExpansion(event_name, &filter_list)) {
418 return; 418 return;
419 } 419 }
420 420
421 for (size_t i = 0; i < filter_list->GetSize(); i++) { 421 for (size_t i = 0; i < filter_list->GetSize(); i++) {
422 DictionaryValue* filter = NULL; 422 DictionaryValue* filter_value = nullptr;
423 CHECK(filter_list->GetDictionary(i, &filter)); 423 CHECK(filter_list->GetDictionary(i, &filter_value));
424 if (filter->Equals(filter)) { 424 if (filter_value->Equals(filter)) {
425 filter_list->Remove(i, NULL); 425 filter_list->Remove(i, nullptr);
426 break; 426 break;
427 } 427 }
428 } 428 }
429 } 429 }
430 430
431 const DictionaryValue* EventRouter::GetFilteredEvents( 431 const DictionaryValue* EventRouter::GetFilteredEvents(
432 const std::string& extension_id) { 432 const std::string& extension_id) {
433 const DictionaryValue* events = NULL; 433 const DictionaryValue* events = NULL;
434 extension_prefs_->ReadPrefAsDictionary( 434 extension_prefs_->ReadPrefAsDictionary(
435 extension_id, kFilteredEvents, &events); 435 extension_id, kFilteredEvents, &events);
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 const std::string& extension_id, 883 const std::string& extension_id,
884 const GURL& listener_url, 884 const GURL& listener_url,
885 content::BrowserContext* browser_context) 885 content::BrowserContext* browser_context)
886 : event_name(event_name), 886 : event_name(event_name),
887 extension_id(extension_id), 887 extension_id(extension_id),
888 listener_url(listener_url), 888 listener_url(listener_url),
889 browser_context(browser_context) { 889 browser_context(browser_context) {
890 } 890 }
891 891
892 } // namespace extensions 892 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/event_router.h ('k') | extensions/browser/event_router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698