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

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

Issue 2002443002: Bail out of resetting a URL's engagement if the URL is not valid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 498
499 double score = 499 double score =
500 std::min(SiteEngagementScore::kMaxPoints, 500 std::min(SiteEngagementScore::kMaxPoints,
501 (proportion_remaining * GetScore(origin)) + undecay); 501 (proportion_remaining * GetScore(origin)) + undecay);
502 ResetScoreAndAccessTimesForURL(origin, score, &last_visit); 502 ResetScoreAndAccessTimesForURL(origin, score, &last_visit);
503 } 503 }
504 } 504 }
505 505
506 void SiteEngagementService::ResetScoreAndAccessTimesForURL( 506 void SiteEngagementService::ResetScoreAndAccessTimesForURL(
507 const GURL& url, double score, const base::Time* updated_time) { 507 const GURL& url, double score, const base::Time* updated_time) {
508 DCHECK(url.is_valid()); 508 // It appears that the history service occassionally sends bad URLs to us.
509 // See crbug.com/612881.
510 if (!url.is_valid())
511 return;
512
509 DCHECK_GE(score, 0); 513 DCHECK_GE(score, 0);
510 DCHECK_LE(score, SiteEngagementScore::kMaxPoints); 514 DCHECK_LE(score, SiteEngagementScore::kMaxPoints);
511 515
512 HostContentSettingsMap* settings_map = 516 HostContentSettingsMap* settings_map =
513 HostContentSettingsMapFactory::GetForProfile(profile_); 517 HostContentSettingsMapFactory::GetForProfile(profile_);
514 std::unique_ptr<base::DictionaryValue> score_dict = 518 std::unique_ptr<base::DictionaryValue> score_dict =
515 GetScoreDictForOrigin(settings_map, url); 519 GetScoreDictForOrigin(settings_map, url);
516 SiteEngagementScore engagement_score(clock_.get(), *score_dict); 520 SiteEngagementScore engagement_score(clock_.get(), *score_dict);
517 521
518 engagement_score.Reset(score, updated_time); 522 engagement_score.Reset(score, updated_time);
519 if (score == 0) { 523 if (score == 0) {
520 settings_map->SetWebsiteSettingDefaultScope( 524 settings_map->SetWebsiteSettingDefaultScope(
521 url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), 525 url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
522 nullptr); 526 nullptr);
523 return; 527 return;
524 } 528 }
525 529
526 if (engagement_score.UpdateScoreDict(score_dict.get())) { 530 if (engagement_score.UpdateScoreDict(score_dict.get())) {
527 settings_map->SetWebsiteSettingDefaultScope( 531 settings_map->SetWebsiteSettingDefaultScope(
528 url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), 532 url, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
529 score_dict.release()); 533 score_dict.release());
530 } 534 }
531 } 535 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698