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..405df0fabbb7aedd3d16b8e229ad8b0c94d5d318 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,68 @@ WebRtcLogUploader::~WebRtcLogUploader() { |
void WebRtcLogUploader::OnURLFetchComplete( |
const net::URLFetcher* source) { |
+ // Append 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. |
+ |
+ int response_code = source->GetResponseCode(); |
+ std::string response_string; |
+ if (response_code != 200 || |
+ !source->GetResponseAsString(&response_string)) { |
+ 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|. |
+ std::vector<std::string> log_entries; |
+ base::SplitStringAlongWhitespace(contents, &log_entries); |
+ if (log_entries.size() >= kLogListLimitLines) { |
+ std::string& new_first_entry = |
+ log_entries[log_entries.size() - kLogListLimitLines + 1]; |
+ size_t new_first_entry_pos = contents.find(new_first_entry); |
tommi (sloooow) - chröme
2013/06/27 08:45:40
Is this guaranteed to be correct?
What if kLogLis
Henrik Grunell
2013/06/27 11:56:22
The lines will not contain other whitespaces than
|
+ contents.erase(0, new_first_entry_pos); |
+ } |
+ |
+ // Write the Unix time and report ID to the log list file. The response in |
+ // |response_string| contains the report ID. |
+ base::Time time_now = base::Time::Now(); |
+ contents += base::DoubleToString(time_now.ToDoubleT()) + |
+ "," + response_string + '\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); |
+ DCHECK(ret); |
tommi (sloooow) - chröme
2013/06/27 08:45:40
FYI - there is also DPCHECK which will print out a
Henrik Grunell
2013/06/27 11:56:22
OK, good to know. Changed.
|
+ |
+ ret = base::ClosePlatformFile(logs_uploaded_file); |
+ DCHECK(ret); |
tommi (sloooow) - chröme
2013/06/27 08:45:40
you could use that here too
Henrik Grunell
2013/06/27 11:56:22
Done.
|
} |
void WebRtcLogUploader::OnURLFetchUploadProgress( |