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

Side by Side Diff: chrome/browser/tracing/crash_service_uploader.cc

Issue 1225923003: Make compression optional in TraceUploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment for clarification. Created 5 years, 5 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 unified diff | Download patch
OLDNEW
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"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 if (progress_callback_.is_null()) 96 if (progress_callback_.is_null())
97 return; 97 return;
98 content::BrowserThread::PostTask( 98 content::BrowserThread::PostTask(
99 content::BrowserThread::UI, FROM_HERE, 99 content::BrowserThread::UI, FROM_HERE,
100 base::Bind(progress_callback_, current, total)); 100 base::Bind(progress_callback_, current, total));
101 } 101 }
102 102
103 void TraceCrashServiceUploader::DoUpload( 103 void TraceCrashServiceUploader::DoUpload(
104 const std::string& file_contents, 104 const std::string& file_contents,
105 UploadMode upload_mode,
105 scoped_ptr<base::DictionaryValue> metadata, 106 scoped_ptr<base::DictionaryValue> metadata,
106 const UploadProgressCallback& progress_callback, 107 const UploadProgressCallback& progress_callback,
107 const UploadDoneCallback& done_callback) { 108 const UploadDoneCallback& done_callback) {
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
109 content::BrowserThread::PostTask( 110 content::BrowserThread::PostTask(
110 content::BrowserThread::FILE, FROM_HERE, 111 content::BrowserThread::FILE, FROM_HERE,
111 base::Bind(&TraceCrashServiceUploader::DoUploadOnFileThread, 112 base::Bind(&TraceCrashServiceUploader::DoUploadOnFileThread,
112 base::Unretained(this), file_contents, upload_url_, 113 base::Unretained(this), file_contents, upload_mode,
113 base::Passed(metadata.Pass()), progress_callback, 114 upload_url_, base::Passed(metadata.Pass()), progress_callback,
114 done_callback)); 115 done_callback));
115 } 116 }
116 117
117 void TraceCrashServiceUploader::DoUploadOnFileThread( 118 void TraceCrashServiceUploader::DoUploadOnFileThread(
118 const std::string& file_contents, 119 const std::string& file_contents,
120 UploadMode upload_mode,
119 const std::string& upload_url, 121 const std::string& upload_url,
120 scoped_ptr<base::DictionaryValue> metadata, 122 scoped_ptr<base::DictionaryValue> metadata,
121 const UploadProgressCallback& progress_callback, 123 const UploadProgressCallback& progress_callback,
122 const UploadDoneCallback& done_callback) { 124 const UploadDoneCallback& done_callback) {
123 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 125 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
124 DCHECK(!url_fetcher_.get()); 126 DCHECK(!url_fetcher_.get());
125 127
126 progress_callback_ = progress_callback; 128 progress_callback_ = progress_callback;
127 done_callback_ = done_callback; 129 done_callback_ = done_callback;
128 130
(...skipping 28 matching lines...) Expand all
157 version = product_components[1]; 159 version = product_components[1];
158 } else { 160 } else {
159 version = "unknown"; 161 version = "unknown";
160 } 162 }
161 163
162 if (url_fetcher_.get()) { 164 if (url_fetcher_.get()) {
163 OnUploadError("Already uploading."); 165 OnUploadError("Already uploading.");
164 return; 166 return;
165 } 167 }
166 168
167 scoped_ptr<char[]> compressed_contents(new char[kMaxUploadBytes]); 169 std::string compressed_contents;
168 int compressed_bytes; 170 if (upload_mode == COMPRESSED_UPLOAD) {
169 if (!Compress(file_contents, kMaxUploadBytes, compressed_contents.get(), 171 scoped_ptr<char[]> compressed_buffer(new char[kMaxUploadBytes]);
170 &compressed_bytes)) { 172 int compressed_bytes;
171 OnUploadError("Compressing file failed."); 173 if (!Compress(file_contents, kMaxUploadBytes, compressed_buffer.get(),
172 return; 174 &compressed_bytes)) {
175 OnUploadError("Compressing file failed.");
176 return;
177 }
178 compressed_contents =
179 std::string(compressed_buffer.get(), compressed_bytes);
180 } else {
181 if (file_contents.size() >= kMaxUploadBytes) {
182 OnUploadError("File is too large to upload.");
183 return;
184 }
185 compressed_contents = file_contents;
173 } 186 }
174 187
175 std::string post_data; 188 std::string post_data;
176 SetupMultipart(product, version, metadata.Pass(), "trace.json.gz", 189 SetupMultipart(product, version, metadata.Pass(), "trace.json.gz",
177 std::string(compressed_contents.get(), compressed_bytes), 190 compressed_contents, &post_data);
178 &post_data);
179 191
180 content::BrowserThread::PostTask( 192 content::BrowserThread::PostTask(
181 content::BrowserThread::UI, FROM_HERE, 193 content::BrowserThread::UI, FROM_HERE,
182 base::Bind(&TraceCrashServiceUploader::CreateAndStartURLFetcher, 194 base::Bind(&TraceCrashServiceUploader::CreateAndStartURLFetcher,
183 base::Unretained(this), upload_url, post_data)); 195 base::Unretained(this), upload_url, post_data));
184 } 196 }
185 197
186 void TraceCrashServiceUploader::OnUploadError(std::string error_message) { 198 void TraceCrashServiceUploader::OnUploadError(std::string error_message) {
187 LOG(ERROR) << error_message; 199 LOG(ERROR) << error_message;
188 content::BrowserThread::PostTask( 200 content::BrowserThread::PostTask(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 std::string content_type = kUploadContentType; 295 std::string content_type = kUploadContentType;
284 content_type.append("; boundary="); 296 content_type.append("; boundary=");
285 content_type.append(kMultipartBoundary); 297 content_type.append(kMultipartBoundary);
286 298
287 url_fetcher_ = 299 url_fetcher_ =
288 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this); 300 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this);
289 url_fetcher_->SetRequestContext(request_context_); 301 url_fetcher_->SetRequestContext(request_context_);
290 url_fetcher_->SetUploadData(content_type, post_data); 302 url_fetcher_->SetUploadData(content_type, post_data);
291 url_fetcher_->Start(); 303 url_fetcher_->Start();
292 } 304 }
OLDNEW
« no previous file with comments | « chrome/browser/tracing/crash_service_uploader.h ('k') | chrome/browser/tracing/navigation_tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698