Chromium Code Reviews| Index: chrome/browser/budget_service/budget_service_impl.cc |
| diff --git a/chrome/browser/budget_service/budget_service_impl.cc b/chrome/browser/budget_service/budget_service_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..90c4b468ff7717777e199f03b0c20f97b07dea48 |
| --- /dev/null |
| +++ b/chrome/browser/budget_service/budget_service_impl.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2016 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. |
| + |
| +#include "chrome/browser/budget_service/budget_service_impl.h" |
| + |
| +#include "chrome/browser/budget_service/budget_manager.h" |
| +#include "chrome/browser/budget_service/budget_manager_factory.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/render_process_host.h" |
| + |
| +namespace { |
| + |
| +BudgetManager::CostType budgetOperationTypeToBudgetManagerCostType( |
| + blink::mojom::BudgetOperationType type) { |
| + // Silent push is the only operation type supported currently. |
|
Peter Beverloo
2016/08/23 10:13:30
Now that we have the blink::mojom::BudgetOperation
harkness
2016/08/23 10:48:33
Good idea. Done.
|
| + return BudgetManager::CostType::SILENT_PUSH; |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +void BudgetServiceImpl::Create(int render_process_id, |
| + blink::mojom::BudgetServiceRequest request) { |
| + new BudgetServiceImpl(render_process_id, std::move(request)); |
| +} |
| + |
| +BudgetServiceImpl::BudgetServiceImpl(int render_process_id, |
| + blink::mojom::BudgetServiceRequest request) |
| + : render_process_id_(render_process_id), |
| + binding_(this, std::move(request)) {} |
| + |
| +BudgetServiceImpl::~BudgetServiceImpl() = default; |
| + |
| +// blink::mojom::BudgetService implementation. |
|
Peter Beverloo
2016/08/23 10:13:30
nit: remove? Line 48 too. They don't really add va
harkness
2016/08/23 10:48:33
Done.
|
| +void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type, |
| + const GetCostCallback& callback) { |
| + // Query the BudgetManager for the cost and return it. |
| + content::BrowserContext* context = |
| + content::RenderProcessHost::FromID(render_process_id_) |
| + ->GetBrowserContext(); |
|
Peter Beverloo
2016/08/23 10:13:30
Mmm. DCHECK(context)?
harkness
2016/08/23 10:48:32
Done.
|
| + BudgetManager* manager = BudgetManagerFactory::GetForProfile(context); |
| + double cost = |
| + manager->GetCost(budgetOperationTypeToBudgetManagerCostType(type)); |
| + callback.Run(cost); |
| +} |
| + |
| +// blink::mojom::BudgetService implementation. |
| +void BudgetServiceImpl::GetBudget(const url::Origin& origin, |
| + const GetBudgetCallback& callback) { |
| + // TODO(harkness) Call the BudgetManager once it supports detailed GetBudget |
| + // calls. |
| + callback.Run(0); |
| +} |