| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/webui/media/webrtc_logs_ui.h" | 5 #include "chrome/browser/ui/webui/media/webrtc_logs_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" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 void WebRtcLogsDOMHandler::UpdateUI() { | 143 void WebRtcLogsDOMHandler::UpdateUI() { |
| 144 std::vector<UploadList::UploadInfo> uploads; | 144 std::vector<UploadList::UploadInfo> uploads; |
| 145 upload_list_->GetUploads(50, &uploads); | 145 upload_list_->GetUploads(50, &uploads); |
| 146 | 146 |
| 147 base::ListValue upload_list; | 147 base::ListValue upload_list; |
| 148 for (std::vector<UploadList::UploadInfo>::iterator i = uploads.begin(); | 148 for (std::vector<UploadList::UploadInfo>::iterator i = uploads.begin(); |
| 149 i != uploads.end(); | 149 i != uploads.end(); |
| 150 ++i) { | 150 ++i) { |
| 151 base::DictionaryValue* upload = new base::DictionaryValue(); | 151 scoped_ptr<base::DictionaryValue> upload(new base::DictionaryValue()); |
| 152 upload->SetString("id", i->id); | 152 upload->SetString("id", i->upload_id); |
| 153 | 153 |
| 154 base::string16 value_w; | 154 base::string16 value_w; |
| 155 if (!i->time.is_null()) | 155 if (!i->upload_time.is_null()) |
| 156 value_w = base::TimeFormatFriendlyDateAndTime(i->time); | 156 value_w = base::TimeFormatFriendlyDateAndTime(i->upload_time); |
| 157 upload->SetString("upload_time", value_w); | 157 upload->SetString("upload_time", value_w); |
| 158 | 158 |
| 159 value_w.clear(); | |
| 160 double seconds_since_epoch; | |
| 161 if (base::StringToDouble(i->local_id, &seconds_since_epoch)) { | |
| 162 base::Time capture_time = base::Time::FromDoubleT(seconds_since_epoch); | |
| 163 value_w = base::TimeFormatFriendlyDateAndTime(capture_time); | |
| 164 } | |
| 165 upload->SetString("capture_time", value_w); | |
| 166 | |
| 167 base::FilePath::StringType value; | 159 base::FilePath::StringType value; |
| 168 if (!i->local_id.empty()) | 160 if (!i->local_id.empty()) |
| 169 value = log_dir_.AppendASCII(i->local_id) | 161 value = log_dir_.AppendASCII(i->local_id) |
| 170 .AddExtension(FILE_PATH_LITERAL(".gz")).value(); | 162 .AddExtension(FILE_PATH_LITERAL(".gz")).value(); |
| 171 upload->SetString("local_file", value); | 163 upload->SetString("local_file", value); |
| 172 | 164 |
| 173 upload_list.Append(upload); | 165 // In october 2015, capture time was added to the log list, previously the |
| 166 // local ID was used as capture time. The local ID has however changed so |
| 167 // that it might not be a time. We fall back on the local ID if it traslates |
| 168 // to a time within reasonable bounds, otherwise we fall back on the upload |
| 169 // time. |
| 170 // TODO(grunell): Use |capture_time| only. |
| 171 if (!i->capture_time.is_null()) { |
| 172 value_w = base::TimeFormatFriendlyDateAndTime(i->capture_time); |
| 173 } else { |
| 174 // Fall back on local ID as time. We need to check that it's within |
| 175 // resonable bounds, since the ID may not represent time. Check between |
| 176 // 2012 when the feature was introduced and now. |
| 177 double seconds_since_epoch; |
| 178 if (base::StringToDouble(i->local_id, &seconds_since_epoch)) { |
| 179 base::Time capture_time = base::Time::FromDoubleT(seconds_since_epoch); |
| 180 base::Time::Exploded lower_limit = {2012, 1, 0, 1, 0, 0, 0, 0}; |
| 181 if (capture_time > base::Time::FromUTCExploded(lower_limit) && |
| 182 capture_time < base::Time::Now()) { |
| 183 value_w = base::TimeFormatFriendlyDateAndTime(capture_time); |
| 184 } |
| 185 } |
| 186 } |
| 187 // If we haven't set |value_w| above, we fall back on the upload time, which |
| 188 // was already in the variable. |
| 189 upload->SetString("capture_time", value_w); |
| 190 |
| 191 upload_list.Append(upload.Pass()); |
| 174 } | 192 } |
| 175 | 193 |
| 176 base::StringValue version(version_info::GetVersionNumber()); | 194 base::StringValue version(version_info::GetVersionNumber()); |
| 177 | 195 |
| 178 web_ui()->CallJavascriptFunction("updateWebRtcLogsList", upload_list, | 196 web_ui()->CallJavascriptFunction("updateWebRtcLogsList", upload_list, |
| 179 version); | 197 version); |
| 180 } | 198 } |
| 181 | 199 |
| 182 } // namespace | 200 } // namespace |
| 183 | 201 |
| 184 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 185 // | 203 // |
| 186 // WebRtcLogsUI | 204 // WebRtcLogsUI |
| 187 // | 205 // |
| 188 /////////////////////////////////////////////////////////////////////////////// | 206 /////////////////////////////////////////////////////////////////////////////// |
| 189 | 207 |
| 190 WebRtcLogsUI::WebRtcLogsUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 208 WebRtcLogsUI::WebRtcLogsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 191 Profile* profile = Profile::FromWebUI(web_ui); | 209 Profile* profile = Profile::FromWebUI(web_ui); |
| 192 web_ui->AddMessageHandler(new WebRtcLogsDOMHandler(profile)); | 210 web_ui->AddMessageHandler(new WebRtcLogsDOMHandler(profile)); |
| 193 | 211 |
| 194 // Set up the chrome://webrtc-logs/ source. | 212 // Set up the chrome://webrtc-logs/ source. |
| 195 content::WebUIDataSource::Add(profile, CreateWebRtcLogsUIHTMLSource()); | 213 content::WebUIDataSource::Add(profile, CreateWebRtcLogsUIHTMLSource()); |
| 196 } | 214 } |
| OLD | NEW |