Move AppMenuTest from ChromeShellTest to ChromePublicTest
[chromium-blink-merge.git] / chrome / browser / engagement / site_engagement_helper.cc
blobb107edf030c458bb1d9803395d91ab0dbc7652c6
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.
5 #include "chrome/browser/engagement/site_engagement_helper.h"
7 #include "chrome/browser/engagement/site_engagement_service.h"
8 #include "chrome/browser/engagement/site_engagement_service_factory.h"
9 #include "chrome/browser/prerender/prerender_contents.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/web_contents.h"
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SiteEngagementHelper);
16 SiteEngagementHelper::~SiteEngagementHelper() {
19 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* web_contents)
20 : content::WebContentsObserver(web_contents) {
23 void SiteEngagementHelper::DidStartNavigationToPendingEntry(
24 const GURL& url,
25 content::NavigationController::ReloadType reload_type) {
26 prerender::PrerenderContents* prerender_contents =
27 prerender::PrerenderContents::FromWebContents(web_contents());
29 // Ignore pre-render loads.
30 if (prerender_contents != NULL)
31 return;
33 // Ignore all schemes except HTTP and HTTPS.
34 if (!url.SchemeIsHTTPOrHTTPS())
35 return;
37 Profile* profile =
38 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
39 SiteEngagementService* service =
40 SiteEngagementServiceFactory::GetForProfile(profile);
41 // Service is null in incognito.
42 if (!service)
43 return;
45 service->HandleNavigation(url);