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

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: . Created 6 years, 9 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
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
17 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #if !defined(OS_ANDROID) 20 #if !defined(OS_ANDROID)
20 #include "chrome/browser/extensions/api/gcm/gcm_api.h" 21 #include "chrome/browser/extensions/api/gcm/gcm_api.h"
21 #endif 22 #endif
22 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/state_store.h" 24 #include "chrome/browser/extensions/state_store.h"
24 #include "chrome/browser/services/gcm/gcm_client_factory.h" 25 #include "chrome/browser/services/gcm/gcm_client_factory.h"
25 #include "chrome/browser/services/gcm/gcm_event_router.h" 26 #include "chrome/browser/services/gcm/gcm_event_router.h"
26 #include "chrome/browser/signin/profile_oauth2_token_service.h" 27 #include "chrome/browser/signin/profile_oauth2_token_service.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void Reset(); 268 void Reset();
268 void Load(const base::WeakPtr<GCMProfileService>& service); 269 void Load(const base::WeakPtr<GCMProfileService>& service);
269 void Stop(); 270 void Stop();
270 void CheckOut(); 271 void CheckOut();
271 void Register(const std::string& app_id, 272 void Register(const std::string& app_id,
272 const std::vector<std::string>& sender_ids); 273 const std::vector<std::string>& sender_ids);
273 void Unregister(const std::string& app_id); 274 void Unregister(const std::string& app_id);
274 void Send(const std::string& app_id, 275 void Send(const std::string& app_id,
275 const std::string& receiver_id, 276 const std::string& receiver_id,
276 const GCMClient::OutgoingMessage& message); 277 const GCMClient::OutgoingMessage& message);
277 void RequestGCMStatistics(); 278 void RequestGCMStatistics(bool clear_logs);
279 void SetGCMRecording(bool recording);
278 280
279 // For testing purpose. Can be called from UI thread. Use with care. 281 // For testing purpose. Can be called from UI thread. Use with care.
280 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 282 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
281 283
282 private: 284 private:
283 friend class base::RefCountedThreadSafe<IOWorker>; 285 friend class base::RefCountedThreadSafe<IOWorker>;
284 virtual ~IOWorker(); 286 virtual ~IOWorker();
285 287
286 base::WeakPtr<GCMProfileService> service_; 288 base::WeakPtr<GCMProfileService> service_;
287 289
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 459
458 void GCMProfileService::IOWorker::Send( 460 void GCMProfileService::IOWorker::Send(
459 const std::string& app_id, 461 const std::string& app_id,
460 const std::string& receiver_id, 462 const std::string& receiver_id,
461 const GCMClient::OutgoingMessage& message) { 463 const GCMClient::OutgoingMessage& message) {
462 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 464 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
463 465
464 gcm_client_->Send(app_id, receiver_id, message); 466 gcm_client_->Send(app_id, receiver_id, message);
465 } 467 }
466 468
467 void GCMProfileService::IOWorker::RequestGCMStatistics() { 469 void GCMProfileService::IOWorker::RequestGCMStatistics(bool clear_logs) {
468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 470 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
469 gcm::GCMClient::GCMStatistics stats; 471 gcm::GCMClient::GCMStatistics stats;
470 472
471 if (gcm_client_.get()) { 473 if (gcm_client_.get()) {
474 if (clear_logs)
475 gcm_client_->ClearActivityLogs();
476 stats = gcm_client_->GetStatistics();
472 stats.gcm_client_created = true; 477 stats.gcm_client_created = true;
473 stats = gcm_client_->GetStatistics();
474 } 478 }
475 479
476 content::BrowserThread::PostTask( 480 content::BrowserThread::PostTask(
481 content::BrowserThread::UI,
482 FROM_HERE,
483 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished,
484 service_,
485 stats));
486 }
487
488 void GCMProfileService::IOWorker::SetGCMRecording(bool recording) {
489 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
490 gcm::GCMClient::GCMStatistics stats;
491
492 if (gcm_client_.get()) {
493 gcm_client_->SetRecording(recording);
494 stats = gcm_client_->GetStatistics();
495 stats.gcm_client_created = true;
496 }
497
498 content::BrowserThread::PostTask(
477 content::BrowserThread::UI, 499 content::BrowserThread::UI,
478 FROM_HERE, 500 FROM_HERE,
479 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished, 501 base::Bind(&GCMProfileService::RequestGCMStatisticsFinished,
480 service_, 502 service_,
481 stats)); 503 stats));
482 } 504 }
483 505
484 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) { 506 std::string GCMProfileService::GetGCMEnabledStateString(GCMEnabledState state) {
485 switch (state) { 507 switch (state) {
486 case GCMProfileService::ALWAYS_ENABLED: 508 case GCMProfileService::ALWAYS_ENABLED:
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 805
784 std::string GCMProfileService::SignedInUserName() const { 806 std::string GCMProfileService::SignedInUserName() const {
785 return username_; 807 return username_;
786 } 808 }
787 809
788 bool GCMProfileService::IsGCMClientReady() const { 810 bool GCMProfileService::IsGCMClientReady() const {
789 return gcm_client_ready_; 811 return gcm_client_ready_;
790 } 812 }
791 813
792 void GCMProfileService::RequestGCMStatistics( 814 void GCMProfileService::RequestGCMStatistics(
793 RequestGCMStatisticsCallback callback) { 815 RequestGCMStatisticsCallback callback, bool clear_logs) {
794 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 816 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
795 DCHECK(!callback.is_null()); 817 DCHECK(!callback.is_null());
796 818
797 request_gcm_statistics_callback_ = callback; 819 request_gcm_statistics_callback_ = callback;
798 content::BrowserThread::PostTask( 820 content::BrowserThread::PostTask(
799 content::BrowserThread::IO, 821 content::BrowserThread::IO,
800 FROM_HERE, 822 FROM_HERE,
801 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics, 823 base::Bind(&GCMProfileService::IOWorker::RequestGCMStatistics,
802 io_worker_)); 824 io_worker_,
825 clear_logs));
826 }
827
828 void GCMProfileService::SetGCMRecording(
829 RequestGCMStatisticsCallback callback, bool recording) {
830 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
831
832 request_gcm_statistics_callback_ = callback;
833 content::BrowserThread::PostTask(
834 content::BrowserThread::IO,
835 FROM_HERE,
836 base::Bind(&GCMProfileService::IOWorker::SetGCMRecording,
837 io_worker_,
838 recording));
803 } 839 }
804 840
805 void GCMProfileService::Observe(int type, 841 void GCMProfileService::Observe(int type,
806 const content::NotificationSource& source, 842 const content::NotificationSource& source,
807 const content::NotificationDetails& details) { 843 const content::NotificationDetails& details) {
808 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 844 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
809 845
810 switch (type) { 846 switch (type) {
811 case chrome::NOTIFICATION_PROFILE_DESTROYED: 847 case chrome::NOTIFICATION_PROFILE_DESTROYED:
812 ResetGCMClient(); 848 ResetGCMClient();
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 registration_info->sender_ids.push_back(sender); 1221 registration_info->sender_ids.push_back(sender);
1186 } 1222 }
1187 1223
1188 return true; 1224 return true;
1189 } 1225 }
1190 1226
1191 void GCMProfileService::RequestGCMStatisticsFinished( 1227 void GCMProfileService::RequestGCMStatisticsFinished(
1192 GCMClient::GCMStatistics stats) { 1228 GCMClient::GCMStatistics stats) {
1193 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 1229 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
1194 1230
1231 std::vector<std::string> ids;
1232 for (RegistrationInfoMap::const_iterator it = registration_info_map_.begin();
1233 it != registration_info_map_.end(); ++it) {
1234 ids.push_back(it->first);
1235 }
1236 stats.app_ids_cached = JoinString(ids, ',');;
1195 request_gcm_statistics_callback_.Run(stats); 1237 request_gcm_statistics_callback_.Run(stats);
1196 } 1238 }
1197 1239
1198 // static 1240 // static
1199 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { 1241 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() {
1200 return kRegistrationKey; 1242 return kRegistrationKey;
1201 } 1243 }
1202 1244
1203 } // namespace gcm 1245 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698