Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/permissions/permission_manager_factory.h" | 11 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 12 #include "chrome/browser/permissions/permission_result.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 | 17 |
| 17 BudgetServiceImpl::BudgetServiceImpl(int render_process_id) | 18 BudgetServiceImpl::BudgetServiceImpl(int render_process_id) |
| 18 : render_process_id_(render_process_id) {} | 19 : render_process_id_(render_process_id) {} |
| 19 | 20 |
| 20 BudgetServiceImpl::~BudgetServiceImpl() = default; | 21 BudgetServiceImpl::~BudgetServiceImpl() = default; |
| 21 | 22 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 57 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 57 | 58 |
| 58 PermissionManager* permission_manager = | 59 PermissionManager* permission_manager = |
| 59 PermissionManagerFactory::GetForProfile(profile); | 60 PermissionManagerFactory::GetForProfile(profile); |
| 60 DCHECK(permission_manager); | 61 DCHECK(permission_manager); |
| 61 | 62 |
| 62 // By request of the Privacy Team, we only communicate the budget buckets with | 63 // 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 | 64 // 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 | 65 // 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. | 66 // ready to ship for real. See https://crbug.com/710809 for context. |
| 66 if (permission_manager->GetPermissionStatus( | 67 if (permission_manager |
| 67 content::PermissionType::NOTIFICATIONS, origin.GetURL(), GURL()) != | 68 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
|
johnme
2017/06/12 10:18:20
This loses the call to UpdatePermissionStatusWithD
| |
| 68 blink::mojom::PermissionStatus::GRANTED) { | 69 origin.GetURL(), GURL()) |
| 70 .content_setting != CONTENT_SETTING_ALLOW) { | |
| 69 blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New()); | 71 blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New()); |
| 70 empty_state->budget_at = 0; | 72 empty_state->budget_at = 0; |
| 71 empty_state->time = | 73 empty_state->time = |
| 72 base::Time::Now().ToDoubleT() * base::Time::kMillisecondsPerSecond; | 74 base::Time::Now().ToDoubleT() * base::Time::kMillisecondsPerSecond; |
| 73 | 75 |
| 74 std::vector<blink::mojom::BudgetStatePtr> predictions; | 76 std::vector<blink::mojom::BudgetStatePtr> predictions; |
| 75 predictions.push_back(std::move(empty_state)); | 77 predictions.push_back(std::move(empty_state)); |
| 76 | 78 |
| 77 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, | 79 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, |
| 78 std::move(predictions)); | 80 std::move(predictions)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 91 // BudgetServiceImpl should have been destroyed. | 93 // BudgetServiceImpl should have been destroyed. |
| 92 content::RenderProcessHost* host = | 94 content::RenderProcessHost* host = |
| 93 content::RenderProcessHost::FromID(render_process_id_); | 95 content::RenderProcessHost::FromID(render_process_id_); |
| 94 DCHECK(host); | 96 DCHECK(host); |
| 95 | 97 |
| 96 // Request a reservation from the BudgetManager. | 98 // Request a reservation from the BudgetManager. |
| 97 content::BrowserContext* context = host->GetBrowserContext(); | 99 content::BrowserContext* context = host->GetBrowserContext(); |
| 98 BudgetManagerFactory::GetForProfile(context)->Reserve(origin, operation, | 100 BudgetManagerFactory::GetForProfile(context)->Reserve(origin, operation, |
| 99 callback); | 101 callback); |
| 100 } | 102 } |
| OLD | NEW |