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

Unified Diff: components/gcm_driver/gcm_driver_android.cc

Issue 1515153003: Enable chrome://gcm-internals on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/gcm_driver/gcm_driver_android.h ('k') | components/gcm_driver/gcm_driver_desktop.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_driver_android.cc
diff --git a/components/gcm_driver/gcm_driver_android.cc b/components/gcm_driver/gcm_driver_android.cc
index adfd08b63ffcc5750c3491b497e80c61481322a4..f0baa829e5047ecfae3b7ce2839636f25327f829 100644
--- a/components/gcm_driver/gcm_driver_android.cc
+++ b/components/gcm_driver/gcm_driver_android.cc
@@ -25,7 +25,8 @@ namespace gcm {
GCMDriverAndroid::GCMDriverAndroid(
const base::FilePath& store_path,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
- : GCMDriver(store_path, blocking_task_runner) {
+ : GCMDriver(store_path, blocking_task_runner),
+ recorder_(this) {
JNIEnv* env = AttachCurrentThread();
java_ref_.Reset(
Java_GCMDriver_create(env,
@@ -49,6 +50,8 @@ void GCMDriverAndroid::OnRegisterFinished(
GCMClient::Result result = success ? GCMClient::SUCCESS
: GCMClient::UNKNOWN_ERROR;
+ recorder_.RecordRegistrationResponse(app_id, success);
+
RegisterFinished(app_id, registration_id, result);
}
@@ -61,6 +64,8 @@ void GCMDriverAndroid::OnUnregisterFinished(
GCMClient::Result result = success ? GCMClient::SUCCESS
: GCMClient::UNKNOWN_ERROR;
+ recorder_.RecordUnregistrationResponse(app_id, success);
+
UnregisterFinished(app_id, result);
}
@@ -74,6 +79,8 @@ void GCMDriverAndroid::OnMessageReceived(
const JavaParamRef<jobjectArray>& j_data_keys_and_values) {
std::string app_id = ConvertJavaStringToUTF8(env, j_app_id);
+ int message_byte_size = 0;
+
IncomingMessage message;
message.sender_id = ConvertJavaStringToUTF8(env, j_sender_id);
message.collapse_key = ConvertJavaStringToUTF8(env, j_collapse_key);
@@ -84,14 +91,19 @@ void GCMDriverAndroid::OnMessageReceived(
&data_keys_and_values);
for (size_t i = 0; i + 1 < data_keys_and_values.size(); i += 2) {
message.data[data_keys_and_values[i]] = data_keys_and_values[i+1];
+ message_byte_size += data_keys_and_values[i+1].size();
}
// Convert j_raw_data from byte[] to binary std::string.
if (j_raw_data) {
std::vector<uint8_t> raw_data;
JavaByteArrayToByteVector(env, j_raw_data, &raw_data);
message.raw_data.assign(raw_data.begin(), raw_data.end());
+
+ message_byte_size += message.raw_data.size();
}
+ recorder_.RecordDataMessageReceived(app_id, message_byte_size);
+
DispatchMessage(app_id, message);
}
@@ -144,13 +156,29 @@ bool GCMDriverAndroid::IsConnected() const {
void GCMDriverAndroid::GetGCMStatistics(
const GetGCMStatisticsCallback& callback,
- bool clear_logs) {
- NOTIMPLEMENTED();
+ ClearActivityLogs clear_logs) {
+ DCHECK(!callback.is_null());
+
+ get_gcm_statistics_callback_ = callback;
+
+ if (clear_logs == CLEAR_LOGS)
+ recorder_.Clear();
+
+ GCMClient::GCMStatistics stats;
+ stats.is_recording = recorder_.is_recording();
+
+ recorder_.CollectActivities(&stats.recorded_activities);
+
+ callback.Run(stats);
}
void GCMDriverAndroid::SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) {
- NOTIMPLEMENTED();
+ DCHECK(!callback.is_null());
+
+ recorder_.set_is_recording(recording);
+
+ GetGCMStatistics(callback, recording ? KEEP_LOGS : CLEAR_LOGS);
}
void GCMDriverAndroid::SetAccountTokens(
@@ -191,6 +219,12 @@ void GCMDriverAndroid::AddHeartbeatInterval(const std::string& scope,
void GCMDriverAndroid::RemoveHeartbeatInterval(const std::string& scope) {
}
+void GCMDriverAndroid::OnActivityRecorded() {
+ DCHECK(!get_gcm_statistics_callback_.is_null());
+
+ GetGCMStatistics(get_gcm_statistics_callback_, KEEP_LOGS);
+}
+
GCMClient::Result GCMDriverAndroid::EnsureStarted(
GCMClient::StartMode start_mode) {
// TODO(johnme): Maybe we should check if GMS is available?
@@ -201,6 +235,9 @@ void GCMDriverAndroid::RegisterImpl(
const std::string& app_id, const std::vector<std::string>& sender_ids) {
DCHECK_EQ(1u, sender_ids.size());
JNIEnv* env = AttachCurrentThread();
+
+ recorder_.RecordRegistrationSent(app_id);
+
Java_GCMDriver_register(env, java_ref_.obj(),
ConvertUTF8ToJavaString(env, app_id).obj(),
ConvertUTF8ToJavaString(env, sender_ids[0]).obj());
@@ -213,6 +250,9 @@ void GCMDriverAndroid::UnregisterImpl(const std::string& app_id) {
void GCMDriverAndroid::UnregisterWithSenderIdImpl(
const std::string& app_id, const std::string& sender_id) {
JNIEnv* env = AttachCurrentThread();
+
+ recorder_.RecordUnregistrationSent(app_id);
+
Java_GCMDriver_unregister(env, java_ref_.obj(),
ConvertUTF8ToJavaString(env, app_id).obj(),
ConvertUTF8ToJavaString(env, sender_id).obj());
« no previous file with comments | « components/gcm_driver/gcm_driver_android.h ('k') | components/gcm_driver/gcm_driver_desktop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698