OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/tracing/crash_service_uploader.h" | 5 #include "chrome/browser/tracing/crash_service_uploader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "build/build_config.h" |
17 #include "components/tracing/tracing_switches.h" | 18 #include "components/tracing/tracing_switches.h" |
18 #include "components/version_info/version_info.h" | 19 #include "components/version_info/version_info.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
21 #include "net/base/mime_util.h" | 22 #include "net/base/mime_util.h" |
22 #include "net/base/network_delegate.h" | 23 #include "net/base/network_delegate.h" |
23 #include "net/proxy/proxy_config.h" | 24 #include "net/proxy/proxy_config.h" |
24 #include "net/proxy/proxy_config_service.h" | 25 #include "net/proxy/proxy_config_service.h" |
25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 85 } |
85 | 86 |
86 content::BrowserThread::PostTask( | 87 content::BrowserThread::PostTask( |
87 content::BrowserThread::UI, FROM_HERE, | 88 content::BrowserThread::UI, FROM_HERE, |
88 base::Bind(done_callback_, success, feedback)); | 89 base::Bind(done_callback_, success, feedback)); |
89 url_fetcher_.reset(); | 90 url_fetcher_.reset(); |
90 } | 91 } |
91 | 92 |
92 void TraceCrashServiceUploader::OnURLFetchUploadProgress( | 93 void TraceCrashServiceUploader::OnURLFetchUploadProgress( |
93 const net::URLFetcher* source, | 94 const net::URLFetcher* source, |
94 int64 current, | 95 int64_t current, |
95 int64 total) { | 96 int64_t total) { |
96 DCHECK(url_fetcher_.get()); | 97 DCHECK(url_fetcher_.get()); |
97 | 98 |
98 LOG(WARNING) << "Upload progress: " << current << " of " << total; | 99 LOG(WARNING) << "Upload progress: " << current << " of " << total; |
99 | 100 |
100 if (progress_callback_.is_null()) | 101 if (progress_callback_.is_null()) |
101 return; | 102 return; |
102 content::BrowserThread::PostTask( | 103 content::BrowserThread::PostTask( |
103 content::BrowserThread::UI, FROM_HERE, | 104 content::BrowserThread::UI, FROM_HERE, |
104 base::Bind(progress_callback_, current, total)); | 105 base::Bind(progress_callback_, current, total)); |
105 } | 106 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 int* compressed_bytes) { | 265 int* compressed_bytes) { |
265 DCHECK(compressed); | 266 DCHECK(compressed); |
266 DCHECK(compressed_bytes); | 267 DCHECK(compressed_bytes); |
267 z_stream stream = {0}; | 268 z_stream stream = {0}; |
268 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, | 269 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, |
269 // 16 is added to produce a gzip header + trailer. | 270 // 16 is added to produce a gzip header + trailer. |
270 MAX_WBITS + 16, | 271 MAX_WBITS + 16, |
271 8, // memLevel = 8 is default. | 272 8, // memLevel = 8 is default. |
272 Z_DEFAULT_STRATEGY); | 273 Z_DEFAULT_STRATEGY); |
273 DCHECK_EQ(Z_OK, result); | 274 DCHECK_EQ(Z_OK, result); |
274 stream.next_in = reinterpret_cast<uint8*>(&input[0]); | 275 stream.next_in = reinterpret_cast<uint8_t*>(&input[0]); |
275 stream.avail_in = input.size(); | 276 stream.avail_in = input.size(); |
276 stream.next_out = reinterpret_cast<uint8*>(compressed); | 277 stream.next_out = reinterpret_cast<uint8_t*>(compressed); |
277 stream.avail_out = max_compressed_bytes; | 278 stream.avail_out = max_compressed_bytes; |
278 // Do a one-shot compression. This will return Z_STREAM_END only if |output| | 279 // Do a one-shot compression. This will return Z_STREAM_END only if |output| |
279 // is large enough to hold all compressed data. | 280 // is large enough to hold all compressed data. |
280 result = deflate(&stream, Z_FINISH); | 281 result = deflate(&stream, Z_FINISH); |
281 bool success = (result == Z_STREAM_END); | 282 bool success = (result == Z_STREAM_END); |
282 result = deflateEnd(&stream); | 283 result = deflateEnd(&stream); |
283 DCHECK(result == Z_OK || result == Z_DATA_ERROR); | 284 DCHECK(result == Z_OK || result == Z_DATA_ERROR); |
284 | 285 |
285 if (success) | 286 if (success) |
286 *compressed_bytes = max_compressed_bytes - stream.avail_out; | 287 *compressed_bytes = max_compressed_bytes - stream.avail_out; |
(...skipping 12 matching lines...) Expand all Loading... |
299 std::string content_type = kUploadContentType; | 300 std::string content_type = kUploadContentType; |
300 content_type.append("; boundary="); | 301 content_type.append("; boundary="); |
301 content_type.append(kMultipartBoundary); | 302 content_type.append(kMultipartBoundary); |
302 | 303 |
303 url_fetcher_ = | 304 url_fetcher_ = |
304 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this); | 305 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this); |
305 url_fetcher_->SetRequestContext(request_context_); | 306 url_fetcher_->SetRequestContext(request_context_); |
306 url_fetcher_->SetUploadData(content_type, post_data); | 307 url_fetcher_->SetUploadData(content_type, post_data); |
307 url_fetcher_->Start(); | 308 url_fetcher_->Start(); |
308 } | 309 } |
OLD | NEW |