Chromium Code Reviews| Index: chrome/browser/engagement/site_engagement_service_proxy.cc |
| diff --git a/chrome/browser/engagement/site_engagement_service_proxy.cc b/chrome/browser/engagement/site_engagement_service_proxy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a2b85af3a52347bf95f7bb2a169742f77223769 |
| --- /dev/null |
| +++ b/chrome/browser/engagement/site_engagement_service_proxy.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2015 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/engagement/site_engagement_service.h" |
| +#include "chrome/browser/engagement/site_engagement_service_proxy.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace { |
| + |
| +std::map<GURL, int> DoGetScoresForOrigins( |
| + content::BrowserContext* browser_context, |
|
raymes
2015/07/15 07:55:47
We can't know for sure whether the browser_context
calamity
2015/07/20 06:39:44
We now check with the profile manager.
|
| + const std::vector<GURL>& origins) { |
| + std::map<GURL, int> score_map; |
| + SiteEngagementService* service = |
| + SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
| + if (!service) |
| + return score_map; |
| + |
| + for (const auto& origin : origins) |
| + score_map[origin] = service->GetScore(origin); |
| + |
| + return score_map; |
| +} |
| + |
| +int DoGetTotalEngagementPoints(content::BrowserContext* browser_context) { |
| + SiteEngagementService* service = |
| + SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
| + return service ? service->GetTotalEngagementPoints() : 0; |
| +} |
| + |
| +} // namespace |
| + |
| +SiteEngagementServiceProxy::SiteEngagementServiceProxy( |
| + content::BrowserContext* browser_context) |
| + : browser_context_(browser_context) { |
| +} |
| + |
| +SiteEngagementServiceProxy::~SiteEngagementServiceProxy() { |
| +} |
| + |
| +void SiteEngagementServiceProxy::GetScoresForOrigins( |
| + const std::vector<GURL>& origins, |
| + base::Callback<void(const std::map<GURL, int>&)> callback) { |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&DoGetScoresForOrigins, browser_context_, origins), callback); |
| +} |
| + |
| +void SiteEngagementServiceProxy::GetTotalEngagementPoints( |
| + base::Callback<void(int)> callback) { |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&DoGetTotalEngagementPoints, browser_context_), callback); |
| +} |