Files
brave-core/browser/net/resource_context_data.h
T
Claudio DeSouza 98d8789d45 [cr133] Remove unnecessary unused process id plumbing
`ChildProcessId` is now a strong alias, however when fixing this it
became apparent that there was actually no use for the value being
plumed around. This change removes the plumbing of the value.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/49b8ddcb14867f200cfa36063fcb79be944f3bcf

commit 49b8ddcb14867f200cfa36063fcb79be944f3bcf
Author: Emily Andrews <emiled@microsoft.com>
Date:   Tue Dec 10 20:42:14 2024 +0000

    Add APIs to RenderProcessHost to use ChildProcessId

    Using int32_t for the child process id can be fraught with peril.
    Developers can mistake this for the PID. Bugs can be created by passing
    in an invalid value by mistake. Using a strongly typed ChildProcessId
    instead will allow the compiler to catch errors.

    This change modifies the internal id_ and render_process_id_ variables
    in the RenderProcessHostImpl code and adds APIs to use ChildProcessId
    to index in. This will allow incremental changes to remove int
    references.

    Bug: 379869738
2025-01-27 09:41:16 -05:00

102 lines
3.5 KiB
C++

/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_NET_RESOURCE_CONTEXT_DATA_H_
#define BRAVE_BROWSER_NET_RESOURCE_CONTEXT_DATA_H_
#include <cstdint>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include "base/containers/unique_ptr_adapters.h"
#include "base/memory/ref_counted.h"
#include "base/supports_user_data.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/websocket.mojom.h"
class BraveProxyingURLLoaderFactory;
class BraveProxyingWebSocket;
class BraveRequestHandler;
namespace content {
class BrowserContext;
}
// Used for both URLLoaders and WebSocket proxies.
class RequestIDGenerator
: public base::RefCountedThreadSafe<RequestIDGenerator> {
public:
RequestIDGenerator() = default;
RequestIDGenerator(const RequestIDGenerator&) = delete;
RequestIDGenerator& operator=(const RequestIDGenerator&) = delete;
int64_t Generate() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return ++id_;
}
private:
friend class base::RefCountedThreadSafe<RequestIDGenerator>;
~RequestIDGenerator() {}
// Although this initialization can be done in a thread other than the IO
// thread, we expect at least one memory barrier before actually calling
// Generate in the IO thread, so we don't protect the variable with a lock.
int64_t id_ = 0;
};
// Owns proxying factories for URLLoaders and websocket proxies. There is
// one |ResourceContextData| per profile.
class ResourceContextData : public base::SupportsUserData::Data {
public:
ResourceContextData(const ResourceContextData&) = delete;
ResourceContextData& operator=(const ResourceContextData&) = delete;
~ResourceContextData() override;
static void StartProxying(
content::BrowserContext* browser_context,
content::FrameTreeNodeId frame_tree_node_id,
network::URLLoaderFactoryBuilder& factory_builder,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner);
static BraveProxyingWebSocket* StartProxyingWebSocket(
content::ContentBrowserClient::WebSocketFactory factory,
const GURL& url,
const net::SiteForCookies& site_for_cookies,
const std::optional<std::string>& user_agent,
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
handshake_client,
content::BrowserContext* browser_context,
int frame_id,
content::FrameTreeNodeId frame_tree_node_id,
const url::Origin& origin);
void RemoveProxy(BraveProxyingURLLoaderFactory* proxy);
void RemoveProxyWebSocket(BraveProxyingWebSocket* proxy);
private:
ResourceContextData();
std::unique_ptr<BraveRequestHandler> request_handler_;
scoped_refptr<RequestIDGenerator> request_id_generator_;
std::set<std::unique_ptr<BraveProxyingURLLoaderFactory>,
base::UniquePtrComparator>
proxies_;
std::set<std::unique_ptr<BraveProxyingWebSocket>,
base::UniquePtrComparator>
websocket_proxies_;
base::WeakPtrFactory<ResourceContextData> weak_factory_;
};
#endif // BRAVE_BROWSER_NET_RESOURCE_CONTEXT_DATA_H_