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

Side by Side Diff: chrome/browser/engagement/site_engagement_service.cc

Issue 2285553002: [HBD] Gate the advertising of Flash on Site Engagement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/engagement/site_engagement_service.h" 5 #include "chrome/browser/engagement/site_engagement_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 99 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
100 switches::kDisableSiteEngagementService)) { 100 switches::kDisableSiteEngagementService)) {
101 return false; 101 return false;
102 } 102 }
103 const std::string group_name = 103 const std::string group_name =
104 base::FieldTrialList::FindFullName(kEngagementParams); 104 base::FieldTrialList::FindFullName(kEngagementParams);
105 return !base::StartsWith(group_name, "Disabled", 105 return !base::StartsWith(group_name, "Disabled",
106 base::CompareCase::SENSITIVE); 106 base::CompareCase::SENSITIVE);
107 } 107 }
108 108
109 // static
110 double SiteEngagementService::GetScoreFromSettings(
111 HostContentSettingsMap* settings,
112 const GURL& origin) {
113 auto clock = base::MakeUnique<base::DefaultClock>();
114 return SiteEngagementScore(clock.get(), origin, settings)
115 .GetScore();
116 }
117
109 SiteEngagementService::SiteEngagementService(Profile* profile) 118 SiteEngagementService::SiteEngagementService(Profile* profile)
110 : SiteEngagementService(profile, base::WrapUnique(new base::DefaultClock)) { 119 : SiteEngagementService(profile, base::MakeUnique<base::DefaultClock>()) {
111 content::BrowserThread::PostAfterStartupTask( 120 content::BrowserThread::PostAfterStartupTask(
112 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( 121 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread(
113 content::BrowserThread::UI), 122 content::BrowserThread::UI),
114 base::Bind(&SiteEngagementService::AfterStartupTask, 123 base::Bind(&SiteEngagementService::AfterStartupTask,
115 weak_factory_.GetWeakPtr())); 124 weak_factory_.GetWeakPtr()));
116 125
117 if (!g_updated_from_variations) { 126 if (!g_updated_from_variations) {
118 SiteEngagementScore::UpdateFromVariations(kEngagementParams); 127 SiteEngagementScore::UpdateFromVariations(kEngagementParams);
119 g_updated_from_variations = true; 128 g_updated_from_variations = true;
120 } 129 }
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 profile_, ServiceAccessType::EXPLICIT_ACCESS); 491 profile_, ServiceAccessType::EXPLICIT_ACCESS);
483 hs->GetCountsAndLastVisitForOrigins( 492 hs->GetCountsAndLastVisitForOrigins(
484 std::set<GURL>(origins.begin(), origins.end()), 493 std::set<GURL>(origins.begin(), origins.end()),
485 base::Bind( 494 base::Bind(
486 &SiteEngagementService::GetCountsAndLastVisitForOriginsComplete, 495 &SiteEngagementService::GetCountsAndLastVisitForOriginsComplete,
487 weak_factory_.GetWeakPtr(), hs, origins, expired)); 496 weak_factory_.GetWeakPtr(), hs, origins, expired));
488 } 497 }
489 498
490 SiteEngagementScore SiteEngagementService::CreateEngagementScore( 499 SiteEngagementScore SiteEngagementService::CreateEngagementScore(
491 const GURL& origin) const { 500 const GURL& origin) const {
492 return SiteEngagementScore(clock_.get(), origin, profile_); 501 // If we are in incognito, |settings| will automatically have the data from
502 // the original profile migrated in, so all engagement scores in incognito
503 // will be initialised to the values from the original profile.
504 return SiteEngagementScore(
505 clock_.get(), origin,
506 HostContentSettingsMapFactory::GetForProfile(profile_));
493 } 507 }
494 508
495 int SiteEngagementService::OriginsWithMaxDailyEngagement() const { 509 int SiteEngagementService::OriginsWithMaxDailyEngagement() const {
496 HostContentSettingsMap* settings_map = 510 HostContentSettingsMap* settings_map =
497 HostContentSettingsMapFactory::GetForProfile(profile_); 511 HostContentSettingsMapFactory::GetForProfile(profile_);
498 std::unique_ptr<ContentSettingsForOneType> engagement_settings = 512 std::unique_ptr<ContentSettingsForOneType> engagement_settings =
499 GetEngagementContentSettings(settings_map); 513 GetEngagementContentSettings(settings_map);
500 514
501 int total_origins = 0; 515 int total_origins = 0;
502 516
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 if (!engagement_score.last_shortcut_launch_time().is_null() && 597 if (!engagement_score.last_shortcut_launch_time().is_null() &&
584 engagement_score.last_shortcut_launch_time() > last_visit) { 598 engagement_score.last_shortcut_launch_time() > last_visit) {
585 engagement_score.set_last_shortcut_launch_time(last_visit); 599 engagement_score.set_last_shortcut_launch_time(last_visit);
586 } 600 }
587 601
588 engagement_score.Commit(); 602 engagement_score.Commit();
589 } 603 }
590 604
591 SetLastEngagementTime(now); 605 SetLastEngagementTime(now);
592 } 606 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_service.h ('k') | chrome/browser/engagement/site_engagement_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698