| 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 "components/feedback/feedback_util.h" | 5 #include "components/feedback/feedback_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "components/feedback/feedback_data.h" | 12 #include "components/feedback/feedback_data.h" |
| 13 #include "components/feedback/feedback_uploader.h" | 13 #include "components/feedback/feedback_uploader.h" |
| 14 #include "components/feedback/feedback_uploader_factory.h" | 14 #include "components/feedback/feedback_uploader_factory.h" |
| 15 #include "components/feedback/proto/common.pb.h" | |
| 16 #include "components/feedback/proto/dom.pb.h" | |
| 17 #include "components/feedback/proto/extension.pb.h" | 15 #include "components/feedback/proto/extension.pb.h" |
| 18 #include "components/feedback/proto/math.pb.h" | |
| 19 #include "third_party/zlib/google/zip.h" | 16 #include "third_party/zlib/google/zip.h" |
| 20 | 17 |
| 21 using feedback::FeedbackData; | 18 using feedback::FeedbackData; |
| 22 | 19 |
| 23 namespace { | |
| 24 | |
| 25 #if defined(OS_CHROMEOS) | |
| 26 const int kChromeOSProductId = 208; | |
| 27 #else | |
| 28 const int kChromeBrowserProductId = 237; | |
| 29 #endif | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 namespace feedback_util { | 20 namespace feedback_util { |
| 34 | 21 |
| 35 void SendReport(scoped_refptr<FeedbackData> data) { | 22 void SendReport(scoped_refptr<FeedbackData> data) { |
| 36 if (!data.get()) { | 23 if (!data.get()) { |
| 37 LOG(ERROR) << "SendReport called with NULL data!"; | 24 LOG(ERROR) << "SendReport called with NULL data!"; |
| 38 NOTREACHED(); | 25 NOTREACHED(); |
| 39 return; | 26 return; |
| 40 } | 27 } |
| 41 | 28 |
| 42 userfeedback::ExtensionSubmit feedback_data; | 29 userfeedback::ExtensionSubmit feedback_data; |
| 43 data->PrepareReport(&feedback_data); | 30 data->PrepareReport(&feedback_data); |
| 44 | 31 |
| 45 // Set whether we're reporting from ChromeOS or Chrome on another platform. | |
| 46 userfeedback::ChromeData chrome_data; | |
| 47 #if defined(OS_CHROMEOS) | |
| 48 chrome_data.set_chrome_platform( | |
| 49 userfeedback::ChromeData_ChromePlatform_CHROME_OS); | |
| 50 userfeedback::ChromeOsData chrome_os_data; | |
| 51 chrome_os_data.set_category( | |
| 52 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); | |
| 53 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; | |
| 54 feedback_data.set_product_id(kChromeOSProductId); | |
| 55 #else | |
| 56 chrome_data.set_chrome_platform( | |
| 57 userfeedback::ChromeData_ChromePlatform_CHROME_BROWSER); | |
| 58 userfeedback::ChromeBrowserData chrome_browser_data; | |
| 59 chrome_browser_data.set_category( | |
| 60 userfeedback::ChromeBrowserData_ChromeBrowserCategory_OTHER); | |
| 61 *(chrome_data.mutable_chrome_browser_data()) = chrome_browser_data; | |
| 62 feedback_data.set_product_id(kChromeBrowserProductId); | |
| 63 #endif | |
| 64 | |
| 65 *(feedback_data.mutable_chrome_data()) = chrome_data; | |
| 66 | |
| 67 // This pointer will eventually get deleted by the PostCleanup class, after | 32 // This pointer will eventually get deleted by the PostCleanup class, after |
| 68 // we've either managed to successfully upload the report or died trying. | 33 // we've either managed to successfully upload the report or died trying. |
| 69 std::string post_body; | 34 std::string post_body; |
| 70 feedback_data.SerializeToString(&post_body); | 35 feedback_data.SerializeToString(&post_body); |
| 71 | 36 |
| 72 feedback::FeedbackUploader *uploader = | 37 feedback::FeedbackUploader *uploader = |
| 73 feedback::FeedbackUploaderFactory::GetForBrowserContext(data->context()); | 38 feedback::FeedbackUploaderFactory::GetForBrowserContext(data->context()); |
| 74 uploader->QueueReport(post_body); | 39 uploader->QueueReport(post_body); |
| 75 } | 40 } |
| 76 | 41 |
| 77 bool ZipString(const base::FilePath& filename, | 42 bool ZipString(const base::FilePath& filename, |
| 78 const std::string& data, std::string* compressed_logs) { | 43 const std::string& data, std::string* compressed_logs) { |
| 79 base::FilePath temp_path; | 44 base::FilePath temp_path; |
| 80 base::FilePath zip_file; | 45 base::FilePath zip_file; |
| 81 | 46 |
| 82 // Create a temporary directory, put the logs into a file in it. Create | 47 // Create a temporary directory, put the logs into a file in it. Create |
| 83 // another temporary file to receive the zip file in. | 48 // another temporary file to receive the zip file in. |
| 84 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), &temp_path)) | 49 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), &temp_path)) |
| 85 return false; | 50 return false; |
| 86 if (base::WriteFile(temp_path.Append(filename), data.c_str(), data.size()) == | 51 if (base::WriteFile(temp_path.Append(filename), data.c_str(), data.size()) == |
| 87 -1) | 52 -1) { |
| 88 return false; | 53 return false; |
| 54 } |
| 89 | 55 |
| 90 bool succeed = base::CreateTemporaryFile(&zip_file) && | 56 bool succeed = base::CreateTemporaryFile(&zip_file) && |
| 91 zip::Zip(temp_path, zip_file, false) && | 57 zip::Zip(temp_path, zip_file, false) && |
| 92 base::ReadFileToString(zip_file, compressed_logs); | 58 base::ReadFileToString(zip_file, compressed_logs); |
| 93 | 59 |
| 94 base::DeleteFile(temp_path, true); | 60 base::DeleteFile(temp_path, true); |
| 95 base::DeleteFile(zip_file, false); | 61 base::DeleteFile(zip_file, false); |
| 96 | 62 |
| 97 return succeed; | 63 return succeed; |
| 98 } | 64 } |
| 99 | 65 |
| 100 } // namespace feedback_util | 66 } // namespace feedback_util |
| OLD | NEW |