Commit 7f1d1239 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Remove origins from the BudgetService interface messages.

Bug: 779444
Change-Id: I7bb353e31a10cd43a910de1cd4282e23309caf5e
Reviewed-on: https://chromium-review.googlesource.com/788640Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523041}
parent df12a0f1
......@@ -14,8 +14,9 @@
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
BudgetServiceImpl::BudgetServiceImpl(int render_process_id)
: render_process_id_(render_process_id) {}
BudgetServiceImpl::BudgetServiceImpl(int render_process_id,
const url::Origin& origin)
: render_process_id_(render_process_id), origin_(origin) {}
BudgetServiceImpl::~BudgetServiceImpl() = default;
......@@ -23,8 +24,9 @@ BudgetServiceImpl::~BudgetServiceImpl() = default;
void BudgetServiceImpl::Create(blink::mojom::BudgetServiceRequest request,
content::RenderProcessHost* host,
const url::Origin& origin) {
mojo::MakeStrongBinding(base::MakeUnique<BudgetServiceImpl>(host->GetID()),
std::move(request));
mojo::MakeStrongBinding(
base::MakeUnique<BudgetServiceImpl>(host->GetID(), origin),
std::move(request));
}
void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type,
......@@ -42,8 +44,7 @@ void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type,
std::move(callback).Run(cost);
}
void BudgetServiceImpl::GetBudget(const url::Origin& origin,
GetBudgetCallback callback) {
void BudgetServiceImpl::GetBudget(GetBudgetCallback callback) {
// The RenderProcessHost should still be alive as long as any connections are
// alive, and if the BudgetService mojo connection is down, the
// BudgetServiceImpl should have been destroyed.
......@@ -62,8 +63,8 @@ void BudgetServiceImpl::GetBudget(const url::Origin& origin,
// something the impact of which has to be reconsidered when the feature is
// ready to ship for real. See https://crbug.com/710809 for context.
if (permission_manager->GetPermissionStatus(
content::PermissionType::NOTIFICATIONS, origin.GetURL(),
origin.GetURL()) != blink::mojom::PermissionStatus::GRANTED) {
content::PermissionType::NOTIFICATIONS, origin_.GetURL(),
origin_.GetURL()) != blink::mojom::PermissionStatus::GRANTED) {
blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New());
empty_state->budget_at = 0;
empty_state->time =
......@@ -78,12 +79,11 @@ void BudgetServiceImpl::GetBudget(const url::Origin& origin,
}
// Query the BudgetManager for the budget.
BudgetManagerFactory::GetForProfile(profile)->GetBudget(origin,
BudgetManagerFactory::GetForProfile(profile)->GetBudget(origin_,
std::move(callback));
}
void BudgetServiceImpl::Reserve(const url::Origin& origin,
blink::mojom::BudgetOperationType operation,
void BudgetServiceImpl::Reserve(blink::mojom::BudgetOperationType operation,
ReserveCallback callback) {
// The RenderProcessHost should still be alive as long as any connections are
// alive, and if the BudgetService mojo connection is down, the
......@@ -94,6 +94,6 @@ void BudgetServiceImpl::Reserve(const url::Origin& origin,
// Request a reservation from the BudgetManager.
content::BrowserContext* context = host->GetBrowserContext();
BudgetManagerFactory::GetForProfile(context)->Reserve(origin, operation,
BudgetManagerFactory::GetForProfile(context)->Reserve(origin_, operation,
std::move(callback));
}
......@@ -7,21 +7,18 @@
#include "base/macros.h"
#include "third_party/WebKit/public/platform/modules/budget_service/budget_service.mojom.h"
#include "url/origin.h"
namespace content {
class RenderProcessHost;
}
namespace url {
class Origin;
}
// Implementation of the BudgetService Mojo service provided by the browser
// layer. It is responsible for dispatching budget requests to the
// BudgetManager.
class BudgetServiceImpl : public blink::mojom::BudgetService {
public:
explicit BudgetServiceImpl(int render_process_id);
BudgetServiceImpl(int render_process_id, const url::Origin& origin);
~BudgetServiceImpl() override;
static void Create(blink::mojom::BudgetServiceRequest request,
......@@ -31,15 +28,15 @@ class BudgetServiceImpl : public blink::mojom::BudgetService {
// blink::mojom::BudgetService implementation.
void GetCost(blink::mojom::BudgetOperationType operation,
GetCostCallback callback) override;
void GetBudget(const url::Origin& origin,
GetBudgetCallback callback) override;
void Reserve(const url::Origin& origin,
blink::mojom::BudgetOperationType operation,
void GetBudget(GetBudgetCallback callback) override;
void Reserve(blink::mojom::BudgetOperationType operation,
ReserveCallback callback) override;
private:
// Render process ID is used to get the browser context.
int render_process_id_;
const int render_process_id_;
const url::Origin origin_;
DISALLOW_COPY_AND_ASSIGN(BudgetServiceImpl);
};
......
......@@ -95,10 +95,7 @@ ScriptPromise BudgetService::getBudget(ScriptState* script_state) {
ScriptPromise promise = resolver->Promise();
// Get the budget from the browser BudgetService.
scoped_refptr<const SecurityOrigin> origin(
ExecutionContext::From(script_state)->GetSecurityOrigin());
service_->GetBudget(origin,
WTF::Bind(&BudgetService::GotBudget, WrapPersistent(this),
service_->GetBudget(WTF::Bind(&BudgetService::GotBudget, WrapPersistent(this),
WrapPersistent(resolver)));
return promise;
}
......@@ -142,11 +139,9 @@ ScriptPromise BudgetService::reserve(ScriptState* script_state,
ScriptPromise promise = resolver->Promise();
// Call to the BudgetService to place the reservation.
scoped_refptr<const SecurityOrigin> origin(
ExecutionContext::From(script_state)->GetSecurityOrigin());
service_->Reserve(origin, type,
WTF::Bind(&BudgetService::GotReservation,
WrapPersistent(this), WrapPersistent(resolver)));
service_->Reserve(
type, WTF::Bind(&BudgetService::GotReservation, WrapPersistent(this),
WrapPersistent(resolver)));
return promise;
}
......
......@@ -4,8 +4,6 @@
module blink.mojom;
import "url/mojo/origin.mojom";
enum BudgetOperationType {
SILENT_PUSH,
INVALID_OPERATION
......@@ -34,7 +32,8 @@ struct BudgetState {
// for the budget available for an origin.
interface BudgetService {
GetCost(BudgetOperationType operation) => (double cost);
GetBudget(url.mojom.Origin origin) => (BudgetServiceErrorType error_type, array<BudgetState> budget);
Reserve(url.mojom.Origin origin, BudgetOperationType operation) => (BudgetServiceErrorType error_type, bool success);
GetBudget() => (BudgetServiceErrorType error_type, array<BudgetState> budget);
Reserve(BudgetOperationType operation)
=> (BudgetServiceErrorType error_type, bool success);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment