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 namespace { | |
13 | |
14 BudgetManager::CostType budgetOperationTypeToBudgetManagerCostType( | |
15 blink::mojom::BudgetOperationType type) { | |
16 // 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.
| |
17 return BudgetManager::CostType::SILENT_PUSH; | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 // static | |
23 void BudgetServiceImpl::Create(int render_process_id, | |
24 blink::mojom::BudgetServiceRequest request) { | |
25 new BudgetServiceImpl(render_process_id, std::move(request)); | |
26 } | |
27 | |
28 BudgetServiceImpl::BudgetServiceImpl(int render_process_id, | |
29 blink::mojom::BudgetServiceRequest request) | |
30 : render_process_id_(render_process_id), | |
31 binding_(this, std::move(request)) {} | |
32 | |
33 BudgetServiceImpl::~BudgetServiceImpl() = default; | |
34 | |
35 // 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.
| |
36 void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type, | |
37 const GetCostCallback& callback) { | |
38 // Query the BudgetManager for the cost and return it. | |
39 content::BrowserContext* context = | |
40 content::RenderProcessHost::FromID(render_process_id_) | |
41 ->GetBrowserContext(); | |
Peter Beverloo
2016/08/23 10:13:30
Mmm. DCHECK(context)?
harkness
2016/08/23 10:48:32
Done.
| |
42 BudgetManager* manager = BudgetManagerFactory::GetForProfile(context); | |
43 double cost = | |
44 manager->GetCost(budgetOperationTypeToBudgetManagerCostType(type)); | |
45 callback.Run(cost); | |
46 } | |
47 | |
48 // blink::mojom::BudgetService implementation. | |
49 void BudgetServiceImpl::GetBudget(const url::Origin& origin, | |
50 const GetBudgetCallback& callback) { | |
51 // TODO(harkness) Call the BudgetManager once it supports detailed GetBudget | |
52 // calls. | |
53 callback.Run(0); | |
54 } | |
OLD | NEW |