blob: 60ad7d2230e6036d84f350e710ef38e48f168873 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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:
explicit 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
|