Chromium Code Reviews| 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/media/webrtc_log_uploader.h" | 5 #include "chrome/browser/media/webrtc_log_uploader.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | |
| 8 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "base/strings/string_split.h" | |
| 9 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/time.h" | |
| 15 #include "chrome/browser/media/webrtc_log_upload_list.h" | |
| 16 #include "chrome/common/chrome_paths.h" | |
| 10 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 11 #include "chrome/common/partial_circular_buffer.h" | 18 #include "chrome/common/partial_circular_buffer.h" |
| 12 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
| 14 #include "net/base/network_delegate.h" | 21 #include "net/base/network_delegate.h" |
| 15 #include "net/proxy/proxy_config.h" | 22 #include "net/proxy/proxy_config.h" |
| 16 #include "net/proxy/proxy_config_service.h" | 23 #include "net/proxy/proxy_config_service.h" |
| 17 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_context_builder.h" | 26 #include "net/url_request/url_request_context_builder.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "third_party/zlib/zlib.h" | 28 #include "third_party/zlib/zlib.h" |
| 22 | 29 |
| 23 namespace { | 30 namespace { |
| 24 | 31 |
| 25 const int kLogCountLimit = 5; | 32 const int kLogCountLimit = 5; |
| 26 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB | 33 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB |
| 34 const int kLogListLimitLines = 50; | |
| 27 | 35 |
| 28 const char kUploadURL[] = "https://clients2.google.com/cr/report"; | 36 const char kUploadURL[] = "https://clients2.google.com/cr/report"; |
| 29 const char kUploadContentType[] = "multipart/form-data"; | 37 const char kUploadContentType[] = "multipart/form-data"; |
| 30 const char kMultipartBoundary[] = | 38 const char kMultipartBoundary[] = |
| 31 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 39 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
| 32 | 40 |
| 33 } // namespace | 41 } // namespace |
| 34 | 42 |
| 35 WebRtcLogUploader::WebRtcLogUploader() | 43 WebRtcLogUploader::WebRtcLogUploader() |
| 36 : log_count_(0) { | 44 : log_count_(0) { |
| 37 } | 45 } |
| 38 | 46 |
| 39 WebRtcLogUploader::~WebRtcLogUploader() { | 47 WebRtcLogUploader::~WebRtcLogUploader() { |
| 40 } | 48 } |
| 41 | 49 |
| 42 void WebRtcLogUploader::OnURLFetchComplete( | 50 void WebRtcLogUploader::OnURLFetchComplete( |
| 43 const net::URLFetcher* source) { | 51 const net::URLFetcher* source) { |
| 52 int response_code = source->GetResponseCode(); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
In general this code could use with some commentin
Henrik Grunell
2013/06/26 09:45:37
Done, let me know if you think more is needed.
| |
| 53 std::string response_string; | |
| 54 if (response_code != 200 || | |
| 55 !source->GetResponseAsString(&response_string)) { | |
| 56 return; | |
| 57 } | |
| 58 base::FilePath log_dir_path; | |
| 59 PathService::Get(chrome::DIR_USER_DATA, &log_dir_path); | |
| 60 base::FilePath upload_log_path = | |
| 61 log_dir_path.AppendASCII(WebRtcLogUploadList::kWebRtcLogListFilename); | |
| 62 | |
| 63 int flags = base::PLATFORM_FILE_OPEN_ALWAYS | | |
| 64 base::PLATFORM_FILE_READ | | |
| 65 base::PLATFORM_FILE_WRITE; | |
| 66 base::PlatformFileError error = base::PLATFORM_FILE_OK; | |
| 67 base::PlatformFile logs_uploaded_file = | |
| 68 base::CreatePlatformFile(upload_log_path, flags, NULL, &error); | |
| 69 if (error != base::PLATFORM_FILE_OK) | |
| 70 return; | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
log an error?
Henrik Grunell
2013/06/26 09:45:37
Yes, can be good. Done.
| |
| 71 | |
| 72 std::string contents; | |
| 73 char contents_buf[5 * 1024]; | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
instead of having two buffers for the file content
Henrik Grunell
2013/06/26 09:45:37
Yes, done.
| |
| 74 size_t processed = base::ReadPlatformFileAtCurrentPos(logs_uploaded_file, | |
| 75 &contents_buf[0], | |
| 76 sizeof(contents_buf)); | |
| 77 DCHECK_LT(processed, sizeof(contents_buf)); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
nit: rename the |processed| variable to |read|. n
Henrik Grunell
2013/06/26 09:45:37
Done.
| |
| 78 contents.append(contents_buf, processed); | |
| 79 | |
| 80 std::vector<std::string> log_entries; | |
| 81 base::SplitStringAlongWhitespace(contents, &log_entries); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
if I'm understanding this correctly, you're splitt
Henrik Grunell
2013/06/26 09:45:37
If there's another whitespace there's an error in
tommi (sloooow) - chröme
2013/06/27 08:45:40
OK, but I still feel that it's incorrect to mix th
Henrik Grunell
2013/06/27 11:56:21
Agree, done.
| |
| 82 if (log_entries.size() >= kLogListLimitLines) | |
| 83 contents = contents.substr(contents.find('\n') + 1); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
this is unnecessarily inefficient. you're searchi
Henrik Grunell
2013/06/26 09:45:37
Absolutely, done.
| |
| 84 | |
| 85 base::Time time_now = base::Time::Now(); | |
| 86 contents += base::DoubleToString(time_now.ToDoubleT()) + | |
| 87 "," + response_string + '\n'; | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
can you add a comment on why the response string i
Henrik Grunell
2013/06/26 09:45:37
Done. The response is the report id which is writt
tommi (sloooow) - chröme
2013/06/27 08:45:40
OK, can you change the variable name to reflect th
Henrik Grunell
2013/06/27 11:56:21
Done.
| |
| 88 | |
| 89 base::SeekPlatformFile(logs_uploaded_file, base::PLATFORM_FILE_FROM_BEGIN, 0); | |
| 90 processed = base::WritePlatformFileAtCurrentPos(logs_uploaded_file, | |
| 91 contents.c_str(), | |
| 92 contents.size()); | |
| 93 DCHECK_EQ(processed, contents.size()); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
this will likely fail if log_entries.size() >= kLo
Henrik Grunell
2013/06/26 09:45:37
I don't understand. I want to write contents.size(
| |
| 94 DCHECK(base::ClosePlatformFile(logs_uploaded_file)); | |
|
tommi (sloooow) - chröme
2013/06/25 12:57:15
DCHECK code is removed in release builds, so you n
Henrik Grunell
2013/06/26 09:45:37
Oops. Fixed.
| |
| 44 } | 95 } |
| 45 | 96 |
| 46 void WebRtcLogUploader::OnURLFetchUploadProgress( | 97 void WebRtcLogUploader::OnURLFetchUploadProgress( |
| 47 const net::URLFetcher* source, int64 current, int64 total) { | 98 const net::URLFetcher* source, int64 current, int64 total) { |
| 48 } | 99 } |
| 49 | 100 |
| 50 bool WebRtcLogUploader::ApplyForStartLogging() { | 101 bool WebRtcLogUploader::ApplyForStartLogging() { |
| 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 102 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 52 if (log_count_ < kLogCountLimit) { | 103 if (log_count_ < kLogCountLimit) { |
| 53 ++log_count_; | 104 ++log_count_; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 size_t old_size = post_data->size() - stream->avail_out; | 240 size_t old_size = post_data->size() - stream->avail_out; |
| 190 post_data->resize(old_size + kIntermediateCompressionBufferBytes); | 241 post_data->resize(old_size + kIntermediateCompressionBufferBytes); |
| 191 stream->next_out = reinterpret_cast<uint8*>(&(*post_data)[old_size]); | 242 stream->next_out = reinterpret_cast<uint8*>(&(*post_data)[old_size]); |
| 192 stream->avail_out = kIntermediateCompressionBufferBytes; | 243 stream->avail_out = kIntermediateCompressionBufferBytes; |
| 193 } | 244 } |
| 194 | 245 |
| 195 void WebRtcLogUploader::DecreaseLogCount() { | 246 void WebRtcLogUploader::DecreaseLogCount() { |
| 196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 247 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 197 --log_count_; | 248 --log_count_; |
| 198 } | 249 } |
| OLD | NEW |