diff options
Diffstat (limited to 'chrome/browser/net')
| -rw-r--r-- | chrome/browser/net/url_request_tracking.cc | 47 | ||||
| -rw-r--r-- | chrome/browser/net/url_request_tracking.h | 35 |
2 files changed, 82 insertions, 0 deletions
diff --git a/chrome/browser/net/url_request_tracking.cc b/chrome/browser/net/url_request_tracking.cc new file mode 100644 index 0000000..f877782 --- /dev/null +++ b/chrome/browser/net/url_request_tracking.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/net/url_request_tracking.h" + +#include "base/basictypes.h" +#include "net/url_request/url_request.h" + +namespace { + +// The value is not important, this address is used as the unique key for the +// PID. +const void* kOriginProcessUniqueIDKey = 0; + +class UniqueIDData : public URLRequest::UserData { + public: + UniqueIDData(int id) : id_(id) {} + virtual ~UniqueIDData() {} + + int id() const { return id_; } + void set_id(int id) { id_ = id; } + + private: + int id_; + + DISALLOW_COPY_AND_ASSIGN(UniqueIDData); +}; + +} // namespace + +namespace chrome_browser_net { + +void SetOriginProcessUniqueIDForRequest(int id, URLRequest* request) { + // The request will take ownership. + request->SetUserData(&kOriginProcessUniqueIDKey, new UniqueIDData(id)); +} + +int GetOriginProcessUniqueIDForRequest(const URLRequest* request) { + const UniqueIDData* data = static_cast<const UniqueIDData*>( + request->GetUserData(&kOriginProcessUniqueIDKey)); + if (!data) + return -1; + return data->id(); +} + +} // namespace chrome_browser_net diff --git a/chrome/browser/net/url_request_tracking.h b/chrome/browser/net/url_request_tracking.h new file mode 100644 index 0000000..c0a3e9e --- /dev/null +++ b/chrome/browser/net/url_request_tracking.h @@ -0,0 +1,35 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_NET_URL_REQUEST_TRACKING_H_ +#define CHROME_BROWSER_NET_URL_REQUEST_TRACKING_H_ + +class URLRequest; + +namespace chrome_browser_net { + +// Sets the given ID on the given request for later retrieval. This information +// duplicates a field in the ResourceDispatcherHost's user data, but is also +// set for non-ResourceDispatcher-related requests. Having this one global +// place allows us to do more general things, such as assigning traffic for the +// network view in the task manager. +// +// If you make a request on behalf of a child process, please call this +// function. The default value will be -1 which will be interprepreted as +// originating from the browser itself. +// +// The ID is the child process' unique ID (not a PID) of the process originating +// the request. This is normally the renderer corresponding to the load. If a +// plugin process does a request through a renderer process this will be the +// plugin (the originator of the request). +void SetOriginProcessUniqueIDForRequest(int id, URLRequest* request); + +// Returns the child process' unique ID that has been previously set by +// SetOriginProcessUniqueIDForRequest. If no ID has been set, the return +// value is -1. We use this to identify requests made by the browser process. +int GetOriginProcessUniqueIDForRequest(const URLRequest* request); + +} // namespace chrome_browser_net + +#endif // CHROME_BROWSER_NET_URL_REQUEST_TRACKING_H_ |
