OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/feedback/feedback_util.h" | 5 #include "chrome/browser/feedback/feedback_util.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // we've either managed to successfully upload the report or died trying. | 367 // we've either managed to successfully upload the report or died trying. |
368 std::string* post_body = new std::string; | 368 std::string* post_body = new std::string; |
369 feedback_data.SerializeToString(post_body); | 369 feedback_data.SerializeToString(post_body); |
370 | 370 |
371 DispatchFeedback(data->profile(), post_body, 0); | 371 DispatchFeedback(data->profile(), post_body, 0); |
372 } | 372 } |
373 | 373 |
374 bool ZipString(const base::FilePath& filename, | 374 bool ZipString(const base::FilePath& filename, |
375 const std::string& data, std::string* compressed_logs) { | 375 const std::string& data, std::string* compressed_logs) { |
376 base::FilePath temp_path; | 376 base::FilePath temp_path; |
| 377 |
| 378 // Create a temporary directory, put the logs into a file in it. |
| 379 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) |
| 380 return false; |
| 381 |
| 382 base::FilePath temp_file = temp_path.Append(filename); |
| 383 if (file_util::WriteFile(temp_file, data.c_str(), data.size()) == -1) |
| 384 return false; |
| 385 |
| 386 return ZipFile(temp_file, compressed_logs); |
| 387 } |
| 388 |
| 389 bool ZipFile(const base::FilePath& filename, std::string* compressed_logs) { |
377 base::FilePath zip_file; | 390 base::FilePath zip_file; |
378 | 391 |
379 // Create a temporary directory, put the logs into a file in it. Create | 392 // Create a temporary file to receive the zip file in it. |
380 // another temporary file to receive the zip file in. | |
381 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) | |
382 return false; | |
383 if (file_util::WriteFile(temp_path.Append(filename), | |
384 data.c_str(), data.size()) == -1) | |
385 return false; | |
386 if (!file_util::CreateTemporaryFile(&zip_file)) | 393 if (!file_util::CreateTemporaryFile(&zip_file)) |
387 return false; | 394 return false; |
388 | 395 |
389 if (!zip::Zip(temp_path, zip_file, false)) | 396 if (!zip::Zip(filename, zip_file, false)) |
390 return false; | 397 return false; |
391 | 398 |
392 if (!base::ReadFileToString(zip_file, compressed_logs)) | 399 if (!base::ReadFileToString(zip_file, compressed_logs)) |
393 return false; | 400 return false; |
394 | 401 |
| 402 base::DeleteFile(zip_file, false); |
| 403 |
395 return true; | 404 return true; |
396 } | 405 } |
397 | 406 |
398 } // namespace feedback_util | 407 } // namespace feedback_util |
OLD | NEW |