Chromium Code Reviews| 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 "chrome/browser/services/gcm/gcm_service.h" | 5 #include "chrome/browser/services/gcm/gcm_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 | 465 |
| 466 void GCMService::RemoveAppHandler(const std::string& app_id) { | 466 void GCMService::RemoveAppHandler(const std::string& app_id) { |
| 467 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 467 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 468 DCHECK(!app_id.empty()); | 468 DCHECK(!app_id.empty()); |
| 469 | 469 |
| 470 app_handlers_.erase(app_id); | 470 app_handlers_.erase(app_id); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void GCMService::Register(const std::string& app_id, | 473 void GCMService::Register(const std::string& app_id, |
| 474 const std::vector<std::string>& sender_ids, | 474 const std::vector<std::string>& sender_ids, |
| 475 RegisterCallback callback) { | 475 const RegisterCallback& callback) { |
| 476 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 476 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 477 DCHECK(!app_id.empty()); | 477 DCHECK(!app_id.empty()); |
| 478 DCHECK(!sender_ids.empty()); | 478 DCHECK(!sender_ids.empty()); |
| 479 DCHECK(!callback.is_null()); | 479 DCHECK(!callback.is_null()); |
| 480 | 480 |
| 481 GCMClient::Result result = EnsureAppReady(app_id); | 481 GCMClient::Result result = EnsureAppReady(app_id); |
| 482 if (result != GCMClient::SUCCESS) { | 482 if (result != GCMClient::SUCCESS) { |
| 483 callback.Run(std::string(), result); | 483 callback.Run(std::string(), result); |
| 484 return; | 484 return; |
| 485 } | 485 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 content::BrowserThread::PostTask( | 521 content::BrowserThread::PostTask( |
| 522 content::BrowserThread::IO, | 522 content::BrowserThread::IO, |
| 523 FROM_HERE, | 523 FROM_HERE, |
| 524 base::Bind(&GCMService::IOWorker::Register, | 524 base::Bind(&GCMService::IOWorker::Register, |
| 525 base::Unretained(io_worker_.get()), | 525 base::Unretained(io_worker_.get()), |
| 526 app_id, | 526 app_id, |
| 527 normalized_sender_ids)); | 527 normalized_sender_ids)); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void GCMService::Unregister(const std::string& app_id, | 530 void GCMService::Unregister(const std::string& app_id, |
| 531 UnregisterCallback callback) { | 531 const UnregisterCallback& callback) { |
| 532 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 532 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 533 DCHECK(!app_id.empty()); | 533 DCHECK(!app_id.empty()); |
| 534 DCHECK(!callback.is_null()); | 534 DCHECK(!callback.is_null()); |
| 535 | 535 |
| 536 GCMClient::Result result = EnsureAppReady(app_id); | 536 GCMClient::Result result = EnsureAppReady(app_id); |
| 537 if (result != GCMClient::SUCCESS) { | 537 if (result != GCMClient::SUCCESS) { |
| 538 callback.Run(result); | 538 callback.Run(result); |
| 539 return; | 539 return; |
| 540 } | 540 } |
| 541 | 541 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 568 content::BrowserThread::IO, | 568 content::BrowserThread::IO, |
| 569 FROM_HERE, | 569 FROM_HERE, |
| 570 base::Bind(&GCMService::IOWorker::Unregister, | 570 base::Bind(&GCMService::IOWorker::Unregister, |
| 571 base::Unretained(io_worker_.get()), | 571 base::Unretained(io_worker_.get()), |
| 572 app_id)); | 572 app_id)); |
| 573 } | 573 } |
| 574 | 574 |
| 575 void GCMService::Send(const std::string& app_id, | 575 void GCMService::Send(const std::string& app_id, |
| 576 const std::string& receiver_id, | 576 const std::string& receiver_id, |
| 577 const GCMClient::OutgoingMessage& message, | 577 const GCMClient::OutgoingMessage& message, |
| 578 SendCallback callback) { | 578 const SendCallback& callback) { |
| 579 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 579 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 580 DCHECK(!app_id.empty()); | 580 DCHECK(!app_id.empty()); |
| 581 DCHECK(!receiver_id.empty()); | 581 DCHECK(!receiver_id.empty()); |
| 582 DCHECK(!callback.is_null()); | 582 DCHECK(!callback.is_null()); |
| 583 | 583 |
| 584 GCMClient::Result result = EnsureAppReady(app_id); | 584 GCMClient::Result result = EnsureAppReady(app_id); |
| 585 if (result != GCMClient::SUCCESS) { | 585 if (result != GCMClient::SUCCESS) { |
| 586 callback.Run(std::string(), result); | 586 callback.Run(std::string(), result); |
| 587 return; | 587 return; |
| 588 } | 588 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 bool GCMService::IsStarted() const { | 631 bool GCMService::IsStarted() const { |
| 632 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 632 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 633 return !account_id_.empty(); | 633 return !account_id_.empty(); |
| 634 } | 634 } |
| 635 | 635 |
| 636 bool GCMService::IsGCMClientReady() const { | 636 bool GCMService::IsGCMClientReady() const { |
| 637 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 637 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 638 return gcm_client_ready_; | 638 return gcm_client_ready_; |
| 639 } | 639 } |
| 640 | 640 |
| 641 void GCMService::GetGCMStatistics(GetGCMStatisticsCallback callback, | 641 void GCMService::GetGCMStatistics(const GetGCMStatisticsCallback& callback, |
| 642 bool clear_logs) { | 642 bool clear_logs) { |
| 643 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 643 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 644 DCHECK(!callback.is_null()); | 644 DCHECK(!callback.is_null()); |
| 645 | 645 |
| 646 request_gcm_statistics_callback_ = callback; | 646 request_gcm_statistics_callback_ = callback; |
| 647 content::BrowserThread::PostTask( | 647 content::BrowserThread::PostTask( |
| 648 content::BrowserThread::IO, | 648 content::BrowserThread::IO, |
| 649 FROM_HERE, | 649 FROM_HERE, |
| 650 base::Bind(&GCMService::IOWorker::GetGCMStatistics, | 650 base::Bind(&GCMService::IOWorker::GetGCMStatistics, |
| 651 base::Unretained(io_worker_.get()), | 651 base::Unretained(io_worker_.get()), |
| 652 clear_logs)); | 652 clear_logs)); |
| 653 } | 653 } |
| 654 | 654 |
| 655 void GCMService::SetGCMRecording(GetGCMStatisticsCallback callback, | 655 void GCMService::SetGCMRecording(const GetGCMStatisticsCallback& callback, |
| 656 bool recording) { | 656 bool recording) { |
| 657 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 657 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 658 | 658 |
| 659 request_gcm_statistics_callback_ = callback; | 659 request_gcm_statistics_callback_ = callback; |
| 660 content::BrowserThread::PostTask( | 660 content::BrowserThread::PostTask( |
| 661 content::BrowserThread::IO, | 661 content::BrowserThread::IO, |
| 662 FROM_HERE, | 662 FROM_HERE, |
| 663 base::Bind(&GCMService::IOWorker::SetGCMRecording, | 663 base::Bind(&GCMService::IOWorker::SetGCMRecording, |
| 664 base::Unretained(io_worker_.get()), | 664 base::Unretained(io_worker_.get()), |
| 665 recording)); | 665 recording)); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 } | 842 } |
| 843 | 843 |
| 844 GCMAppHandler* GCMService::GetAppHandler(const std::string& app_id) { | 844 GCMAppHandler* GCMService::GetAppHandler(const std::string& app_id) { |
| 845 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 845 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 846 | 846 |
| 847 std::map<std::string, GCMAppHandler*>::const_iterator iter = | 847 std::map<std::string, GCMAppHandler*>::const_iterator iter = |
| 848 app_handlers_.find(app_id); | 848 app_handlers_.find(app_id); |
| 849 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; | 849 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; |
| 850 } | 850 } |
| 851 | 851 |
| 852 void GCMService::GetGCMStatisticsFinished( | 852 void GCMService::GetGCMStatisticsFinished(GCMClient::GCMStatistics stats) { |
| 853 GCMClient::GCMStatistics stats) { | |
| 854 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 853 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 855 request_gcm_statistics_callback_.Run(stats); | 854 if (!request_gcm_statistics_callback_.is_null()) |
| 855 request_gcm_statistics_callback_.Run(stats); | |
| 856 } | 856 } |
|
Roger Tawa OOO till Jul 10th
2014/05/09 11:51:00
A lot of crashes were reported yesterday about thi
Ilya Sherman
2014/05/09 20:16:56
Sorry, this was an unrelated change that I acciden
| |
| 857 | 857 |
| 858 } // namespace gcm | 858 } // namespace gcm |
| OLD | NEW |