| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void GCMProfileService::RegisterProfilePrefs( | 135 void GCMProfileService::RegisterProfilePrefs( |
| 136 user_prefs::PrefRegistrySyncable* registry) { | 136 user_prefs::PrefRegistrySyncable* registry) { |
| 137 registry->RegisterBooleanPref( | 137 registry->RegisterBooleanPref( |
| 138 prefs::kGCMChannelEnabled, | 138 prefs::kGCMChannelEnabled, |
| 139 true, | 139 true, |
| 140 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 140 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 141 PushMessagingServiceImpl::RegisterProfilePrefs(registry); | 141 PushMessagingServiceImpl::RegisterProfilePrefs(registry); |
| 142 } | 142 } |
| 143 | 143 |
| 144 #if defined(OS_ANDROID) | 144 #if defined(OS_ANDROID) |
| 145 static GCMProfileService* debug_instance = nullptr; |
| 146 |
| 145 GCMProfileService::GCMProfileService(Profile* profile) | 147 GCMProfileService::GCMProfileService(Profile* profile) |
| 146 : profile_(profile), | 148 : profile_(profile), |
| 147 push_messaging_service_(this, profile) { | 149 push_messaging_service_(this, profile) { |
| 148 DCHECK(!profile->IsOffTheRecord()); | 150 CHECK(!profile->IsOffTheRecord()); |
| 151 |
| 152 // TODO(johnme): Remove debug_instance and this logging code once |
| 153 // crbug.com/437827 is fixed. |
| 154 if (debug_instance != nullptr) { |
| 155 LOG(FATAL) << "An instance of GCMProfileService already exists!" |
| 156 << " Old profile: " << debug_instance->profile_ << " " |
| 157 << debug_instance->profile_->GetDebugName() << " " |
| 158 << debug_instance->profile_->GetProfileType() << " " |
| 159 << debug_instance->profile_->IsSupervised() << " " |
| 160 << debug_instance->profile_->IsNewProfile() << " " |
| 161 << debug_instance->profile_->GetStartTime().ToInternalValue() |
| 162 << ", new profile: " << profile << " " |
| 163 << profile->GetDebugName() << " " |
| 164 << profile->GetProfileType() << " " |
| 165 << profile->IsSupervised() << " " |
| 166 << profile->IsNewProfile() << " " |
| 167 << profile->GetStartTime().ToInternalValue(); |
| 168 } |
| 169 debug_instance = this; |
| 149 | 170 |
| 150 driver_.reset(new GCMDriverAndroid); | 171 driver_.reset(new GCMDriverAndroid); |
| 151 } | 172 } |
| 152 #else | 173 #else |
| 153 GCMProfileService::GCMProfileService( | 174 GCMProfileService::GCMProfileService( |
| 154 Profile* profile, | 175 Profile* profile, |
| 155 scoped_ptr<GCMClientFactory> gcm_client_factory) | 176 scoped_ptr<GCMClientFactory> gcm_client_factory) |
| 156 : profile_(profile), | 177 : profile_(profile), |
| 157 push_messaging_service_(this, profile) { | 178 push_messaging_service_(this, profile) { |
| 158 DCHECK(!profile->IsOffTheRecord()); | 179 DCHECK(!profile->IsOffTheRecord()); |
| 159 | 180 |
| 160 driver_ = CreateGCMDriverDesktop( | 181 driver_ = CreateGCMDriverDesktop( |
| 161 gcm_client_factory.Pass(), | 182 gcm_client_factory.Pass(), |
| 162 profile_->GetPrefs(), | 183 profile_->GetPrefs(), |
| 163 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 184 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 164 profile_->GetRequestContext()); | 185 profile_->GetRequestContext()); |
| 165 | 186 |
| 166 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); | 187 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); |
| 167 } | 188 } |
| 168 #endif // defined(OS_ANDROID) | 189 #endif // defined(OS_ANDROID) |
| 169 | 190 |
| 170 GCMProfileService::GCMProfileService() | 191 GCMProfileService::GCMProfileService() |
| 171 : profile_(NULL), | 192 : profile_(NULL), |
| 172 push_messaging_service_(this, NULL) { | 193 push_messaging_service_(this, NULL) { |
| 173 } | 194 } |
| 174 | 195 |
| 175 GCMProfileService::~GCMProfileService() { | 196 GCMProfileService::~GCMProfileService() { |
| 197 #if defined(OS_ANDROID) |
| 198 debug_instance = nullptr; |
| 199 #endif |
| 176 } | 200 } |
| 177 | 201 |
| 178 void GCMProfileService::Shutdown() { | 202 void GCMProfileService::Shutdown() { |
| 179 #if !defined(OS_ANDROID) | 203 #if !defined(OS_ANDROID) |
| 180 identity_observer_.reset(); | 204 identity_observer_.reset(); |
| 181 #endif // !defined(OS_ANDROID) | 205 #endif // !defined(OS_ANDROID) |
| 182 if (driver_) { | 206 if (driver_) { |
| 183 driver_->Shutdown(); | 207 driver_->Shutdown(); |
| 184 driver_.reset(); | 208 driver_.reset(); |
| 185 } | 209 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 | 220 |
| 197 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 221 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
| 198 driver_.reset(driver); | 222 driver_.reset(driver); |
| 199 #if !defined(OS_ANDROID) | 223 #if !defined(OS_ANDROID) |
| 200 if (identity_observer_) | 224 if (identity_observer_) |
| 201 identity_observer_.reset(new IdentityObserver(profile_, driver)); | 225 identity_observer_.reset(new IdentityObserver(profile_, driver)); |
| 202 #endif // !defined(OS_ANDROID) | 226 #endif // !defined(OS_ANDROID) |
| 203 } | 227 } |
| 204 | 228 |
| 205 } // namespace gcm | 229 } // namespace gcm |
| OLD | NEW |