Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing zea's comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void Reset(); 167 void Reset();
168 void Load(const base::WeakPtr<GCMProfileService>& service); 168 void Load(const base::WeakPtr<GCMProfileService>& service);
169 void Stop(); 169 void Stop();
170 void CheckOut(); 170 void CheckOut();
171 void Register(const std::string& app_id, 171 void Register(const std::string& app_id,
172 const std::vector<std::string>& sender_ids); 172 const std::vector<std::string>& sender_ids);
173 void Unregister(const std::string& app_id); 173 void Unregister(const std::string& app_id);
174 void Send(const std::string& app_id, 174 void Send(const std::string& app_id,
175 const std::string& receiver_id, 175 const std::string& receiver_id,
176 const GCMClient::OutgoingMessage& message); 176 const GCMClient::OutgoingMessage& message);
177 void RequestGCMStatistics(); 177 void RequestGCMStatistics(bool clear_logs);
178 void SetGCMRecording(bool recording);
178 179
179 // For testing purpose. Can be called from UI thread. Use with care. 180 // For testing purpose. Can be called from UI thread. Use with care.
180 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 181 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
181 182
182 private: 183 private:
183 friend class base::RefCountedThreadSafe<IOWorker>; 184 friend class base::RefCountedThreadSafe<IOWorker>;
184 virtual ~IOWorker(); 185 virtual ~IOWorker();
185 186
186 base::WeakPtr<GCMProfileService> service_; 187 base::WeakPtr<GCMProfileService> service_;
187 188
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 364
364 void GCMProfileService::IOWorker::Send( 365 void GCMProfileService::IOWorker::Send(
365 const std::string& app_id, 366 const std::string& app_id,
366 const std::string& receiver_id, 367 const std::string& receiver_id,
367 const GCMClient::OutgoingMessage& message) { 368 const GCMClient::OutgoingMessage& message) {
368 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
369 370
370 gcm_client_->Send(app_id, receiver_id, message); 371 gcm_client_->Send(app_id, receiver_id, message);
371 } 372 }
372 373
373 void GCMProfileService::IOWorker::RequestGCMStatistics() { 374 void GCMProfileService::IOWorker::RequestGCMStatistics(bool clear_logs) {
374 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 375 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
375 gcm::GCMClient::GCMStatistics stats; 376 gcm::GCMClient::GCMStatistics stats;
376 377
377 if (gcm_client_.get()) { 378 if (gcm_client_.get()) {
379 if (clear_logs)
380 gcm_client_->ClearActivityLogs();
381 stats = gcm_client_->GetStatistics();
378 stats.gcm_client_created = true; 382 stats.gcm_client_created = true;
fgorski 2014/03/29 05:09:29 with all of the stuff that is happening inside of
juyik 2014/03/31 22:19:23 Done.
379 stats = gcm_client_->GetStatistics();
380 } 383 }
381 384
382 content::BrowserThread::PostTask( 385 content::BrowserThread::PostTask(
386 content::BrowserThread::UI,
387 FROM_HERE,
388 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished,
389 service_,
390 stats));
391 }
392
393 void GCMProfileService::IOWorker::SetGCMRecording(bool recording) {
394 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
395 gcm::GCMClient::GCMStatistics stats;
396
397 if (gcm_client_.get()) {
398 gcm_client_->SetRecording(recording);
399 stats = gcm_client_->GetStatistics();
400 stats.gcm_client_created = true;
401 }
402
403 content::BrowserThread::PostTask(
383 content::BrowserThread::UI, 404 content::BrowserThread::UI,
384 FROM_HERE, 405 FROM_HERE,
385 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished, 406 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished,
386 service_, 407 service_,
387 stats)); 408 stats));
388 } 409 }
389 410
390 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) { 411 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) {
391 switch (state) { 412 switch (state) {
392 case GCMProfileService::ALWAYS_ENABLED: 413 case GCMProfileService::ALWAYS_ENABLED:
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 701
681 std::string GCMProfileService::SignedInUserName() const { 702 std::string GCMProfileService::SignedInUserName() const {
682 return username_; 703 return username_;
683 } 704 }
684 705
685 bool GCMProfileService::IsGCMClientReady() const { 706 bool GCMProfileService::IsGCMClientReady() const {
686 return gcm_client_ready_; 707 return gcm_client_ready_;
687 } 708 }
688 709
689 void GCMProfileService::RequestGCMStatistics( 710 void GCMProfileService::RequestGCMStatistics(
690 RequestGCMStatisticsCallback callback) { 711 RequestGCMStatisticsCallback callback, bool clear_logs) {
691 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 712 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
692 DCHECK(!callback.is_null()); 713 DCHECK(!callback.is_null());
693 714
694 request_gcm_statistics_callback_ = callback; 715 request_gcm_statistics_callback_ = callback;
695 content::BrowserThread::PostTask( 716 content::BrowserThread::PostTask(
696 content::BrowserThread::IO, 717 content::BrowserThread::IO,
697 FROM_HERE, 718 FROM_HERE,
698 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics, 719 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics,
699 io_worker_)); 720 io_worker_,
721 clear_logs));
722 }
723
724 void GCMProfileService::SetGCMRecording(
725 RequestGCMStatisticsCallback callback, bool recording) {
726 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
727
728 request_gcm_statistics_callback_ = callback;
729 content::BrowserThread::PostTask(
730 content::BrowserThread::IO,
731 FROM_HERE,
732 base::Bind(&GCMProfileService::IOWorker::SetGCMRecording,
733 io_worker_,
734 recording));
700 } 735 }
701 736
702 void GCMProfileService::Observe(int type, 737 void GCMProfileService::Observe(int type,
703 const content::NotificationSource& source, 738 const content::NotificationSource& source,
704 const content::NotificationDetails& details) { 739 const content::NotificationDetails& details) {
705 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 740 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
706 741
707 switch (type) { 742 switch (type) {
708 case chrome::NOTIFICATION_PROFILE_DESTROYED: 743 case chrome::NOTIFICATION_PROFILE_DESTROYED:
709 ResetGCMClient(); 744 ResetGCMClient();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 933
899 GCMAppHandler* GCMProfileService::GetAppHandler(const std::string& app_id) { 934 GCMAppHandler* GCMProfileService::GetAppHandler(const std::string& app_id) {
900 std::map<std::string, GCMAppHandler*>::const_iterator iter = 935 std::map<std::string, GCMAppHandler*>::const_iterator iter =
901 app_handlers_.find(app_id); 936 app_handlers_.find(app_id);
902 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; 937 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second;
903 } 938 }
904 939
905 void GCMProfileService::RequestGCMStatisticsFinished( 940 void GCMProfileService::RequestGCMStatisticsFinished(
906 GCMClient::GCMStatistics stats) { 941 GCMClient::GCMStatistics stats) {
907 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 942 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
908
909 request_gcm_statistics_callback_.Run(stats); 943 request_gcm_statistics_callback_.Run(stats);
910 } 944 }
911 945
912 } // namespace gcm 946 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698