Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / google / chrome_google_url_tracker_client.cc
blobd8bc86df9f982e7a8c746dc7d35e5d4f7968a17f
1 // Copyright 2014 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/google/chrome_google_url_tracker_client.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "components/google/core/browser/google_url_tracker.h"
14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/web_contents.h"
19 ChromeGoogleURLTrackerClient::ChromeGoogleURLTrackerClient(Profile* profile)
20 : profile_(profile) {
23 ChromeGoogleURLTrackerClient::~ChromeGoogleURLTrackerClient() {
26 void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
27 if (listen) {
28 registrar_.Add(
29 this,
30 content::NOTIFICATION_NAV_ENTRY_PENDING,
31 content::NotificationService::AllBrowserContextsAndSources());
32 } else {
33 registrar_.Remove(
34 this,
35 content::NOTIFICATION_NAV_ENTRY_PENDING,
36 content::NotificationService::AllBrowserContextsAndSources());
40 bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() {
41 return registrar_.IsRegistered(
42 this,
43 content::NOTIFICATION_NAV_ENTRY_PENDING,
44 content::NotificationService::AllBrowserContextsAndSources());
47 bool ChromeGoogleURLTrackerClient::IsBackgroundNetworkingEnabled() {
48 return !CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kDisableBackgroundNetworking);
52 PrefService* ChromeGoogleURLTrackerClient::GetPrefs() {
53 return profile_->GetPrefs();
56 net::URLRequestContextGetter*
57 ChromeGoogleURLTrackerClient::GetRequestContext() {
58 return profile_->GetRequestContext();
61 void ChromeGoogleURLTrackerClient::Observe(
62 int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) {
65 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type);
66 content::NavigationController* controller =
67 content::Source<content::NavigationController>(source).ptr();
68 InfoBarService* infobar_service =
69 InfoBarService::FromWebContents(controller->GetWebContents());
70 // Because we're listening to all sources, there may be no InfoBarService for
71 // some notifications, e.g. navigations in bubbles/balloons etc.
72 if (infobar_service) {
73 google_url_tracker()->OnNavigationPending(
74 scoped_ptr<GoogleURLTrackerNavigationHelper>(
75 new GoogleURLTrackerNavigationHelperImpl(
76 controller->GetWebContents(), google_url_tracker())),
77 infobar_service,
78 controller->GetPendingEntry()->GetUniqueID());