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

Unified Diff: chrome/browser/media/webrtc_log_uploader.cc

Issue 17589014: Write a log list for uploaded WebRTC logs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer line limitation code. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/webrtc_log_uploader.cc
diff --git a/chrome/browser/media/webrtc_log_uploader.cc b/chrome/browser/media/webrtc_log_uploader.cc
index f88e3821ada4ca34a3d27a3a5bc6fed882169957..9f53cdd3911763b9de5afb291af2d068daa640a6 100644
--- a/chrome/browser/media/webrtc_log_uploader.cc
+++ b/chrome/browser/media/webrtc_log_uploader.cc
@@ -4,9 +4,16 @@
#include "chrome/browser/media/webrtc_log_uploader.h"
+#include "base/files/file_path.h"
#include "base/logging.h"
+#include "base/path_service.h"
#include "base/shared_memory.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
+#include "base/time.h"
+#include "chrome/browser/media/webrtc_log_upload_list.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/partial_circular_buffer.h"
#include "content/public/browser/browser_thread.h"
@@ -24,6 +31,7 @@ namespace {
const int kLogCountLimit = 5;
const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB
+const int kLogListLimitLines = 50;
const char kUploadURL[] = "https://clients2.google.com/cr/report";
const char kUploadContentType[] = "multipart/form-data";
@@ -41,6 +49,77 @@ WebRtcLogUploader::~WebRtcLogUploader() {
void WebRtcLogUploader::OnURLFetchComplete(
const net::URLFetcher* source) {
+ // Append information (time and report ID) about this uploaded log to a log
+ // list file, limited to |kLogListLimitLines| entries. This list is used for
+ // viewing the uploaded logs under chrome://webrtc-logs, see
+ // WebRtcLogUploadList. The list has the format
+ // time,id
+ // time,id
+ // etc.
+ // where each line represents an uploaded log and "time" is Unix time.
+
+ int response_code = source->GetResponseCode();
+ std::string report_id;
+ if (response_code != 200 ||
+ !source->GetResponseAsString(&report_id)) {
+ return;
+ }
+
+ base::FilePath log_dir_path;
+ PathService::Get(chrome::DIR_USER_DATA, &log_dir_path);
+ base::FilePath upload_log_path =
+ log_dir_path.AppendASCII(WebRtcLogUploadList::kWebRtcLogListFilename);
+
+ int flags = base::PLATFORM_FILE_OPEN_ALWAYS |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_WRITE;
+ base::PlatformFileError error = base::PLATFORM_FILE_OK;
+ base::PlatformFile logs_uploaded_file =
+ base::CreatePlatformFile(upload_log_path, flags, NULL, &error);
+ if (error != base::PLATFORM_FILE_OK) {
+ LOG(WARNING) << "Could not open WebRTC log list file.";
+ return;
+ }
+
+ // Read the log list file. Each line is ~35 chars (bytes). Use a buffer size
+ // of 3 times the estimated max size to have a margin.
+ std::string contents(3 * kLogListLimitLines * 35, '\0');
+ size_t read = base::ReadPlatformFileAtCurrentPos(logs_uploaded_file,
+ &contents[0],
+ contents.size());
+ DCHECK_LT(read, contents.size());
+ contents.resize(read);
+
+ // Limit the number of log entries to |kLogListLimitLines| - 1, to make room
+ // for the new entry. Each line including the last ends with a '\n', so hit
+ // n will be before line n-1 (from the back).
+ if (!contents.empty()) {
+ int lf_count = 0;
+ int i = contents.size() - 1;
+ for (; i >= 0 && lf_count < kLogListLimitLines; --i) {
+ if (contents[i] == '\n')
+ ++lf_count;
+ }
+ // + 1 to compensate for the for loop decrease before the conditional check
+ // and + 1 to get the length.
+ contents.erase(0, i + 2);
tommi (sloooow) - chröme 2013/06/28 11:00:05 I think we'll then also need to add a check if i >
Henrik Grunell 2013/06/28 14:12:23 Good point. Added check.
+ }
+
+ // Write the Unix time and report ID to the log list file.
+ base::Time time_now = base::Time::Now();
+ contents += base::DoubleToString(time_now.ToDoubleT()) +
+ "," + report_id + '\n';
+
+ base::SeekPlatformFile(logs_uploaded_file, base::PLATFORM_FILE_FROM_BEGIN, 0);
+ size_t written = base::WritePlatformFileAtCurrentPos(logs_uploaded_file,
+ contents.c_str(),
+ contents.size());
+ DCHECK_EQ(written, contents.size());
+ bool ret = base::TruncatePlatformFile(logs_uploaded_file, written);
+ DPCHECK(ret);
+
+ ret = base::ClosePlatformFile(logs_uploaded_file);
+ DPCHECK(ret);
}
void WebRtcLogUploader::OnURLFetchUploadProgress(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698