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

Issue 2303113002: Fix semantics of ExtensionWebRequestEventRouter::EventListeners. (Closed)

Created:
4 years, 3 months ago by erikchen
Modified:
4 years, 3 months ago
Reviewers:
Devlin
CC:
chromium-reviews, chromium-apps-reviews_chromium.org, extensions-reviews_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Fix semantics of ExtensionWebRequestEventRouter::EventListeners. There are two types of EventListeners: those with web_view_instance_id and those without. EventListeners with a web_view_instance_id need to always consider embedder_process_id for equality comparisons. EventListeners without a web_view_instance_id should sometimes ignore embedder_process_id (when being removed) for equality comparisons. The previous code had two major issues: 1) EventListeners were stored in a std::set. std:set requires a stable sort operator. There is no way to create a stable sort operator that sometimes ignores embedder_process_id. Aside: std::set is almost never the right container to use from a performance perspective. In this case, the code frequently needs to iterate through the entire container away, so I've changed the container to be a std::vector (we expect the total number of elements to be small). If we find performance issues, we should switch to std::unordered_set. 2) EventListeners need to be messaged asynchronously, but it's possible that the EventListener is no longer registered by the time the callback comes around. The previous code would make a copy of the EventListener, and then try to "find" the original copy in the callback. Once again, this requires clear semantics for equality. The new code makes several changes: 1) Create the class EventListener::ID. As its name implies, this uniquely identifies an EventListener. 2) Disallow copy and assignment of EventListeners. The only use case is async identity checking, which should use EventListener::ID instead. 3) This cleanup means EventListener::blocked_requests no longer has to be mutable. (A clear sign that something was wrong with the previous scheme). The most important result is that it is no longer possible to have identity confusion between EventListeners, as all comparisons use EventListener::ID. This was the root cause of the leak from Issue 643025. BUG=643025, 641958 Committed: https://crrev.com/7cdfec136b896222345c88f56e89a2d40d53e49c Cr-Commit-Position: refs/heads/master@{#417398}

Patch Set 1 #

Patch Set 2 : clang format. #

Patch Set 3 : Rebase. #

Patch Set 4 : Compile error on Linux. #

Total comments: 20

Patch Set 5 : Comments from rdevlin. #

Total comments: 16

Patch Set 6 : Comments from rdevlin.cronin. #

Total comments: 4

Patch Set 7 : Comments from rdevlin. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+445 lines, -259 lines) Patch
M chrome/browser/extensions/api/web_request/web_request_api_unittest.cc View 1 2 3 4 5 11 chunks +160 lines, -23 lines 0 comments Download
M extensions/browser/api/web_request/web_request_api.h View 1 2 3 4 5 6 chunks +97 lines, -29 lines 0 comments Download
M extensions/browser/api/web_request/web_request_api.cc View 1 2 3 4 5 6 26 chunks +188 lines, -207 lines 0 comments Download

Messages

Total messages: 27 (15 generated)
erikchen
rdevlin: Please review.
4 years, 3 months ago (2016-09-02 02:14:21 UTC) #5
Devlin
On 2016/09/02 02:14:21, erikchen wrote: > rdevlin: Please review. haven't taken a close look yet, ...
4 years, 3 months ago (2016-09-02 04:00:10 UTC) #9
erikchen
On 2016/09/02 04:00:10, Devlin wrote: > On 2016/09/02 02:14:21, erikchen wrote: > > rdevlin: Please ...
4 years, 3 months ago (2016-09-06 22:31:03 UTC) #14
Devlin
https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.cc File extensions/browser/api/web_request/web_request_api.cc (right): https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.cc#newcode984 extensions/browser/api/web_request/web_request_api.cc:984: EventListener* listener = FindEventListener(id); This makes me a bit ...
4 years, 3 months ago (2016-09-07 19:18:00 UTC) #15
erikchen
rdevlin: PTAL https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.cc File extensions/browser/api/web_request/web_request_api.cc (right): https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.cc#newcode984 extensions/browser/api/web_request/web_request_api.cc:984: EventListener* listener = FindEventListener(id); On 2016/09/07 19:18:00, ...
4 years, 3 months ago (2016-09-07 22:07:43 UTC) #16
Devlin
https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.h File extensions/browser/api/web_request/web_request_api.h (right): https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.h#newcode331 extensions/browser/api/web_request/web_request_api.h:331: // An EventListener is uniquely defined by five properties. ...
4 years, 3 months ago (2016-09-08 17:33:13 UTC) #17
erikchen
https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.h File extensions/browser/api/web_request/web_request_api.h (right): https://codereview.chromium.org/2303113002/diff/60001/extensions/browser/api/web_request/web_request_api.h#newcode331 extensions/browser/api/web_request/web_request_api.h:331: // An EventListener is uniquely defined by five properties. ...
4 years, 3 months ago (2016-09-08 18:34:42 UTC) #18
Devlin
lgtm. Please also update the CL description since it's slightly out of date (e.g., EventListener::Identifier ...
4 years, 3 months ago (2016-09-08 19:53:32 UTC) #19
erikchen
https://codereview.chromium.org/2303113002/diff/100001/extensions/browser/api/web_request/web_request_api.cc File extensions/browser/api/web_request/web_request_api.cc (right): https://codereview.chromium.org/2303113002/diff/100001/extensions/browser/api/web_request/web_request_api.cc#newcode367 extensions/browser/api/web_request/web_request_api.cc:367: false)); On 2016/09/08 19:53:32, Devlin wrote: > add /* ...
4 years, 3 months ago (2016-09-08 20:04:25 UTC) #21
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2303113002/120001
4 years, 3 months ago (2016-09-08 20:05:09 UTC) #24
commit-bot: I haz the power
Committed patchset #7 (id:120001)
4 years, 3 months ago (2016-09-08 21:15:06 UTC) #25
commit-bot: I haz the power
4 years, 3 months ago (2016-09-08 21:16:53 UTC) #27
Message was sent while issue was closed.
Patchset 7 (id:??) landed as
https://crrev.com/7cdfec136b896222345c88f56e89a2d40d53e49c
Cr-Commit-Position: refs/heads/master@{#417398}

Powered by Google App Engine
This is Rietveld 408576698