| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/preferences/important_sites_util.h" | 5 #include "chrome/browser/engagement/important_sites_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 CROSSED_ENGAGEMENT = 2, | 77 CROSSED_ENGAGEMENT = 2, |
| 78 CROSSED_NOTIFICATIONS_AND_ENGAGEMENT = 3, | 78 CROSSED_NOTIFICATIONS_AND_ENGAGEMENT = 3, |
| 79 CROSSED_DURABLE_AND_ENGAGEMENT = 4, | 79 CROSSED_DURABLE_AND_ENGAGEMENT = 4, |
| 80 CROSSED_NOTIFICATIONS_AND_DURABLE = 5, | 80 CROSSED_NOTIFICATIONS_AND_DURABLE = 5, |
| 81 CROSSED_NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT = 6, | 81 CROSSED_NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT = 6, |
| 82 CROSSED_REASON_UNKNOWN = 7, | 82 CROSSED_REASON_UNKNOWN = 7, |
| 83 CROSSED_REASON_BOUNDARY | 83 CROSSED_REASON_BOUNDARY |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 CrossedReason GetCrossedReasonFromBitfield(int32_t reason_bitfield) { | 86 CrossedReason GetCrossedReasonFromBitfield(int32_t reason_bitfield) { |
| 87 bool durable = reason_bitfield & (1 << ImportantReason::DURABLE); | 87 bool durable = (reason_bitfield & (1 << ImportantReason::DURABLE)) != 0; |
| 88 bool notifications = reason_bitfield & (1 << ImportantReason::NOTIFICATIONS); | 88 bool notifications = |
| 89 bool engagement = reason_bitfield & (1 << ImportantReason::ENGAGEMENT); | 89 (reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0; |
| 90 bool engagement = (reason_bitfield & (1 << ImportantReason::ENGAGEMENT)) != 0; |
| 90 if (durable && notifications && engagement) | 91 if (durable && notifications && engagement) |
| 91 return CROSSED_NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT; | 92 return CROSSED_NOTIFICATIONS_AND_DURABLE_AND_ENGAGEMENT; |
| 92 else if (notifications && durable) | 93 else if (notifications && durable) |
| 93 return CROSSED_NOTIFICATIONS_AND_DURABLE; | 94 return CROSSED_NOTIFICATIONS_AND_DURABLE; |
| 94 else if (notifications && engagement) | 95 else if (notifications && engagement) |
| 95 return CROSSED_NOTIFICATIONS_AND_ENGAGEMENT; | 96 return CROSSED_NOTIFICATIONS_AND_ENGAGEMENT; |
| 96 else if (durable && engagement) | 97 else if (durable && engagement) |
| 97 return CROSSED_DURABLE_AND_ENGAGEMENT; | 98 return CROSSED_DURABLE_AND_ENGAGEMENT; |
| 98 else if (notifications) | 99 else if (notifications) |
| 99 return CROSSED_NOTIFICATIONS; | 100 return CROSSED_NOTIFICATIONS; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // experiment to give us initial data on what signals actually mattered. | 424 // experiment to give us initial data on what signals actually mattered. |
| 424 for (int32_t reason_bitfield : blacklisted_sites_reason_bitfield) { | 425 for (int32_t reason_bitfield : blacklisted_sites_reason_bitfield) { |
| 425 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", | 426 UMA_HISTOGRAM_ENUMERATION("Storage.BlacklistedImportantSites.Reason", |
| 426 GetCrossedReasonFromBitfield(reason_bitfield), | 427 GetCrossedReasonFromBitfield(reason_bitfield), |
| 427 CROSSED_REASON_BOUNDARY); | 428 CROSSED_REASON_BOUNDARY); |
| 428 } | 429 } |
| 429 } | 430 } |
| 430 | 431 |
| 431 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, | 432 void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile, |
| 432 const GURL& origin) { | 433 const GURL& origin) { |
| 434 SiteEngagementScore::SetParamValuesForTesting(); |
| 433 // First get data from site engagement. | 435 // First get data from site engagement. |
| 434 SiteEngagementService* site_engagement_service = | 436 SiteEngagementService* site_engagement_service = |
| 435 SiteEngagementService::Get(profile); | 437 SiteEngagementService::Get(profile); |
| 436 site_engagement_service->ResetScoreForURL( | 438 site_engagement_service->ResetScoreForURL( |
| 437 origin, SiteEngagementScore::GetMediumEngagementBoundary()); | 439 origin, SiteEngagementScore::GetMediumEngagementBoundary()); |
| 438 DCHECK(site_engagement_service->IsEngagementAtLeast( | 440 DCHECK(site_engagement_service->IsEngagementAtLeast( |
| 439 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); | 441 origin, SiteEngagementService::ENGAGEMENT_LEVEL_MEDIUM)); |
| 440 } | 442 } |
| OLD | NEW |