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) { | 135 push_messaging_service_(this, profile) { |
142 CHECK(!profile->IsOffTheRecord()); | 136 CHECK(!profile->IsOffTheRecord()); |
143 | 137 |
144 // TODO(johnme): Remove debug_instance and this logging code once | 138 // TODO(johnme): Remove debug_instance and this logging code once |
145 // crbug.com/437827 is fixed. | 139 // crbug.com/437827 is fixed. |
(...skipping 13 matching lines...) Expand all Loading... |
159 << profile->GetStartTime().ToInternalValue(); | 153 << profile->GetStartTime().ToInternalValue(); |
160 } | 154 } |
161 debug_instance = this; | 155 debug_instance = this; |
162 | 156 |
163 driver_.reset(new GCMDriverAndroid); | 157 driver_.reset(new GCMDriverAndroid); |
164 } | 158 } |
165 #else | 159 #else |
166 GCMProfileService::GCMProfileService( | 160 GCMProfileService::GCMProfileService( |
167 Profile* profile, | 161 Profile* profile, |
168 scoped_ptr<GCMClientFactory> gcm_client_factory) | 162 scoped_ptr<GCMClientFactory> gcm_client_factory) |
169 : profile_(profile), | 163 : profile_(profile) { |
170 push_messaging_service_(this, profile) { | |
171 DCHECK(!profile->IsOffTheRecord()); | 164 DCHECK(!profile->IsOffTheRecord()); |
172 | 165 |
173 driver_ = CreateGCMDriverDesktop( | 166 driver_ = CreateGCMDriverDesktop( |
174 gcm_client_factory.Pass(), | 167 gcm_client_factory.Pass(), |
175 profile_->GetPrefs(), | 168 profile_->GetPrefs(), |
176 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 169 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
177 profile_->GetRequestContext()); | 170 profile_->GetRequestContext()); |
178 | 171 |
179 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); | 172 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); |
180 } | 173 } |
181 #endif // defined(OS_ANDROID) | 174 #endif // defined(OS_ANDROID) |
182 | 175 |
183 GCMProfileService::GCMProfileService() | 176 GCMProfileService::GCMProfileService() |
184 : profile_(NULL), | 177 : profile_(NULL) { |
185 push_messaging_service_(this, NULL) { | |
186 } | 178 } |
187 | 179 |
188 GCMProfileService::~GCMProfileService() { | 180 GCMProfileService::~GCMProfileService() { |
189 #if defined(OS_ANDROID) | 181 #if defined(OS_ANDROID) |
190 debug_instance = nullptr; | 182 debug_instance = nullptr; |
191 #endif | 183 #endif |
192 } | 184 } |
193 | 185 |
194 void GCMProfileService::Shutdown() { | 186 void GCMProfileService::Shutdown() { |
195 #if !defined(OS_ANDROID) | 187 #if !defined(OS_ANDROID) |
196 identity_observer_.reset(); | 188 identity_observer_.reset(); |
197 #endif // !defined(OS_ANDROID) | 189 #endif // !defined(OS_ANDROID) |
198 if (driver_) { | 190 if (driver_) { |
199 driver_->Shutdown(); | 191 driver_->Shutdown(); |
200 driver_.reset(); | 192 driver_.reset(); |
201 } | 193 } |
202 } | 194 } |
203 | 195 |
204 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 196 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
205 driver_.reset(driver); | 197 driver_.reset(driver); |
206 #if !defined(OS_ANDROID) | 198 #if !defined(OS_ANDROID) |
207 if (identity_observer_) | 199 if (identity_observer_) |
208 identity_observer_.reset(new IdentityObserver(profile_, driver)); | 200 identity_observer_.reset(new IdentityObserver(profile_, driver)); |
209 #endif // !defined(OS_ANDROID) | 201 #endif // !defined(OS_ANDROID) |
210 } | 202 } |
211 | 203 |
| 204 gcm::FakeGCMProfileService* gcm::GCMProfileService::AsFakeGCMProfileService() { |
| 205 return NULL; |
| 206 } |
| 207 |
212 } // namespace gcm | 208 } // namespace gcm |
OLD | NEW |