Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1471)

Unified Diff: chrome/browser/budget_service/budget_service_impl.cc

Issue 2915173002: Return empty Budget API buckets if there is no notification permission (Closed)
Patch Set: comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/budget_service/budget_manager_browsertest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 5bbb9b42ea5e048be45223927a32f6f4ff7e053d..2db176cbc6e2f8da9ce771f30edb04aea2f6b104 100644
--- a/chrome/browser/budget_service/budget_service_impl.cc
+++ b/chrome/browser/budget_service/budget_service_impl.cc
@@ -7,7 +7,10 @@
#include "base/memory/ptr_util.h"
#include "chrome/browser/budget_service/budget_manager.h"
#include "chrome/browser/budget_service/budget_manager_factory.h"
+#include "chrome/browser/permissions/permission_manager.h"
+#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
@@ -50,9 +53,33 @@ void BudgetServiceImpl::GetBudget(const url::Origin& origin,
content::RenderProcessHost::FromID(render_process_id_);
DCHECK(host);
+ Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
+
+ PermissionManager* permission_manager =
+ PermissionManagerFactory::GetForProfile(profile);
+ DCHECK(permission_manager);
+
+ // By request of the Privacy Team, we only communicate the budget buckets with
+ // the developer when the notification permission has been granted. This is
+ // something the impact of which has to be reconsidered when the feature is
+ // ready to ship for real. See https://crbug.com/710809 for context.
+ if (permission_manager->GetPermissionStatus(
+ content::PermissionType::NOTIFICATIONS, origin.GetURL(), GURL()) !=
+ blink::mojom::PermissionStatus::GRANTED) {
+ blink::mojom::BudgetStatePtr empty_state(blink::mojom::BudgetState::New());
+ empty_state->budget_at = 0;
+ empty_state->time = base::Time::Now().ToDoubleT();
+
+ std::vector<blink::mojom::BudgetStatePtr> predictions;
+ predictions.push_back(std::move(empty_state));
+
+ callback.Run(blink::mojom::BudgetServiceErrorType::NONE,
+ std::move(predictions));
+ return;
+ }
+
// Query the BudgetManager for the budget.
- content::BrowserContext* context = host->GetBrowserContext();
- BudgetManagerFactory::GetForProfile(context)->GetBudget(origin, callback);
+ BudgetManagerFactory::GetForProfile(profile)->GetBudget(origin, callback);
}
void BudgetServiceImpl::Reserve(const url::Origin& origin,
« no previous file with comments | « chrome/browser/budget_service/budget_manager_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698