chromium/services/network/public/cpp/cross_thread_pending_shared_url_loader_factory.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/public/cpp/cross_thread_pending_shared_url_loader_factory.h"

#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/task/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"

namespace network {

// State and methods that need to live on the same sequence |task_runner_|
// as the wrapped SharedURLLoaderFactory |base_factory_|.
//
// Used by both CrossThreadPendingSharedURLLoaderFactory and
// CrossThreadSharedURLLoaderFactory, and shared across chains of
// CreateFactory() and Clone() calls. Ref count accommodates both this sharing,
// as well as lifetime management for cross-thread calls into the object.
class CrossThreadPendingSharedURLLoaderFactory::State
    : public base::RefCountedThreadSafe<State, StateDeleterTraits> {};

struct CrossThreadPendingSharedURLLoaderFactory::StateDeleterTraits {};

// The implementation of SharedURLLoaderFactory provided by
// CrossThreadPendingSharedURLLoaderFactory::CreateFactory(). Uses the exact
// same State object, and posts URLLoaderFactory API calls to it on the
// appropriate thread.
class CrossThreadSharedURLLoaderFactory : public SharedURLLoaderFactory {};

CrossThreadSharedURLLoaderFactory::CrossThreadSharedURLLoaderFactory(
    scoped_refptr<CrossThreadPendingSharedURLLoaderFactory::State> state)
    :{}

CrossThreadSharedURLLoaderFactory::~CrossThreadSharedURLLoaderFactory() {}

void CrossThreadSharedURLLoaderFactory::CreateLoaderAndStart(
    mojo::PendingReceiver<mojom::URLLoader> loader,
    int32_t request_id,
    uint32_t options,
    const ResourceRequest& request,
    mojo::PendingRemote<mojom::URLLoaderClient> client,
    const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {}

void CrossThreadSharedURLLoaderFactory::Clone(
    mojo::PendingReceiver<mojom::URLLoaderFactory> receiver) {}

std::unique_ptr<PendingSharedURLLoaderFactory>
CrossThreadSharedURLLoaderFactory::Clone() {}

CrossThreadPendingSharedURLLoaderFactory::
    CrossThreadPendingSharedURLLoaderFactory(
        scoped_refptr<SharedURLLoaderFactory> url_loader_factory)
    :{}

CrossThreadPendingSharedURLLoaderFactory::
    ~CrossThreadPendingSharedURLLoaderFactory() = default;

scoped_refptr<SharedURLLoaderFactory>
CrossThreadPendingSharedURLLoaderFactory::CreateFactory() {}

CrossThreadPendingSharedURLLoaderFactory::
    CrossThreadPendingSharedURLLoaderFactory(scoped_refptr<State> state)
    :{}

CrossThreadPendingSharedURLLoaderFactory::State::State(
    scoped_refptr<SharedURLLoaderFactory> base_factory)
    :{}

CrossThreadPendingSharedURLLoaderFactory::State::~State() {}

void CrossThreadPendingSharedURLLoaderFactory::State::DeleteOnCorrectThread()
    const {}

void CrossThreadPendingSharedURLLoaderFactory::State::CreateLoaderAndStart(
    mojo::PendingReceiver<mojom::URLLoader> loader,
    int32_t request_id,
    uint32_t options,
    const ResourceRequest& request,
    mojo::PendingRemote<mojom::URLLoaderClient> client,
    const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {}

void CrossThreadPendingSharedURLLoaderFactory::State::Clone(
    mojo::PendingReceiver<mojom::URLLoaderFactory> receiver) {}

}  // namespace network