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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | |
11 #include "base/path_service.h" | 10 #include "base/path_service.h" |
12 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/browser_process.h" | |
16 #include "chrome/browser/media/webrtc_log_upload_list.h" | 16 #include "chrome/browser/media/webrtc_log_upload_list.h" |
17 #include "chrome/common/chrome_paths.h" | |
18 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
19 #include "chrome/common/partial_circular_buffer.h" | 18 #include "chrome/common/partial_circular_buffer.h" |
20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
21 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
22 #include "net/base/network_delegate.h" | |
23 #include "net/proxy/proxy_config.h" | |
24 #include "net/proxy/proxy_config_service.h" | |
25 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
26 #include "net/url_request/url_request_context.h" | |
27 #include "net/url_request/url_request_context_builder.h" | |
28 #include "net/url_request/url_request_context_getter.h" | |
29 #include "third_party/zlib/zlib.h" | 22 #include "third_party/zlib/zlib.h" |
30 | 23 |
31 namespace { | 24 namespace { |
32 | 25 |
33 const int kLogCountLimit = 5; | 26 const int kLogCountLimit = 5; |
34 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB | 27 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB |
35 const int kLogListLimitLines = 50; | 28 const int kLogListLimitLines = 50; |
36 | 29 |
37 const char kUploadURL[] = "https://clients2.google.com/cr/report"; | 30 const char kUploadURL[] = "https://clients2.google.com/cr/report"; |
38 const char kUploadContentType[] = "multipart/form-data"; | 31 const char kUploadContentType[] = "multipart/form-data"; |
39 const char kMultipartBoundary[] = | 32 const char kMultipartBoundary[] = |
40 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 33 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
41 | 34 |
42 const int kHttpResponseOk = 200; | 35 const int kHttpResponseOk = 200; |
43 | 36 |
44 } // namespace | 37 } // namespace |
45 | 38 |
46 WebRtcLogUploader::WebRtcLogUploader() | 39 WebRtcLogUploader::WebRtcLogUploader() |
47 : log_count_(0), | 40 : log_count_(0), |
48 post_data_(NULL) { | 41 post_data_(NULL) { |
49 file_thread_checker_.DetachFromThread(); | 42 file_thread_checker_.DetachFromThread(); |
50 } | 43 } |
51 | 44 |
52 WebRtcLogUploader::~WebRtcLogUploader() { | 45 WebRtcLogUploader::~WebRtcLogUploader() { |
Ami GONE FROM CHROMIUM
2014/03/25 17:53:17
DCHECK the vector is empty.
Henrik Grunell
2014/03/26 06:59:02
Done.
| |
53 DCHECK(create_thread_checker_.CalledOnValidThread()); | 46 DCHECK(create_thread_checker_.CalledOnValidThread()); |
54 // Delete all pending URLFetcher and release all references to | |
55 // WebRtcLoggingHandlerHost. | |
56 for (UploadDoneDataMap::iterator it = upload_done_data_.begin(); | |
57 it != upload_done_data_.end(); ++it) { | |
58 delete it->first; | |
59 } | |
60 upload_done_data_.clear(); | |
61 } | 47 } |
62 | 48 |
63 void WebRtcLogUploader::OnURLFetchComplete( | 49 void WebRtcLogUploader::OnURLFetchComplete( |
64 const net::URLFetcher* source) { | 50 const net::URLFetcher* source) { |
65 DCHECK(create_thread_checker_.CalledOnValidThread()); | 51 DCHECK(create_thread_checker_.CalledOnValidThread()); |
66 DCHECK(upload_done_data_.find(source) != upload_done_data_.end()); | 52 DCHECK(upload_done_data_.find(source) != upload_done_data_.end()); |
67 int response_code = source->GetResponseCode(); | 53 int response_code = source->GetResponseCode(); |
68 std::string report_id; | 54 std::string report_id; |
69 if (response_code == kHttpResponseOk && | 55 if (response_code == kHttpResponseOk && |
70 source->GetResponseAsString(&report_id)) { | 56 source->GetResponseAsString(&report_id)) { |
71 content::BrowserThread::PostTask( | 57 content::BrowserThread::PostTask( |
72 content::BrowserThread::FILE, FROM_HERE, | 58 content::BrowserThread::FILE, FROM_HERE, |
73 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile, | 59 base::Bind(&WebRtcLogUploader::AddUploadedLogInfoToUploadListFile, |
74 base::Unretained(this), | 60 base::Unretained(this), |
75 upload_done_data_[source].upload_list_path, | 61 upload_done_data_[source].upload_list_path, |
76 report_id)); | 62 report_id)); |
77 } | 63 } |
78 NotifyUploadDone(response_code, report_id, upload_done_data_[source]); | 64 NotifyUploadDone(response_code, report_id, upload_done_data_[source]); |
79 upload_done_data_.erase(source); | 65 upload_done_data_.erase(source); |
80 delete source; | 66 |
67 bool found_in_vector = false; | |
68 for (URLFetcherVector::iterator it = url_fetchers_.begin(); | |
69 it != url_fetchers_.end(); | |
70 ++it) { | |
Ami GONE FROM CHROMIUM
2014/03/25 17:53:17
It's a vector, so you could
for (size_t i = 0; i <
Henrik Grunell
2014/03/26 06:59:02
Done.
| |
71 if (*it == source) { | |
72 url_fetchers_.erase(it); | |
73 found_in_vector = true; | |
Ami GONE FROM CHROMIUM
2014/03/25 17:53:17
can drop found_in_vector+break in favor of a retur
Henrik Grunell
2014/03/26 06:59:02
Done.
| |
74 break; | |
75 } | |
76 } | |
77 if (!found_in_vector) { | |
78 DLOG(WARNING) << "URLFetcher not found in vector."; | |
Ami GONE FROM CHROMIUM
2014/03/25 17:53:17
Can this happen if there is a fetch in flight whil
Henrik Grunell
2014/03/26 06:59:02
Right. This should really not happen if cancelled.
| |
79 delete source; | |
80 } | |
81 } | 81 } |
82 | 82 |
83 void WebRtcLogUploader::OnURLFetchUploadProgress( | 83 void WebRtcLogUploader::OnURLFetchUploadProgress( |
84 const net::URLFetcher* source, int64 current, int64 total) { | 84 const net::URLFetcher* source, int64 current, int64 total) { |
85 } | 85 } |
86 | 86 |
87 bool WebRtcLogUploader::ApplyForStartLogging() { | 87 bool WebRtcLogUploader::ApplyForStartLogging() { |
88 DCHECK(create_thread_checker_.CalledOnValidThread()); | 88 DCHECK(create_thread_checker_.CalledOnValidThread()); |
89 if (log_count_ < kLogCountLimit) { | 89 if (log_count_ < kLogCountLimit) { |
90 ++log_count_; | 90 ++log_count_; |
91 return true; | 91 return true; |
92 } | 92 } |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 void WebRtcLogUploader::LoggingStoppedDontUpload() { | 96 void WebRtcLogUploader::LoggingStoppedDontUpload() { |
97 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 97 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
98 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); | 98 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); |
99 } | 99 } |
100 | 100 |
101 void WebRtcLogUploader::LoggingStoppedDoUpload( | 101 void WebRtcLogUploader::LoggingStoppedDoUpload( |
102 net::URLRequestContextGetter* request_context, | |
103 scoped_ptr<unsigned char[]> log_buffer, | 102 scoped_ptr<unsigned char[]> log_buffer, |
104 uint32 length, | 103 uint32 length, |
105 const std::map<std::string, std::string>& meta_data, | 104 const std::map<std::string, std::string>& meta_data, |
106 const WebRtcLogUploadDoneData& upload_done_data) { | 105 const WebRtcLogUploadDoneData& upload_done_data) { |
107 DCHECK(file_thread_checker_.CalledOnValidThread()); | 106 DCHECK(file_thread_checker_.CalledOnValidThread()); |
108 DCHECK(log_buffer.get()); | 107 DCHECK(log_buffer.get()); |
109 DCHECK(!upload_done_data.upload_list_path.empty()); | 108 DCHECK(!upload_done_data.upload_list_path.empty()); |
110 | 109 |
111 scoped_ptr<std::string> post_data; | 110 scoped_ptr<std::string> post_data; |
112 post_data.reset(new std::string); | 111 post_data.reset(new std::string); |
(...skipping 10 matching lines...) Expand all Loading... | |
123 if (post_data_) { | 122 if (post_data_) { |
124 *post_data_ = *post_data; | 123 *post_data_ = *post_data; |
125 NotifyUploadDone(kHttpResponseOk, "", upload_done_data); | 124 NotifyUploadDone(kHttpResponseOk, "", upload_done_data); |
126 return; | 125 return; |
127 } | 126 } |
128 | 127 |
129 content::BrowserThread::PostTask( | 128 content::BrowserThread::PostTask( |
130 content::BrowserThread::UI, FROM_HERE, | 129 content::BrowserThread::UI, FROM_HERE, |
131 base::Bind(&WebRtcLogUploader::CreateAndStartURLFetcher, | 130 base::Bind(&WebRtcLogUploader::CreateAndStartURLFetcher, |
132 base::Unretained(this), | 131 base::Unretained(this), |
133 make_scoped_refptr(request_context), | |
134 upload_done_data, | 132 upload_done_data, |
135 Passed(&post_data))); | 133 Passed(&post_data))); |
136 | 134 |
137 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 135 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
138 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); | 136 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); |
139 } | 137 } |
140 | 138 |
139 void WebRtcLogUploader::CancelURLFetcherOperations() { | |
140 DCHECK(create_thread_checker_.CalledOnValidThread()); | |
141 url_fetchers_.clear(); | |
142 } | |
143 | |
141 void WebRtcLogUploader::SetupMultipart( | 144 void WebRtcLogUploader::SetupMultipart( |
142 std::string* post_data, uint8* log_buffer, uint32 log_buffer_length, | 145 std::string* post_data, uint8* log_buffer, uint32 log_buffer_length, |
143 const std::map<std::string, std::string>& meta_data) { | 146 const std::map<std::string, std::string>& meta_data) { |
144 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
145 const char product[] = "Chrome"; | 148 const char product[] = "Chrome"; |
146 #elif defined(OS_MACOSX) | 149 #elif defined(OS_MACOSX) |
147 const char product[] = "Chrome_Mac"; | 150 const char product[] = "Chrome_Mac"; |
148 #elif defined(OS_LINUX) | 151 #elif defined(OS_LINUX) |
149 #if !defined(ADDRESS_SANITIZER) | 152 #if !defined(ADDRESS_SANITIZER) |
150 const char product[] = "Chrome_Linux"; | 153 const char product[] = "Chrome_Linux"; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 245 |
243 void WebRtcLogUploader::ResizeForNextOutput(std::string* post_data, | 246 void WebRtcLogUploader::ResizeForNextOutput(std::string* post_data, |
244 z_stream* stream) { | 247 z_stream* stream) { |
245 size_t old_size = post_data->size() - stream->avail_out; | 248 size_t old_size = post_data->size() - stream->avail_out; |
246 post_data->resize(old_size + kIntermediateCompressionBufferBytes); | 249 post_data->resize(old_size + kIntermediateCompressionBufferBytes); |
247 stream->next_out = reinterpret_cast<uint8*>(&(*post_data)[old_size]); | 250 stream->next_out = reinterpret_cast<uint8*>(&(*post_data)[old_size]); |
248 stream->avail_out = kIntermediateCompressionBufferBytes; | 251 stream->avail_out = kIntermediateCompressionBufferBytes; |
249 } | 252 } |
250 | 253 |
251 void WebRtcLogUploader::CreateAndStartURLFetcher( | 254 void WebRtcLogUploader::CreateAndStartURLFetcher( |
252 scoped_refptr<net::URLRequestContextGetter> request_context, | |
253 const WebRtcLogUploadDoneData& upload_done_data, | 255 const WebRtcLogUploadDoneData& upload_done_data, |
254 scoped_ptr<std::string> post_data) { | 256 scoped_ptr<std::string> post_data) { |
255 DCHECK(create_thread_checker_.CalledOnValidThread()); | 257 DCHECK(create_thread_checker_.CalledOnValidThread()); |
256 std::string content_type = kUploadContentType; | 258 std::string content_type = kUploadContentType; |
257 content_type.append("; boundary="); | 259 content_type.append("; boundary="); |
258 content_type.append(kMultipartBoundary); | 260 content_type.append(kMultipartBoundary); |
259 | 261 |
260 net::URLFetcher* url_fetcher = | 262 scoped_ptr<net::URLFetcher> url_fetcher( |
261 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this); | 263 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this)); |
262 url_fetcher->SetRequestContext(request_context); | 264 url_fetcher->SetRequestContext(g_browser_process->system_request_context()); |
263 url_fetcher->SetUploadData(content_type, *post_data); | 265 url_fetcher->SetUploadData(content_type, *post_data); |
264 url_fetcher->Start(); | 266 url_fetcher->Start(); |
265 upload_done_data_[url_fetcher] = upload_done_data; | 267 upload_done_data_[url_fetcher.get()] = upload_done_data; |
268 url_fetchers_.push_back(url_fetcher.Pass()); | |
266 } | 269 } |
267 | 270 |
268 void WebRtcLogUploader::DecreaseLogCount() { | 271 void WebRtcLogUploader::DecreaseLogCount() { |
269 DCHECK(create_thread_checker_.CalledOnValidThread()); | 272 DCHECK(create_thread_checker_.CalledOnValidThread()); |
270 --log_count_; | 273 --log_count_; |
271 } | 274 } |
272 | 275 |
273 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile( | 276 void WebRtcLogUploader::AddUploadedLogInfoToUploadListFile( |
274 const base::FilePath& upload_list_path, | 277 const base::FilePath& upload_list_path, |
275 const std::string& report_id) { | 278 const std::string& report_id) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 if (!success) { | 322 if (!success) { |
320 error_message = "Uploading failed, response code: " + | 323 error_message = "Uploading failed, response code: " + |
321 base::IntToString(response_code); | 324 base::IntToString(response_code); |
322 } | 325 } |
323 content::BrowserThread::PostTask( | 326 content::BrowserThread::PostTask( |
324 content::BrowserThread::UI, FROM_HERE, | 327 content::BrowserThread::UI, FROM_HERE, |
325 base::Bind(upload_done_data.callback, success, report_id, | 328 base::Bind(upload_done_data.callback, success, report_id, |
326 error_message)); | 329 error_message)); |
327 } | 330 } |
328 } | 331 } |
OLD | NEW |