| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/budget_service/budget_service_impl.h" | 5 #include "chrome/browser/budget_service/budget_service_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/budget_service/budget_manager.h" | 8 #include "chrome/browser/budget_service/budget_manager.h" |
| 9 #include "chrome/browser/budget_service/budget_manager_factory.h" | 9 #include "chrome/browser/budget_service/budget_manager_factory.h" |
| 10 #include "chrome/browser/permissions/permission_manager.h" | 10 #include "chrome/browser/permissions/permission_manager.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // By request of the Privacy Team, we only communicate the budget buckets with | 62 // By request of the Privacy Team, we only communicate the budget buckets with |
| 63 // the developer when the notification permission has been granted. This is | 63 // the developer when the notification permission has been granted. This is |
| 64 // something the impact of which has to be reconsidered when the feature is | 64 // something the impact of which has to be reconsidered when the feature is |
| 65 // ready to ship for real. See https://crbug.com/710809 for context. | 65 // ready to ship for real. See https://crbug.com/710809 for context. |
| 66 if (permission_manager->GetPermissionStatus( | 66 if (permission_manager->GetPermissionStatus( |
| 67 content::PermissionType::NOTIFICATIONS, origin.GetURL(), GURL()) != | 67 content::PermissionType::NOTIFICATIONS, origin.GetURL(), GURL()) != |
| 68 blink::mojom::PermissionStatus::GRANTED) { | 68 blink::mojom::PermissionStatus::GRANTED) { |
| 69 blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New()); | 69 blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New()); |
| 70 empty_state->budget_at = 0; | 70 empty_state->budget_at = 0; |
| 71 empty_state->time = base::Time::Now().ToDoubleT(); | 71 empty_state->time = |
| 72 base::Time::Now().ToDoubleT() * base::Time::kMillisecondsPerSecond; |
| 72 | 73 |
| 73 std::vector<blink::mojom::BudgetStatePtr> predictions; | 74 std::vector<blink::mojom::BudgetStatePtr> predictions; |
| 74 predictions.push_back(std::move(empty_state)); | 75 predictions.push_back(std::move(empty_state)); |
| 75 | 76 |
| 76 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, | 77 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, |
| 77 std::move(predictions)); | 78 std::move(predictions)); |
| 78 return; | 79 return; |
| 79 } | 80 } |
| 80 | 81 |
| 81 // Query the BudgetManager for the budget. | 82 // Query the BudgetManager for the budget. |
| 82 BudgetManagerFactory::GetForProfile(profile)->GetBudget(origin, callback); | 83 BudgetManagerFactory::GetForProfile(profile)->GetBudget(origin, callback); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void BudgetServiceImpl::Reserve(const url::Origin& origin, | 86 void BudgetServiceImpl::Reserve(const url::Origin& origin, |
| 86 blink::mojom::BudgetOperationType operation, | 87 blink::mojom::BudgetOperationType operation, |
| 87 const ReserveCallback& callback) { | 88 const ReserveCallback& callback) { |
| 88 // The RenderProcessHost should still be alive as long as any connections are | 89 // The RenderProcessHost should still be alive as long as any connections are |
| 89 // alive, and if the BudgetService mojo connection is down, the | 90 // alive, and if the BudgetService mojo connection is down, the |
| 90 // BudgetServiceImpl should have been destroyed. | 91 // BudgetServiceImpl should have been destroyed. |
| 91 content::RenderProcessHost* host = | 92 content::RenderProcessHost* host = |
| 92 content::RenderProcessHost::FromID(render_process_id_); | 93 content::RenderProcessHost::FromID(render_process_id_); |
| 93 DCHECK(host); | 94 DCHECK(host); |
| 94 | 95 |
| 95 // Request a reservation from the BudgetManager. | 96 // Request a reservation from the BudgetManager. |
| 96 content::BrowserContext* context = host->GetBrowserContext(); | 97 content::BrowserContext* context = host->GetBrowserContext(); |
| 97 BudgetManagerFactory::GetForProfile(context)->Reserve(origin, operation, | 98 BudgetManagerFactory::GetForProfile(context)->Reserve(origin, operation, |
| 98 callback); | 99 callback); |
| 99 } | 100 } |
| OLD | NEW |