OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/gcm_driver/gcm_client_impl.h" | 5 #include "components/gcm_driver/gcm_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 // The delay start behavior will be abandoned when Start has been called | 354 // The delay start behavior will be abandoned when Start has been called |
355 // once with IMMEDIATE_START behavior. | 355 // once with IMMEDIATE_START behavior. |
356 if (start_mode == IMMEDIATE_START) | 356 if (start_mode == IMMEDIATE_START) |
357 start_mode_ = IMMEDIATE_START; | 357 start_mode_ = IMMEDIATE_START; |
358 | 358 |
359 // Bail out if the loading is not started or completed. | 359 // Bail out if the loading is not started or completed. |
360 if (state_ != INITIALIZED) | 360 if (state_ != INITIALIZED) |
361 return; | 361 return; |
362 | 362 |
363 // Once the loading is completed, the check-in will be initiated. | 363 // Once the loading is completed, the check-in will be initiated. |
364 gcm_store_->Load(base::Bind(&GCMClientImpl::OnLoadCompleted, | 364 // If we're in lazy start mode, don't create a new store since none is really |
365 weak_ptr_factory_.GetWeakPtr())); | 365 // using GCM functionality yet. |
366 gcm_store_->Load( | |
367 (start_mode == IMMEDIATE_START) ? | |
368 GCMStore::CREATE_NEW_STORE_IF_NOT_EXISTS : | |
369 GCMStore::DO_NOT_CREATE_NEW_STORE, | |
370 base::Bind(&GCMClientImpl::OnLoadCompleted, | |
371 weak_ptr_factory_.GetWeakPtr())); | |
366 state_ = LOADING; | 372 state_ = LOADING; |
367 } | 373 } |
368 | 374 |
369 void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) { | 375 void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) { |
370 DCHECK_EQ(LOADING, state_); | 376 DCHECK_EQ(LOADING, state_); |
371 | 377 |
372 if (!result->success) { | 378 if (!result->success) { |
373 ResetStore(); | 379 if (result->store_does_not_exist) { |
380 // In the case that the store does not exist, setting |state| back to | |
Nicolas Zea
2015/06/15 17:58:37
nit: settings -> set
jianli
2015/06/15 20:50:23
Done.
| |
381 // INITIALIZED such that store loading could be triggered again when | |
382 // Start() is called with IMMEDIATE_START. | |
383 state_ = INITIALIZED; | |
384 } else { | |
385 // Otherwise, destroy the store to try again. | |
386 ResetStore(); | |
387 } | |
374 return; | 388 return; |
375 } | 389 } |
376 gcm_store_reset_ = false; | 390 gcm_store_reset_ = false; |
377 | 391 |
378 device_checkin_info_.android_id = result->device_android_id; | 392 device_checkin_info_.android_id = result->device_android_id; |
379 device_checkin_info_.secret = result->device_security_token; | 393 device_checkin_info_.secret = result->device_security_token; |
380 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; | 394 device_checkin_info_.last_checkin_accounts = result->last_checkin_accounts; |
381 // A case where there were previously no accounts reported with checkin is | 395 // A case where there were previously no accounts reported with checkin is |
382 // considered to be the same as when the list of accounts is empty. It enables | 396 // considered to be the same as when the list of accounts is empty. It enables |
383 // scheduling a periodic checkin for devices with no signed in users | 397 // scheduling a periodic checkin for devices with no signed in users |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1304 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
1291 if (registrations_.empty()) | 1305 if (registrations_.empty()) |
1292 return false; | 1306 return false; |
1293 // Note that account mapper is not counted as a standalone app since it is | 1307 // Note that account mapper is not counted as a standalone app since it is |
1294 // automatically started when other app uses GCM. | 1308 // automatically started when other app uses GCM. |
1295 return registrations_.size() > 1 || | 1309 return registrations_.size() > 1 || |
1296 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1310 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
1297 } | 1311 } |
1298 | 1312 |
1299 } // namespace gcm | 1313 } // namespace gcm |
OLD | NEW |