| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // we've either managed to successfully upload the report or died trying. | 358 // we've either managed to successfully upload the report or died trying. |
| 359 std::string* post_body = new std::string; | 359 std::string* post_body = new std::string; |
| 360 feedback_data.SerializeToString(post_body); | 360 feedback_data.SerializeToString(post_body); |
| 361 | 361 |
| 362 DispatchFeedback(data->profile(), post_body, 0); | 362 DispatchFeedback(data->profile(), post_body, 0); |
| 363 } | 363 } |
| 364 | 364 |
| 365 bool ZipString(const base::FilePath& filename, | 365 bool ZipString(const base::FilePath& filename, |
| 366 const std::string& data, std::string* compressed_logs) { | 366 const std::string& data, std::string* compressed_logs) { |
| 367 base::FilePath temp_path; | 367 base::FilePath temp_path; |
| 368 |
| 369 // Create a temporary directory, put the logs into a file in it. |
| 370 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) |
| 371 return false; |
| 372 |
| 373 base::FilePath temp_file = temp_path.Append(filename); |
| 374 if (file_util::WriteFile(temp_file, data.c_str(), data.size()) == -1) |
| 375 return false; |
| 376 |
| 377 return ZipFile(temp_file, compressed_logs); |
| 378 } |
| 379 |
| 380 bool ZipFile(const base::FilePath& filename, std::string* compressed_logs) { |
| 368 base::FilePath zip_file; | 381 base::FilePath zip_file; |
| 369 | 382 |
| 370 // Create a temporary directory, put the logs into a file in it. Create | 383 // Create a temporary file to receive the zip file in it. |
| 371 // another temporary file to receive the zip file in. | |
| 372 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), &temp_path)) | |
| 373 return false; | |
| 374 if (file_util::WriteFile(temp_path.Append(filename), | |
| 375 data.c_str(), data.size()) == -1) | |
| 376 return false; | |
| 377 if (!file_util::CreateTemporaryFile(&zip_file)) | 384 if (!file_util::CreateTemporaryFile(&zip_file)) |
| 378 return false; | 385 return false; |
| 379 | 386 |
| 380 if (!zip::Zip(temp_path, zip_file, false)) | 387 if (!zip::Zip(filename, zip_file, false)) |
| 381 return false; | 388 return false; |
| 382 | 389 |
| 383 if (!base::ReadFileToString(zip_file, compressed_logs)) | 390 if (!base::ReadFileToString(zip_file, compressed_logs)) |
| 384 return false; | 391 return false; |
| 385 | 392 |
| 393 base::DeleteFile(zip_file, false); |
| 394 |
| 386 return true; | 395 return true; |
| 387 } | 396 } |
| 388 | 397 |
| 389 } // namespace feedback_util | 398 } // namespace feedback_util |
| OLD | NEW |