| 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/ui/webui/gcm_internals_ui.h" | 5 #include "chrome/browser/ui/webui/gcm_internals_ui.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/format_macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "base/strings/string_util.h" | |
| 15 #include "base/strings/stringprintf.h" | |
| 16 #include "base/values.h" | 12 #include "base/values.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 19 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 20 #include "components/gcm_driver/gcm_client.h" | 16 #include "components/gcm_driver/gcm_client.h" |
| 21 #include "components/gcm_driver/gcm_driver.h" | 17 #include "components/gcm_driver/gcm_driver.h" |
| 22 #include "components/gcm_driver/gcm_internals_constants.h" | 18 #include "components/gcm_driver/gcm_internals_constants.h" |
| 19 #include "components/gcm_driver/gcm_internals_helper.h" |
| 23 #include "components/gcm_driver/gcm_profile_service.h" | 20 #include "components/gcm_driver/gcm_profile_service.h" |
| 24 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
| 25 #include "content/public/browser/web_ui_controller.h" | 22 #include "content/public/browser/web_ui_controller.h" |
| 26 #include "content/public/browser/web_ui_data_source.h" | 23 #include "content/public/browser/web_ui_data_source.h" |
| 27 #include "content/public/browser/web_ui_message_handler.h" | 24 #include "content/public/browser/web_ui_message_handler.h" |
| 28 #include "grit/components_resources.h" | 25 #include "grit/components_resources.h" |
| 29 | 26 |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| 32 void SetCheckinInfo( | |
| 33 const std::vector<gcm::CheckinActivity>& checkins, | |
| 34 base::ListValue* checkin_info) { | |
| 35 std::vector<gcm::CheckinActivity>::const_iterator it = checkins.begin(); | |
| 36 for (; it < checkins.end(); ++it) { | |
| 37 base::ListValue* row = new base::ListValue(); | |
| 38 checkin_info->Append(row); | |
| 39 | |
| 40 row->AppendDouble(it->time.ToJsTime()); | |
| 41 row->AppendString(it->event); | |
| 42 row->AppendString(it->details); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void SetConnectionInfo( | |
| 47 const std::vector<gcm::ConnectionActivity>& connections, | |
| 48 base::ListValue* connection_info) { | |
| 49 std::vector<gcm::ConnectionActivity>::const_iterator it = connections.begin(); | |
| 50 for (; it < connections.end(); ++it) { | |
| 51 base::ListValue* row = new base::ListValue(); | |
| 52 connection_info->Append(row); | |
| 53 | |
| 54 row->AppendDouble(it->time.ToJsTime()); | |
| 55 row->AppendString(it->event); | |
| 56 row->AppendString(it->details); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void SetRegistrationInfo( | |
| 61 const std::vector<gcm::RegistrationActivity>& registrations, | |
| 62 base::ListValue* registration_info) { | |
| 63 std::vector<gcm::RegistrationActivity>::const_iterator it = | |
| 64 registrations.begin(); | |
| 65 for (; it < registrations.end(); ++it) { | |
| 66 base::ListValue* row = new base::ListValue(); | |
| 67 registration_info->Append(row); | |
| 68 | |
| 69 row->AppendDouble(it->time.ToJsTime()); | |
| 70 row->AppendString(it->app_id); | |
| 71 row->AppendString(it->source); | |
| 72 row->AppendString(it->event); | |
| 73 row->AppendString(it->details); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void SetReceivingInfo( | |
| 78 const std::vector<gcm::ReceivingActivity>& receives, | |
| 79 base::ListValue* receive_info) { | |
| 80 std::vector<gcm::ReceivingActivity>::const_iterator it = receives.begin(); | |
| 81 for (; it < receives.end(); ++it) { | |
| 82 base::ListValue* row = new base::ListValue(); | |
| 83 receive_info->Append(row); | |
| 84 | |
| 85 row->AppendDouble(it->time.ToJsTime()); | |
| 86 row->AppendString(it->app_id); | |
| 87 row->AppendString(it->from); | |
| 88 row->AppendString(base::IntToString(it->message_byte_size)); | |
| 89 row->AppendString(it->event); | |
| 90 row->AppendString(it->details); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void SetSendingInfo( | |
| 95 const std::vector<gcm::SendingActivity>& sends, | |
| 96 base::ListValue* send_info) { | |
| 97 std::vector<gcm::SendingActivity>::const_iterator it = sends.begin(); | |
| 98 for (; it < sends.end(); ++it) { | |
| 99 base::ListValue* row = new base::ListValue(); | |
| 100 send_info->Append(row); | |
| 101 | |
| 102 row->AppendDouble(it->time.ToJsTime()); | |
| 103 row->AppendString(it->app_id); | |
| 104 row->AppendString(it->receiver_id); | |
| 105 row->AppendString(it->message_id); | |
| 106 row->AppendString(it->event); | |
| 107 row->AppendString(it->details); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 // Class acting as a controller of the chrome://gcm-internals WebUI. | 29 // Class acting as a controller of the chrome://gcm-internals WebUI. |
| 112 class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler { | 30 class GcmInternalsUIMessageHandler : public content::WebUIMessageHandler { |
| 113 public: | 31 public: |
| 114 GcmInternalsUIMessageHandler(); | 32 GcmInternalsUIMessageHandler(); |
| 115 ~GcmInternalsUIMessageHandler() override; | 33 ~GcmInternalsUIMessageHandler() override; |
| 116 | 34 |
| 117 // WebUIMessageHandler implementation. | 35 // WebUIMessageHandler implementation. |
| 118 void RegisterMessages() override; | 36 void RegisterMessages() override; |
| 119 | 37 |
| 120 private: | 38 private: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() | 61 GcmInternalsUIMessageHandler::GcmInternalsUIMessageHandler() |
| 144 : weak_ptr_factory_(this) {} | 62 : weak_ptr_factory_(this) {} |
| 145 | 63 |
| 146 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {} | 64 GcmInternalsUIMessageHandler::~GcmInternalsUIMessageHandler() {} |
| 147 | 65 |
| 148 void GcmInternalsUIMessageHandler::ReturnResults( | 66 void GcmInternalsUIMessageHandler::ReturnResults( |
| 149 Profile* profile, | 67 Profile* profile, |
| 150 gcm::GCMProfileService* profile_service, | 68 gcm::GCMProfileService* profile_service, |
| 151 const gcm::GCMClient::GCMStatistics* stats) const { | 69 const gcm::GCMClient::GCMStatistics* stats) const { |
| 152 base::DictionaryValue results; | 70 base::DictionaryValue results; |
| 153 base::DictionaryValue* device_info = new base::DictionaryValue(); | 71 gcm_driver::SetGCMInternalsInfo(stats, profile_service, profile->GetPrefs(), |
| 154 results.Set(gcm_driver::kDeviceInfo, device_info); | 72 &results); |
| 155 | |
| 156 device_info->SetBoolean(gcm_driver::kProfileServiceCreated, | |
| 157 profile_service != NULL); | |
| 158 device_info->SetBoolean( | |
| 159 gcm_driver::kGcmEnabled, | |
| 160 gcm::GCMProfileService::IsGCMEnabled(profile->GetPrefs())); | |
| 161 if (stats) { | |
| 162 results.SetBoolean(gcm_driver::kIsRecording, stats->is_recording); | |
| 163 device_info->SetBoolean(gcm_driver::kGcmClientCreated, | |
| 164 stats->gcm_client_created); | |
| 165 device_info->SetString(gcm_driver::kGcmClientState, | |
| 166 stats->gcm_client_state); | |
| 167 device_info->SetBoolean(gcm_driver::kConnectionClientCreated, | |
| 168 stats->connection_client_created); | |
| 169 device_info->SetString(gcm_driver::kRegisteredAppIds, | |
| 170 base::JoinString(stats->registered_app_ids, ",")); | |
| 171 if (stats->connection_client_created) | |
| 172 device_info->SetString(gcm_driver::kConnectionState, | |
| 173 stats->connection_state); | |
| 174 if (stats->android_id > 0) { | |
| 175 device_info->SetString( | |
| 176 gcm_driver::kAndroidId, | |
| 177 base::StringPrintf("0x%" PRIx64, stats->android_id)); | |
| 178 } | |
| 179 device_info->SetInteger(gcm_driver::kSendQueueSize, stats->send_queue_size); | |
| 180 device_info->SetInteger(gcm_driver::kResendQueueSize, | |
| 181 stats->resend_queue_size); | |
| 182 | |
| 183 if (stats->recorded_activities.checkin_activities.size() > 0) { | |
| 184 base::ListValue* checkin_info = new base::ListValue(); | |
| 185 results.Set(gcm_driver::kCheckinInfo, checkin_info); | |
| 186 SetCheckinInfo(stats->recorded_activities.checkin_activities, | |
| 187 checkin_info); | |
| 188 } | |
| 189 if (stats->recorded_activities.connection_activities.size() > 0) { | |
| 190 base::ListValue* connection_info = new base::ListValue(); | |
| 191 results.Set(gcm_driver::kConnectionInfo, connection_info); | |
| 192 SetConnectionInfo(stats->recorded_activities.connection_activities, | |
| 193 connection_info); | |
| 194 } | |
| 195 if (stats->recorded_activities.registration_activities.size() > 0) { | |
| 196 base::ListValue* registration_info = new base::ListValue(); | |
| 197 results.Set(gcm_driver::kRegistrationInfo, registration_info); | |
| 198 SetRegistrationInfo(stats->recorded_activities.registration_activities, | |
| 199 registration_info); | |
| 200 } | |
| 201 if (stats->recorded_activities.receiving_activities.size() > 0) { | |
| 202 base::ListValue* receive_info = new base::ListValue(); | |
| 203 results.Set(gcm_driver::kReceiveInfo, receive_info); | |
| 204 SetReceivingInfo(stats->recorded_activities.receiving_activities, | |
| 205 receive_info); | |
| 206 } | |
| 207 if (stats->recorded_activities.sending_activities.size() > 0) { | |
| 208 base::ListValue* send_info = new base::ListValue(); | |
| 209 results.Set(gcm_driver::kSendInfo, send_info); | |
| 210 SetSendingInfo(stats->recorded_activities.sending_activities, send_info); | |
| 211 } | |
| 212 } | |
| 213 web_ui()->CallJavascriptFunction(gcm_driver::kSetGcmInternalsInfo, results); | 73 web_ui()->CallJavascriptFunction(gcm_driver::kSetGcmInternalsInfo, results); |
| 214 } | 74 } |
| 215 | 75 |
| 216 void GcmInternalsUIMessageHandler::RequestAllInfo( | 76 void GcmInternalsUIMessageHandler::RequestAllInfo( |
| 217 const base::ListValue* args) { | 77 const base::ListValue* args) { |
| 218 if (args->GetSize() != 1) { | 78 if (args->GetSize() != 1) { |
| 219 NOTREACHED(); | 79 NOTREACHED(); |
| 220 return; | 80 return; |
| 221 } | 81 } |
| 222 bool clear_logs = false; | 82 bool clear_logs = false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 IDR_GCM_DRIVER_GCM_INTERNALS_JS); | 164 IDR_GCM_DRIVER_GCM_INTERNALS_JS); |
| 305 html_source->SetDefaultResource(IDR_GCM_DRIVER_GCM_INTERNALS_HTML); | 165 html_source->SetDefaultResource(IDR_GCM_DRIVER_GCM_INTERNALS_HTML); |
| 306 | 166 |
| 307 Profile* profile = Profile::FromWebUI(web_ui); | 167 Profile* profile = Profile::FromWebUI(web_ui); |
| 308 content::WebUIDataSource::Add(profile, html_source); | 168 content::WebUIDataSource::Add(profile, html_source); |
| 309 | 169 |
| 310 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); | 170 web_ui->AddMessageHandler(new GcmInternalsUIMessageHandler()); |
| 311 } | 171 } |
| 312 | 172 |
| 313 GCMInternalsUI::~GCMInternalsUI() {} | 173 GCMInternalsUI::~GCMInternalsUI() {} |
| OLD | NEW |