| 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 base::FilePath zip_file; |
| 377 | 378 |
| 378 // Create a temporary directory, put the logs into a file in it. | 379 // Create a temporary directory, put the logs into a file in it. Create |
| 380 // another temporary file to receive the zip file in. |
| 379 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) | 381 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) |
| 380 return false; | 382 return false; |
| 381 | 383 if (file_util::WriteFile(temp_path.Append(filename), |
| 382 base::FilePath temp_file = temp_path.Append(filename); | 384 data.c_str(), data.size()) == -1) |
| 383 if (file_util::WriteFile(temp_file, data.c_str(), data.size()) == -1) | |
| 384 return false; | 385 return false; |
| 385 | |
| 386 return ZipFile(temp_file, compressed_logs); | |
| 387 } | |
| 388 | |
| 389 bool ZipFile(const base::FilePath& filename, std::string* compressed_logs) { | |
| 390 base::FilePath zip_file; | |
| 391 | |
| 392 // Create a temporary file to receive the zip file in it. | |
| 393 if (!file_util::CreateTemporaryFile(&zip_file)) | 386 if (!file_util::CreateTemporaryFile(&zip_file)) |
| 394 return false; | 387 return false; |
| 395 | 388 |
| 396 if (!zip::Zip(filename, zip_file, false)) | 389 if (!zip::Zip(temp_path, zip_file, false)) |
| 397 return false; | 390 return false; |
| 398 | 391 |
| 399 if (!base::ReadFileToString(zip_file, compressed_logs)) | 392 if (!base::ReadFileToString(zip_file, compressed_logs)) |
| 400 return false; | 393 return false; |
| 401 | 394 |
| 402 base::DeleteFile(zip_file, false); | |
| 403 | |
| 404 return true; | 395 return true; |
| 405 } | 396 } |
| 406 | 397 |
| 407 } // namespace feedback_util | 398 } // namespace feedback_util |
| OLD | NEW |