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_driver_desktop.h" | 5 #include "components/gcm_driver/gcm_driver_desktop.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 362 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
363 GCMDriver::Shutdown(); | 363 GCMDriver::Shutdown(); |
364 io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); | 364 io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); |
365 } | 365 } |
366 | 366 |
367 void GCMDriverDesktop::OnSignedIn() { | 367 void GCMDriverDesktop::OnSignedIn() { |
368 signed_in_ = true; | 368 signed_in_ = true; |
369 EnsureStarted(); | 369 EnsureStarted(); |
370 } | 370 } |
371 | 371 |
372 void GCMDriverDesktop::OnSignedOut() { | |
373 signed_in_ = false; | |
374 | |
375 // When sign-in enforcement is dropped, we will no longer wipe out the GCM | |
376 // data when the user signs out. | |
377 if (!GCMDriver::IsAllowedForAllUsers()) | |
378 Purge(); | |
379 } | |
380 | |
381 void GCMDriverDesktop::Purge() { | 372 void GCMDriverDesktop::Purge() { |
382 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 373 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
383 | 374 |
| 375 // We still proceed with the check-out logic even if the check-in is not |
| 376 // initiated in the current session. This will make sure that all the |
| 377 // persisted data written previously will get purged. |
| 378 signed_in_ = false; |
384 RemoveCachedData(); | 379 RemoveCachedData(); |
385 | 380 |
386 io_thread_->PostTask(FROM_HERE, | 381 io_thread_->PostTask(FROM_HERE, |
387 base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, | 382 base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, |
388 base::Unretained(io_worker_.get()))); | 383 base::Unretained(io_worker_.get()))); |
389 } | 384 } |
390 | 385 |
391 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, | 386 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, |
392 GCMAppHandler* handler) { | 387 GCMAppHandler* handler) { |
393 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 388 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 if (gcm_started_) | 609 if (gcm_started_) |
615 return GCMClient::SUCCESS; | 610 return GCMClient::SUCCESS; |
616 | 611 |
617 if (!gcm_enabled_) | 612 if (!gcm_enabled_) |
618 return GCMClient::GCM_DISABLED; | 613 return GCMClient::GCM_DISABLED; |
619 | 614 |
620 // Have any app requested the service? | 615 // Have any app requested the service? |
621 if (app_handlers().empty()) | 616 if (app_handlers().empty()) |
622 return GCMClient::UNKNOWN_ERROR; | 617 return GCMClient::UNKNOWN_ERROR; |
623 | 618 |
| 619 // TODO(jianli): To be removed when sign-in enforcement is dropped. |
624 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) | 620 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) |
625 return GCMClient::NOT_SIGNED_IN; | 621 return GCMClient::NOT_SIGNED_IN; |
626 | 622 |
627 DCHECK(!delayed_task_controller_); | 623 DCHECK(!delayed_task_controller_); |
628 delayed_task_controller_.reset(new GCMDelayedTaskController); | 624 delayed_task_controller_.reset(new GCMDelayedTaskController); |
629 | 625 |
630 // Note that we need to pass weak pointer again since the existing weak | 626 // Note that we need to pass weak pointer again since the existing weak |
631 // pointer in IOWorker might have been invalidated when check-out occurs. | 627 // pointer in IOWorker might have been invalidated when check-out occurs. |
632 io_thread_->PostTask( | 628 io_thread_->PostTask( |
633 FROM_HERE, | 629 FROM_HERE, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 | 730 |
735 // Normally request_gcm_statistics_callback_ would not be null. | 731 // Normally request_gcm_statistics_callback_ would not be null. |
736 if (!request_gcm_statistics_callback_.is_null()) | 732 if (!request_gcm_statistics_callback_.is_null()) |
737 request_gcm_statistics_callback_.Run(stats); | 733 request_gcm_statistics_callback_.Run(stats); |
738 else | 734 else |
739 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 735 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
740 } | 736 } |
741 | 737 |
742 } // namespace gcm | 738 } // namespace gcm |
743 | 739 |
OLD | NEW |