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