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

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

Issue 2265173002: Created Mojo BudgetService implementation in chrome/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_service
Patch Set: Remove use of local variable and call GetCost directly. Created 4 years, 4 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..5a6b8b857681a27b94605ddd76559a3f0e74569a
--- /dev/null
+++ b/chrome/browser/budget_service/budget_service_impl.cc
@@ -0,0 +1,45 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/budget_service/budget_service_impl.h"
+
+#include "chrome/browser/budget_service/budget_manager.h"
+#include "chrome/browser/budget_service/budget_manager_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/render_process_host.h"
+
+// static
+void BudgetServiceImpl::Create(int render_process_id,
+ blink::mojom::BudgetServiceRequest request) {
+ new BudgetServiceImpl(render_process_id, std::move(request));
+}
+
+BudgetServiceImpl::BudgetServiceImpl(int render_process_id,
+ blink::mojom::BudgetServiceRequest request)
+ : render_process_id_(render_process_id),
+ binding_(this, std::move(request)) {}
+
+BudgetServiceImpl::~BudgetServiceImpl() = default;
+
+void BudgetServiceImpl::GetCost(blink::mojom::BudgetOperationType type,
+ const GetCostCallback& callback) {
+ // The RenderProcessHost should still be alive as long as any connections are
+ // alive, and if the BudgetService mojo connection is down, the
+ // BudgetServiceImpl should have been destroyed.
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(render_process_id_);
+ DCHECK(host);
+
+ // Query the BudgetManager for the cost and return it.
+ content::BrowserContext* context = host->GetBrowserContext();
+ double cost = BudgetManagerFactory::GetForProfile(context)->GetCost(type);
+ callback.Run(cost);
+}
+
+void BudgetServiceImpl::GetBudget(const url::Origin& origin,
+ const GetBudgetCallback& callback) {
+ // TODO(harkness) Call the BudgetManager once it supports detailed GetBudget
+ // calls.
+ callback.Run(0);
+}
« no previous file with comments | « chrome/browser/budget_service/budget_service_impl.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698