1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/net/url_request_tracking.h" 6 7#include "base/basictypes.h" 8#include "net/url_request/url_request.h" 9 10namespace { 11 12// The value is not important, this address is used as the unique key for the 13// PID. 14const void* kOriginPidKey = 0; 15 16class OriginPidData : public net::URLRequest::UserData { 17 public: 18 explicit OriginPidData(int pid) : pid_(pid) {} 19 virtual ~OriginPidData() {} 20 21 int pid() const { return pid_; } 22 void set_pid(int pid) { pid_ = pid; } 23 24 private: 25 int pid_; 26 27 DISALLOW_COPY_AND_ASSIGN(OriginPidData); 28}; 29 30} // namespace 31 32namespace chrome_browser_net { 33 34void SetOriginPIDForRequest(int pid, net::URLRequest* request) { 35 // The request will take ownership. 36 request->SetUserData(&kOriginPidKey, new OriginPidData(pid)); 37} 38 39int GetOriginPIDForRequest(const net::URLRequest* request) { 40 const OriginPidData* data = static_cast<const OriginPidData*>( 41 request->GetUserData(&kOriginPidKey)); 42 if (!data) 43 return 0; 44 return data->pid(); 45} 46 47} // namespace chrome_browser_net 48