| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/services/gcm/gcm_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 // static | 121 // static |
| 122 bool GCMProfileService::IsGCMEnabled(Profile* profile) { | 122 bool GCMProfileService::IsGCMEnabled(Profile* profile) { |
| 123 #if defined(OS_ANDROID) | 123 #if defined(OS_ANDROID) |
| 124 return true; | 124 return true; |
| 125 #else | 125 #else |
| 126 return profile->GetPrefs()->GetBoolean(gcm::prefs::kGCMChannelStatus); | 126 return profile->GetPrefs()->GetBoolean(gcm::prefs::kGCMChannelStatus); |
| 127 #endif // defined(OS_ANDROID) | 127 #endif // defined(OS_ANDROID) |
| 128 } | 128 } |
| 129 | 129 |
| 130 // static | |
| 131 void GCMProfileService::RegisterProfilePrefs( | |
| 132 user_prefs::PrefRegistrySyncable* registry) { | |
| 133 PushMessagingServiceImpl::RegisterProfilePrefs(registry); | |
| 134 } | |
| 135 | |
| 136 #if defined(OS_ANDROID) | 130 #if defined(OS_ANDROID) |
| 137 static GCMProfileService* debug_instance = nullptr; | 131 static GCMProfileService* debug_instance = nullptr; |
| 138 | 132 |
| 139 GCMProfileService::GCMProfileService(Profile* profile) | 133 GCMProfileService::GCMProfileService(Profile* profile) |
| 140 : profile_(profile), | 134 : profile_(profile) { |
| 141 push_messaging_service_(this, profile) { | |
| 142 CHECK(!profile->IsOffTheRecord()); | 135 CHECK(!profile->IsOffTheRecord()); |
| 143 | 136 |
| 144 // TODO(johnme): Remove debug_instance and this logging code once | 137 // TODO(johnme): Remove debug_instance and this logging code once |
| 145 // crbug.com/437827 is fixed. | 138 // crbug.com/437827 is fixed. |
| 146 if (debug_instance != nullptr) { | 139 if (debug_instance != nullptr) { |
| 147 LOG(FATAL) << "An instance of GCMProfileService already exists!" | 140 LOG(FATAL) << "An instance of GCMProfileService already exists!" |
| 148 << " Old profile: " << debug_instance->profile_ << " " | 141 << " Old profile: " << debug_instance->profile_ << " " |
| 149 << debug_instance->profile_->GetDebugName() << " " | 142 << debug_instance->profile_->GetDebugName() << " " |
| 150 << debug_instance->profile_->GetProfileType() << " " | 143 << debug_instance->profile_->GetProfileType() << " " |
| 151 << debug_instance->profile_->IsSupervised() << " " | 144 << debug_instance->profile_->IsSupervised() << " " |
| 152 << debug_instance->profile_->IsNewProfile() << " " | 145 << debug_instance->profile_->IsNewProfile() << " " |
| 153 << debug_instance->profile_->GetStartTime().ToInternalValue() | 146 << debug_instance->profile_->GetStartTime().ToInternalValue() |
| 154 << ", new profile: " << profile << " " | 147 << ", new profile: " << profile << " " |
| 155 << profile->GetDebugName() << " " | 148 << profile->GetDebugName() << " " |
| 156 << profile->GetProfileType() << " " | 149 << profile->GetProfileType() << " " |
| 157 << profile->IsSupervised() << " " | 150 << profile->IsSupervised() << " " |
| 158 << profile->IsNewProfile() << " " | 151 << profile->IsNewProfile() << " " |
| 159 << profile->GetStartTime().ToInternalValue(); | 152 << profile->GetStartTime().ToInternalValue(); |
| 160 } | 153 } |
| 161 debug_instance = this; | 154 debug_instance = this; |
| 162 | 155 |
| 163 driver_.reset(new GCMDriverAndroid); | 156 driver_.reset(new GCMDriverAndroid); |
| 164 } | 157 } |
| 165 #else | 158 #else |
| 166 GCMProfileService::GCMProfileService( | 159 GCMProfileService::GCMProfileService( |
| 167 Profile* profile, | 160 Profile* profile, |
| 168 scoped_ptr<GCMClientFactory> gcm_client_factory) | 161 scoped_ptr<GCMClientFactory> gcm_client_factory) |
| 169 : profile_(profile), | 162 : profile_(profile) { |
| 170 push_messaging_service_(this, profile) { | |
| 171 DCHECK(!profile->IsOffTheRecord()); | 163 DCHECK(!profile->IsOffTheRecord()); |
| 172 | 164 |
| 173 driver_ = CreateGCMDriverDesktop( | 165 driver_ = CreateGCMDriverDesktop( |
| 174 gcm_client_factory.Pass(), | 166 gcm_client_factory.Pass(), |
| 175 profile_->GetPrefs(), | 167 profile_->GetPrefs(), |
| 176 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 168 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 177 profile_->GetRequestContext()); | 169 profile_->GetRequestContext()); |
| 178 | 170 |
| 179 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); | 171 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); |
| 180 } | 172 } |
| 181 #endif // defined(OS_ANDROID) | 173 #endif // defined(OS_ANDROID) |
| 182 | 174 |
| 183 GCMProfileService::GCMProfileService() | 175 GCMProfileService::GCMProfileService() |
| 184 : profile_(NULL), | 176 : profile_(NULL) { |
| 185 push_messaging_service_(this, NULL) { | |
| 186 } | 177 } |
| 187 | 178 |
| 188 GCMProfileService::~GCMProfileService() { | 179 GCMProfileService::~GCMProfileService() { |
| 189 #if defined(OS_ANDROID) | 180 #if defined(OS_ANDROID) |
| 190 debug_instance = nullptr; | 181 debug_instance = nullptr; |
| 191 #endif | 182 #endif |
| 192 } | 183 } |
| 193 | 184 |
| 194 void GCMProfileService::Shutdown() { | 185 void GCMProfileService::Shutdown() { |
| 195 #if !defined(OS_ANDROID) | 186 #if !defined(OS_ANDROID) |
| 196 identity_observer_.reset(); | 187 identity_observer_.reset(); |
| 197 #endif // !defined(OS_ANDROID) | 188 #endif // !defined(OS_ANDROID) |
| 198 if (driver_) { | 189 if (driver_) { |
| 199 driver_->Shutdown(); | 190 driver_->Shutdown(); |
| 200 driver_.reset(); | 191 driver_.reset(); |
| 201 } | 192 } |
| 202 } | 193 } |
| 203 | 194 |
| 204 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 195 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
| 205 driver_.reset(driver); | 196 driver_.reset(driver); |
| 206 #if !defined(OS_ANDROID) | 197 #if !defined(OS_ANDROID) |
| 207 if (identity_observer_) | 198 if (identity_observer_) |
| 208 identity_observer_.reset(new IdentityObserver(profile_, driver)); | 199 identity_observer_.reset(new IdentityObserver(profile_, driver)); |
| 209 #endif // !defined(OS_ANDROID) | 200 #endif // !defined(OS_ANDROID) |
| 210 } | 201 } |
| 211 | 202 |
| 212 } // namespace gcm | 203 } // namespace gcm |
| OLD | NEW |