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

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

Issue 2748103011: Grant origins engagement for having interactions on their notifications. (Closed)
Patch Set: Created 3 years, 9 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (!ShouldRecordEngagement(url)) 468 if (!ShouldRecordEngagement(url))
469 return; 469 return;
470 470
471 SiteEngagementMetrics::RecordEngagement( 471 SiteEngagementMetrics::RecordEngagement(
472 is_hidden ? SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN 472 is_hidden ? SiteEngagementMetrics::ENGAGEMENT_MEDIA_HIDDEN
473 : SiteEngagementMetrics::ENGAGEMENT_MEDIA_VISIBLE); 473 : SiteEngagementMetrics::ENGAGEMENT_MEDIA_VISIBLE);
474 AddPoints(url, is_hidden ? SiteEngagementScore::GetHiddenMediaPoints() 474 AddPoints(url, is_hidden ? SiteEngagementScore::GetHiddenMediaPoints()
475 : SiteEngagementScore::GetVisibleMediaPoints()); 475 : SiteEngagementScore::GetVisibleMediaPoints());
476 476
477 RecordMetrics(); 477 RecordMetrics();
478 double score = GetScore(url);
478 for (SiteEngagementObserver& observer : observer_list_) 479 for (SiteEngagementObserver& observer : observer_list_)
479 observer.OnEngagementIncreased(web_contents, url, GetScore(url)); 480 observer.OnEngagementIncreased(web_contents, url, score);
480 } 481 }
481 482
482 void SiteEngagementService::HandleNavigation(content::WebContents* web_contents, 483 void SiteEngagementService::HandleNavigation(content::WebContents* web_contents,
483 ui::PageTransition transition) { 484 ui::PageTransition transition) {
484 const GURL& url = web_contents->GetLastCommittedURL(); 485 const GURL& url = web_contents->GetLastCommittedURL();
485 if (!IsEngagementNavigation(transition) || !ShouldRecordEngagement(url)) 486 if (!IsEngagementNavigation(transition) || !ShouldRecordEngagement(url))
486 return; 487 return;
487 488
488 SiteEngagementMetrics::RecordEngagement( 489 SiteEngagementMetrics::RecordEngagement(
489 SiteEngagementMetrics::ENGAGEMENT_NAVIGATION); 490 SiteEngagementMetrics::ENGAGEMENT_NAVIGATION);
490 AddPoints(url, SiteEngagementScore::GetNavigationPoints()); 491 AddPoints(url, SiteEngagementScore::GetNavigationPoints());
491 492
492 RecordMetrics(); 493 RecordMetrics();
494 double score = GetScore(url);
493 for (SiteEngagementObserver& observer : observer_list_) 495 for (SiteEngagementObserver& observer : observer_list_)
494 observer.OnEngagementIncreased(web_contents, url, GetScore(url)); 496 observer.OnEngagementIncreased(web_contents, url, score);
495 } 497 }
496 498
497 void SiteEngagementService::HandleUserInput( 499 void SiteEngagementService::HandleUserInput(
498 content::WebContents* web_contents, 500 content::WebContents* web_contents,
499 SiteEngagementMetrics::EngagementType type) { 501 SiteEngagementMetrics::EngagementType type) {
500 const GURL& url = web_contents->GetLastCommittedURL(); 502 const GURL& url = web_contents->GetLastCommittedURL();
501 if (!ShouldRecordEngagement(url)) 503 if (!ShouldRecordEngagement(url))
502 return; 504 return;
503 505
504 SiteEngagementMetrics::RecordEngagement(type); 506 SiteEngagementMetrics::RecordEngagement(type);
505 AddPoints(url, SiteEngagementScore::GetUserInputPoints()); 507 AddPoints(url, SiteEngagementScore::GetUserInputPoints());
506 508
507 RecordMetrics(); 509 RecordMetrics();
510 double score = GetScore(url);
508 for (SiteEngagementObserver& observer : observer_list_) 511 for (SiteEngagementObserver& observer : observer_list_)
509 observer.OnEngagementIncreased(web_contents, url, GetScore(url)); 512 observer.OnEngagementIncreased(web_contents, url, score);
513 }
514
515 void SiteEngagementService::HandleNotificationInteraction(const GURL& url) {
516 if (!ShouldRecordEngagement(url))
517 return;
518
519 SiteEngagementMetrics::RecordEngagement(
520 SiteEngagementMetrics::ENGAGEMENT_NOTIFICATION_INTERACTION);
521 AddPoints(url, SiteEngagementScore::GetNotificationInteractionPoints());
522
523 RecordMetrics();
524 double score = GetScore(url);
525 for (SiteEngagementObserver& observer : observer_list_)
526 observer.OnEngagementIncreased(nullptr, url, score);
510 } 527 }
511 528
512 void SiteEngagementService::SendLevelChangeToHelpers( 529 void SiteEngagementService::SendLevelChangeToHelpers(
513 const GURL& url, 530 const GURL& url,
514 blink::mojom::EngagementLevel level) { 531 blink::mojom::EngagementLevel level) {
515 for (SiteEngagementService::Helper* helper : helpers_) 532 for (SiteEngagementService::Helper* helper : helpers_)
516 helper->OnEngagementLevelChanged(url, level); 533 helper->OnEngagementLevelChanged(url, level);
517 } 534 }
518 535
519 bool SiteEngagementService::IsLastEngagementStale() const { 536 bool SiteEngagementService::IsLastEngagementStale() const {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 if (!engagement_score.last_shortcut_launch_time().is_null() && 665 if (!engagement_score.last_shortcut_launch_time().is_null() &&
649 engagement_score.last_shortcut_launch_time() > last_visit) { 666 engagement_score.last_shortcut_launch_time() > last_visit) {
650 engagement_score.set_last_shortcut_launch_time(last_visit); 667 engagement_score.set_last_shortcut_launch_time(last_visit);
651 } 668 }
652 669
653 engagement_score.Commit(); 670 engagement_score.Commit();
654 } 671 }
655 672
656 SetLastEngagementTime(now); 673 SetLastEngagementTime(now);
657 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698