OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/budget_service/budget_service_impl.h" |
| 6 |
| 7 #include "chrome/browser/budget_service/budget_manager.h" |
| 8 #include "chrome/browser/budget_service/budget_manager_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/render_process_host.h" |
| 11 |
| 12 // static |
| 13 void BudgetServiceImpl::Create(int render_process_id, |
| 14 blink::mojom::BudgetServiceRequest request) { |
| 15 new BudgetServiceImpl(render_process_id, std::move(request)); |
| 16 } |
| 17 |
| 18 BudgetServiceImpl::BudgetServiceImpl(int render_process_id, |
| 19 blink::mojom::BudgetServiceRequest request) |
| 20 : render_process_id_(render_process_id), |
| 21 binding_(this, std::move(request)) {} |
| 22 |
| 23 BudgetServiceImpl::~BudgetServiceImpl() = default; |
| 24 |
| 25 void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type, |
| 26 const GetCostCallback& callback) { |
| 27 // The RenderProcessHost should still be alive as long as any connections are |
| 28 // alive, and if the BudgetService mojo connection is down, the |
| 29 // BudgetServiceImpl should have been destroyed. |
| 30 content::RenderProcessHost* host = |
| 31 content::RenderProcessHost::FromID(render_process_id_); |
| 32 DCHECK(host); |
| 33 |
| 34 // Query the BudgetManager for the cost and return it. |
| 35 content::BrowserContext* context = host->GetBrowserContext(); |
| 36 double cost = BudgetManagerFactory::GetForProfile(context)->GetCost(type); |
| 37 callback.Run(cost); |
| 38 } |
| 39 |
| 40 void BudgetServiceImpl::GetBudget(const url::Origin& origin, |
| 41 const GetBudgetCallback& callback) { |
| 42 // TODO(harkness) Call the BudgetManager once it supports detailed GetBudget |
| 43 // calls. |
| 44 callback.Run(0); |
| 45 } |
OLD | NEW |