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

Issue 6698009: Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events. (Closed)

Created:
9 years, 9 months ago by Matt Perry
Modified:
9 years, 7 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, darin-cc_chromium.org
Visibility:
Public.

Description

Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events. This lets us look up the request associated with an http transaction and send event details for the webRequest.onBeforeRequest extension event. I also hooked up the onBeforeRequest event for HTTP network and cache transactions so that they are separate from other requests. This lets us have the request header information. BUG=60101 TEST=no Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=79905

Patch Set 1 #

Patch Set 2 : net and cache intercept #

Total comments: 27

Patch Set 3 : new event #

Patch Set 4 : delegate callbcak #

Total comments: 29

Patch Set 5 : feedback #

Total comments: 6

Patch Set 6 : test fixes #

Total comments: 19

Patch Set 7 : comments #

Patch Set 8 : 500 error #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1170 lines, -624 lines) Patch
chrome/browser/extensions/extension_webrequest_api.h View 1 2 3 4 5 6 5 chunks +39 lines, -5 lines 0 comments Download
chrome/browser/extensions/extension_webrequest_api.cc View 1 2 3 4 5 6 7 chunks +84 lines, -7 lines 0 comments Download
chrome/browser/extensions/extension_webrequest_api_constants.h View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
chrome/browser/extensions/extension_webrequest_api_constants.cc View 1 2 3 4 5 1 chunk +2 lines, -0 lines 0 comments Download
chrome/browser/extensions/extension_webrequest_apitest.cc View 1 2 1 chunk +12 lines, -2 lines 0 comments Download
chrome/browser/net/chrome_network_delegate.h View 1 2 3 4 5 6 1 chunk +5 lines, -2 lines 0 comments Download
chrome/browser/net/chrome_network_delegate.cc View 1 2 3 4 5 2 chunks +12 lines, -4 lines 0 comments Download
chrome/common/extensions/api/extension_api.json View 1 2 3 4 5 6 1 chunk +15 lines, -0 lines 0 comments Download
chrome/common/extensions/docs/experimental.webRequest.html View 1 2 3 4 5 6 2 chunks +229 lines, -0 lines 0 comments Download
chrome/common/extensions/docs/samples.html View 1 2 49 chunks +442 lines, -442 lines 0 comments Download
chrome/test/data/extensions/api_test/webrequest/api/test.html View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
chrome/test/data/extensions/api_test/webrequest/events/test.html View 1 2 3 4 5 4 chunks +137 lines, -95 lines 0 comments Download
net/base/network_delegate.h View 1 2 3 4 5 6 3 chunks +26 lines, -9 lines 0 comments Download
net/base/network_delegate.cc View 1 2 3 4 5 2 chunks +12 lines, -4 lines 0 comments Download
net/http/http_cache_transaction.h View 1 2 3 4 5 2 chunks +4 lines, -0 lines 0 comments Download
net/http/http_cache_transaction.cc View 1 2 3 4 5 6 5 chunks +63 lines, -29 lines 0 comments Download
net/http/http_network_transaction.h View 1 2 3 4 5 6 3 chunks +7 lines, -0 lines 0 comments Download
net/http/http_network_transaction.cc View 1 2 3 4 5 6 5 chunks +48 lines, -14 lines 0 comments Download
net/http/http_request_info.h View 1 2 3 4 5 6 1 chunk +4 lines, -0 lines 0 comments Download
net/http/http_request_info.cc View 1 chunk +2 lines, -1 line 0 comments Download
net/url_request/url_request.cc View 1 2 3 4 5 6 3 chunks +6 lines, -2 lines 0 comments Download
net/url_request/url_request_http_job.cc View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
net/url_request/url_request_test_util.h View 1 2 3 4 5 1 chunk +5 lines, -2 lines 0 comments Download
net/url_request/url_request_test_util.cc View 1 2 3 4 5 2 chunks +10 lines, -4 lines 0 comments Download
net/url_request/url_request_unittest.cc View 1 2 3 4 5 6 2 chunks +2 lines, -2 lines 0 comments Download

Messages

Total messages: 16 (0 generated)
Matt Perry
rvargas: http_cache* willchan: everything else
9 years, 9 months ago (2011-03-17 00:01:02 UTC) #1
willchan no longer on Chromium
http://codereview.chromium.org/6698009/diff/1001/chrome/browser/extensions/extension_webrequest_api.cc File chrome/browser/extensions/extension_webrequest_api.cc (right): http://codereview.chromium.org/6698009/diff/1001/chrome/browser/extensions/extension_webrequest_api.cc#newcode252 chrome/browser/extensions/extension_webrequest_api.cc:252: http_requests_[request->identifier()] = request; You insert into this map here. ...
9 years, 9 months ago (2011-03-17 15:55:54 UTC) #2
rvargas (doing something else)
http://codereview.chromium.org/6698009/diff/1001/net/http/http_cache_transaction.cc File net/http/http_cache_transaction.cc (right): http://codereview.chromium.org/6698009/diff/1001/net/http/http_cache_transaction.cc#newcode1104 net/http/http_cache_transaction.cc:1104: nit: remove http://codereview.chromium.org/6698009/diff/1001/net/http/http_cache_transaction.cc#newcode1126 net/http/http_cache_transaction.cc:1126: next_state_ = STATE_CACHE_BEFORE_WRITE_RESPONSE; This should ...
9 years, 9 months ago (2011-03-17 19:40:20 UTC) #3
Matt Perry
http://codereview.chromium.org/6698009/diff/1001/net/http/http_network_transaction.cc File net/http/http_network_transaction.cc (right): http://codereview.chromium.org/6698009/diff/1001/net/http/http_network_transaction.cc#newcode698 net/http/http_network_transaction.cc:698: if (session_->network_delegate()->NotifyBeforeHttpRequest( On 2011/03/17 19:40:20, rvargas wrote: > For ...
9 years, 9 months ago (2011-03-17 19:52:18 UTC) #4
Matt Perry
I've changed the HTTP-specific event to onBeforeSendHeaders. onBeforeSendRequest is sent from the same place (before ...
9 years, 9 months ago (2011-03-22 21:11:43 UTC) #5
willchan no longer on Chromium
http://codereview.chromium.org/6698009/diff/10002/chrome/browser/extensions/extension_webrequest_api.cc File chrome/browser/extensions/extension_webrequest_api.cc (right): http://codereview.chromium.org/6698009/diff/10002/chrome/browser/extensions/extension_webrequest_api.cc#newcode153 chrome/browser/extensions/extension_webrequest_api.cc:153: // We use this class as UserData on any ...
9 years, 9 months ago (2011-03-22 23:05:35 UTC) #6
rvargas (doing something else)
http://codereview.chromium.org/6698009/diff/10002/net/base/network_delegate.h File net/base/network_delegate.h (right): http://codereview.chromium.org/6698009/diff/10002/net/base/network_delegate.h#newcode39 net/base/network_delegate.h:39: CompletionCallback* callback); You should document the expected behavior of ...
9 years, 9 months ago (2011-03-23 00:54:35 UTC) #7
Matt Perry
I believe I've addressed all your comments, except for the ones I had questions on. ...
9 years, 9 months ago (2011-03-24 00:11:25 UTC) #8
rvargas (doing something else)
This looks basically good for my part. Just a few extra nits. http://codereview.chromium.org/6698009/diff/10002/net/http/http_cache_transaction.cc File net/http/http_cache_transaction.cc ...
9 years, 9 months ago (2011-03-24 18:16:02 UTC) #9
Matt Perry
http://codereview.chromium.org/6698009/diff/10002/net/http/http_cache_transaction.cc File net/http/http_cache_transaction.cc (right): http://codereview.chromium.org/6698009/diff/10002/net/http/http_cache_transaction.cc#newcode1149 net/http/http_cache_transaction.cc:1149: int HttpCache::Transaction::DoCacheNotifyBeforeSendHeadersComplete(int result) { On 2011/03/24 18:16:02, rvargas wrote: ...
9 years, 9 months ago (2011-03-24 20:39:37 UTC) #10
rvargas (doing something else)
http://codereview.chromium.org/6698009/diff/17001/net/http/http_cache_transaction.cc File net/http/http_cache_transaction.cc (right): http://codereview.chromium.org/6698009/diff/17001/net/http/http_cache_transaction.cc#newcode534 net/http/http_cache_transaction.cc:534: case STATE_NOTIFY_BEFORE_SEND_HEADERS: On 2011/03/24 20:39:37, Matt Perry wrote: > ...
9 years, 9 months ago (2011-03-24 20:56:34 UTC) #11
Matt Perry
Ready for another look. http://codereview.chromium.org/6698009/diff/17001/net/base/network_delegate.h File net/base/network_delegate.h (right): http://codereview.chromium.org/6698009/diff/17001/net/base/network_delegate.h#newcode37 net/base/network_delegate.h:37: bool NotifyBeforeSendHeaders(uint64 request_id, On 2011/03/24 ...
9 years, 9 months ago (2011-03-24 22:10:53 UTC) #12
rvargas (doing something else)
LGTM
9 years, 9 months ago (2011-03-25 20:48:59 UTC) #13
willchan no longer on Chromium
http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_transaction.cc File net/http/http_network_transaction.cc (right): http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_transaction.cc#newcode708 net/http/http_network_transaction.cc:708: int HttpNetworkTransaction::DoBuildRequestComplete(int result) { On 2011/03/24 00:11:25, Matt Perry ...
9 years, 9 months ago (2011-03-26 01:46:49 UTC) #14
Matt Perry
http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_transaction.cc File net/http/http_network_transaction.cc (right): http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_transaction.cc#newcode708 net/http/http_network_transaction.cc:708: int HttpNetworkTransaction::DoBuildRequestComplete(int result) { On 2011/03/26 01:46:49, willchan wrote: ...
9 years, 9 months ago (2011-03-28 22:51:01 UTC) #15
willchan no longer on Chromium
9 years, 9 months ago (2011-03-29 20:46:26 UTC) #16
LGTM

http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_trans...
File net/http/http_network_transaction.cc (right):

http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_trans...
net/http/http_network_transaction.cc:708: int
HttpNetworkTransaction::DoBuildRequestComplete(int result) {
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > On 2011/03/24 00:11:25, Matt Perry wrote:
> > > On 2011/03/22 23:05:35, willchan wrote:
> > > > Sorry for nitpicking like this, but to make it more like net code, the
> > > > parameters need to make sense too.
> > > > 
> > > > Please move this code into DoBuildRequest(). DoBuildRequestComplete()
> should
> > > be
> > > > simple. Something like:
> > > > 
> > > > DoBuildRequestComplete(int result) {
> > > >   if (result == OK)
> > > >     next_state_ = STATE_SEND_REQUEST
> > > >   return result;
> > > > }
> > > > 
> > > > DoSendRequest(void) shouldn't need a parameter, and thus shouldn't need
> the
> > if
> > > > (result == OK)
> > > 
> > > Done. Though now I notice that delegate_callback_ may never get to the
> > Release()
> > > in DoSendRequest() - I think. Should I  be concerned about that? I'm
> following
> > > the pattern in HttpCache::Transaction, and it doesn't seem to handle that
> > case,
> > > so maybe I'm misinterpreting it.
> > 
> > I think maybe you want to only create the delegate_callback_ In
> BuildRequest().
> > AddRef() it at that point. Then in the destructor, if |delegate_callback_|
is
> > non-NULL, Cancel() it. And in BuildRequestComplete(), NULL it out too, in
> > addition to the Release() call.
> 
> Any reason to prefer doing it that way as opposed to always creating the
> callback?

I don't know that this is possible today, but let's say we get to BuildRequest()
and get ERR_IO_PENDING. Now, let's say we restart the transaction (I think we
only restart the transaction in STATE_NONE right now, but I'm not sure how
strict of a convention that is).

At that point, we have pending callback that should be Cancel()'d. Now that
we've restarted, we need to use a new callback object, otherwise, we'll be
trying to use one that has already have Cancel() called on it.

The fact that we can restart transactions and Cancel() can't be reset (nor we
would want to), makes me feel like it's best not to keep the callback alive for
the whole transaction, just create and release it when we're done.

http://codereview.chromium.org/6698009/diff/10002/net/http/http_network_trans...
net/http/http_network_transaction.cc:1157: void
HttpNetworkTransaction::ResetStateForRestart() {
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > On 2011/03/24 00:11:25, Matt Perry wrote:
> > > On 2011/03/22 23:05:35, willchan wrote:
> > > > This is the core place where all state gets reset when we "restart" a
> > > > transaction (primarily done for authentication purposes, like HTTP auth
> and
> > > SSL
> > > > client auth). At this point, you should probably Cancel() your callback,
> and
> > > > mark the transaction as restarted.
> > > 
> > > Mark it how?
> > > 
> > > > You should pass that into the
> > > > NetworkDelegate. I say pass that into the NetworkDelegate rather than
not
> > call
> > > > the NetworkDelegate, because eventually when we make NetLog hide behind
> > > > NetworkDelegate, then we will still need to make sure it's getting
called.
> > > 
> > > You lost me here... What's being passed into the NetworkDelegate? And for
> what
> > > purpose?
> > 
> > Note that we will "restart" a transaction for authentication purposes. I
> believe
> > you previously told me that we only want onBeforeSendHeaders() to be called
> for
> > the first request, not for the subsequent restarted transactions where we
try
> to
> > send the correct authentication credentials. We should always call
> > NetworkDelegate though, for future NetLog purposes, but within the
> > ChromeNetworkDelegate or ExtensionWebRequestEventRouter, we may want to
filter
> > out these extra authentication requests. Therefore, I think you need a bool
> > member variable to track whether this is the original transaction, or a
> > restarted authentication transaction.
> 
> Oh I see now. FWIW, OnBeforeSendHeaders will be called for restarted requests
as
> well. In the ExtensionWebRequestEventRouter, the request will no longer be in
> the map (since it was already processed), so it'll be ignored. This is already
> the behavior you suggest, I believe.

OIC, ok!

http://codereview.chromium.org/6698009/diff/21002/chrome/browser/extensions/e...
File chrome/browser/extensions/extension_webrequest_api.cc (right):

http://codereview.chromium.org/6698009/diff/21002/chrome/browser/extensions/e...
chrome/browser/extensions/extension_webrequest_api.cc:33: static const char
*kWebRequestEvents[] = {
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > Where's OnRequestDeleted?
> 
> These are only the extension-visible events. Extensions don't get notified
when
> a request is deleted.

OK, I defer to you here. Just noting that this means that an extension shouldn't
keep a map of requests, because the lack of a request deletion notification
means that an extension would not know when to remove a request from the map,
and thus an extension would leak. I think we may have touched upon this before
and you had a good answer, but I forget. It doesn't seem obvious to me how this
would be addressed.

> 
> > Nit: FYI, these should probably be static const char* const
kWebRequestEvents.
> > That extra const will let the compiler optimize away an extra load. Also,
> things
> > like strlen(kWebRequestEvents[0]) become compile-time constants rather than
> > being dynamically computed at run-time.
> 
> Done. Thanks for the tip.

http://codereview.chromium.org/6698009/diff/21002/chrome/browser/extensions/e...
chrome/browser/extensions/extension_webrequest_api.cc:309:
http_requests_[request->identifier()] = request;
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > As discussed previously, this may include more than just URLRequestHttpJob.
> > AppCacheURLRequestJob notably will be caught. You may want to edit that one
> too,
> > although that's an edge case.
> 
> OK. I think it doesn't affect anything if these are caught, since they'll just
> sit in the map until they are deleted. Is there a way to tell whether it's an
> AppCache job at this point?

No there isn't. I suspect that eventually you'll want to edit
AppCacheURLRequestJob to call NetworkDelegate at the appropriate points.

http://codereview.chromium.org/6698009/diff/21002/chrome/browser/extensions/e...
chrome/browser/extensions/extension_webrequest_api.cc:367:
http_requests_.erase(request->identifier());
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > Doesn't erase() cause crashes if the key doesn't exist?
> 
> No, that's not an error.

Learn something new everyday.

> 
> > What if it completed
> > successfully and got removed in OnBeforeSendHeaders() first? Is there a test
> for
> > this somewhere?
> 
> That's actually the common case. Most of the time, OnBeforeSendHeaders is
called
> before the request is deleted. Sometimes (like with AppCache jobs, I believe),
> this path is taken. I don't have any explicit tests for this.

http://codereview.chromium.org/6698009/diff/21002/net/http/http_network_trans...
File net/http/http_network_transaction.cc (right):

http://codereview.chromium.org/6698009/diff/21002/net/http/http_network_trans...
net/http/http_network_transaction.cc:683: request_body_.reset(NULL);
On 2011/03/28 22:51:01, Matt Perry wrote:
> On 2011/03/26 01:46:49, willchan wrote:
> > Shouldn't request_body_ already be NULL?
> 
> What if the transaction is restarted?

Good point. I guess I'd expect to reset request_body_ in those cases. It feels
cleaner to ditch |request_body_| during a ResetStateForRestart(), but I guess
what you have is safer since it's more relaxed. I tend to make things stricter
and add DCHECKs to catch when the assumptions change, rather than writing more
tolerant code. Up to you.

Powered by Google App Engine
This is Rietveld 408576698