Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / invalidation / ticl_profile_settings_provider.cc
blob6b2292c9f8eef8fe7e83f4b932c9b60d64245dde
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/invalidation/ticl_profile_settings_provider.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/gcm_driver/gcm_channel_status_syncer.h"
17 namespace invalidation {
19 TiclProfileSettingsProvider::TiclProfileSettingsProvider(Profile* profile)
20 : profile_(profile) {
21 registrar_.Init(profile->GetPrefs());
22 registrar_.Add(
23 prefs::kInvalidationServiceUseGCMChannel,
24 base::Bind(&TiclProfileSettingsProvider::FireOnUseGCMChannelChanged,
25 base::Unretained(this)));
26 registrar_.Add(
27 gcm::prefs::kGCMChannelStatus,
28 base::Bind(&TiclProfileSettingsProvider::FireOnUseGCMChannelChanged,
29 base::Unretained(this)));
32 TiclProfileSettingsProvider::~TiclProfileSettingsProvider() {
35 bool TiclProfileSettingsProvider::UseGCMChannel() const {
36 if (!gcm::GCMProfileService::IsGCMEnabled(profile_)) {
37 // Do not try to use GCM channel if GCM is disabled.
38 return false;
41 if (profile_->GetPrefs()->GetBoolean(
42 prefs::kInvalidationServiceUseGCMChannel)) {
43 // Use GCM channel if it was enabled via prefs.
44 return true;
47 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
48 switches::kInvalidationUseGCMChannel)) {
49 // Use GCM channel if it was enabled via a command-line switch.
50 return true;
53 // By default, do not use GCM channel.
54 return false;
57 } // namespace invalidation