Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/engagement/site_engagement_service.h" | |
| 6 #include "chrome/browser/engagement/site_engagement_service_proxy.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "content/public/browser/browser_thread.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 std::map<GURL, int> DoGetScoresForOrigins( | |
| 13 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.
| |
| 14 const std::vector<GURL>& origins) { | |
| 15 std::map<GURL, int> score_map; | |
| 16 SiteEngagementService* service = | |
| 17 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); | |
| 18 if (!service) | |
| 19 return score_map; | |
| 20 | |
| 21 for (const auto& origin : origins) | |
| 22 score_map[origin] = service->GetScore(origin); | |
| 23 | |
| 24 return score_map; | |
| 25 } | |
| 26 | |
| 27 int DoGetTotalEngagementPoints(content::BrowserContext* browser_context) { | |
| 28 SiteEngagementService* service = | |
| 29 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); | |
| 30 return service ? service->GetTotalEngagementPoints() : 0; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 SiteEngagementServiceProxy::SiteEngagementServiceProxy( | |
| 36 content::BrowserContext* browser_context) | |
| 37 : browser_context_(browser_context) { | |
| 38 } | |
| 39 | |
| 40 SiteEngagementServiceProxy::~SiteEngagementServiceProxy() { | |
| 41 } | |
| 42 | |
| 43 void SiteEngagementServiceProxy::GetScoresForOrigins( | |
| 44 const std::vector<GURL>& origins, | |
| 45 base::Callback<void(const std::map<GURL, int>&)> callback) { | |
| 46 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 47 content::BrowserThread::UI, FROM_HERE, | |
| 48 base::Bind(&DoGetScoresForOrigins, browser_context_, origins), callback); | |
| 49 } | |
| 50 | |
| 51 void SiteEngagementServiceProxy::GetTotalEngagementPoints( | |
| 52 base::Callback<void(int)> callback) { | |
| 53 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 54 content::BrowserThread::UI, FROM_HERE, | |
| 55 base::Bind(&DoGetTotalEngagementPoints, browser_context_), callback); | |
| 56 } | |
| OLD | NEW |