OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/invalidation/ticl_invalidation_service_profile_settings
_provider.h" |
| 6 |
| 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 |
| 16 namespace invalidation { |
| 17 |
| 18 TiclInvalidationServiceProfileSettingsProvider:: |
| 19 TiclInvalidationServiceProfileSettingsProvider(Profile* profile) |
| 20 : profile_(profile) { |
| 21 registrar_.Init(profile->GetPrefs()); |
| 22 registrar_.Add(prefs::kInvalidationServiceUseGCMChannel, |
| 23 base::Bind(&TiclInvalidationServiceProfileSettingsProvider:: |
| 24 FireOnUseGCMChannelChanged, |
| 25 base::Unretained(this))); |
| 26 registrar_.Add(prefs::kGCMChannelEnabled, |
| 27 base::Bind(&TiclInvalidationServiceProfileSettingsProvider:: |
| 28 FireOnUseGCMChannelChanged, |
| 29 base::Unretained(this))); |
| 30 } |
| 31 |
| 32 TiclInvalidationServiceProfileSettingsProvider:: |
| 33 ~TiclInvalidationServiceProfileSettingsProvider() { |
| 34 } |
| 35 |
| 36 bool TiclInvalidationServiceProfileSettingsProvider::UseGCMChannel() const { |
| 37 if (gcm::GCMProfileService::GetGCMEnabledState(profile_) != |
| 38 gcm::GCMProfileService::ALWAYS_ENABLED) { |
| 39 // Do not use GCM channel if GCM is disabled or is to be used for apps only. |
| 40 return false; |
| 41 } |
| 42 |
| 43 if (profile_->GetPrefs()->GetBoolean( |
| 44 prefs::kInvalidationServiceUseGCMChannel)) { |
| 45 // Use GCM channel if it was enabled via prefs. |
| 46 return true; |
| 47 } |
| 48 |
| 49 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 50 switches::kInvalidationUseGCMChannel)) { |
| 51 // Use GCM channel if it was enabled via a command-line switch. |
| 52 return true; |
| 53 } |
| 54 |
| 55 // By default, do not use GCM channel. |
| 56 return false; |
| 57 } |
| 58 |
| 59 } // namespace invalidation |
OLD | NEW |