blob: 98125825f3835010b8717c196f276bf5a8aaedae [file] [log] [blame]
// Copyright 2019 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 FUCHSIA_ENGINE_RENDERER_URL_REQUEST_RULES_RECEIVER_H_
#define FUCHSIA_ENGINE_RENDERER_URL_REQUEST_RULES_RECEIVER_H_
#include "base/sequence_checker.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "content/public/renderer/render_frame_observer.h"
#include "fuchsia/engine/common/web_engine_url_loader_throttle.h"
#include "fuchsia/engine/url_request_rewrite.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace content {
class RenderFrame;
} // namespace content
// Provides rewriting rules for network requests. Owned by
// WebEngineRenderFrameObserver, this object will be destroyed on RenderFrame
// destruction. This is guaranteed to outlive any WebEngineURLLoaderThrottle
// that uses it as the RenderFrame destruction will have triggered the
// destruction of all pending WebEngineURLLoaderThrottles.
// This class should only be used on the IO thread, with the exception of the
// GetCachedRules() implementation, which can be called from any sequence.
class UrlRequestRulesReceiver
: public mojom::UrlRequestRulesReceiver,
public WebEngineURLLoaderThrottle::CachedRulesProvider {
public:
UrlRequestRulesReceiver(content::RenderFrame* render_frame);
~UrlRequestRulesReceiver() override;
private:
void OnUrlRequestRulesReceiverAssociatedReceiver(
mojo::PendingAssociatedReceiver<mojom::UrlRequestRulesReceiver> receiver);
// mojom::UrlRequestRulesReceiver implementation.
void OnRulesUpdated(std::vector<mojom::UrlRequestRulePtr> rules) override;
// WebEngineURLLoaderThrottle::CachedRulesProvider implementation.
scoped_refptr<WebEngineURLLoaderThrottle::UrlRequestRewriteRules>
GetCachedRules() override;
base::Lock lock_;
// This is accessed by WebEngineURLLoaderThrottles, which can be off-sequence
// in the case of synchronous network requests.
scoped_refptr<WebEngineURLLoaderThrottle::UrlRequestRewriteRules>
cached_rules_ GUARDED_BY(lock_);
mojo::AssociatedReceiver<mojom::UrlRequestRulesReceiver>
url_request_rules_receiver_{this};
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(UrlRequestRulesReceiver);
};
#endif // FUCHSIA_ENGINE_RENDERER_URL_REQUEST_RULES_RECEIVER_H_