| 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_data.h" | 5 #include "components/feedback/feedback_data.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 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 "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/task_scheduler/post_task.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "components/feedback/feedback_util.h" | 17 #include "components/feedback/feedback_util.h" |
| 17 #include "components/feedback/tracing_manager.h" | 18 #include "components/feedback/tracing_manager.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 | 22 |
| 22 namespace feedback { | 23 namespace feedback { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 trace_id_, | 57 trace_id_, |
| 57 base::Bind(&FeedbackData::OnGetTraceData, this, trace_id_))) { | 58 base::Bind(&FeedbackData::OnGetTraceData, this, trace_id_))) { |
| 58 pending_op_count_--; | 59 pending_op_count_--; |
| 59 trace_id_ = 0; | 60 trace_id_ = 0; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 if (sys_info) { | 64 if (sys_info) { |
| 64 ++pending_op_count_; | 65 ++pending_op_count_; |
| 65 AddLogs(std::move(sys_info)); | 66 AddLogs(std::move(sys_info)); |
| 66 BrowserThread::PostBlockingPoolTaskAndReply( | 67 base::PostTaskWithTraitsAndReply( |
| 67 FROM_HERE, base::Bind(&FeedbackData::CompressLogs, this), | 68 FROM_HERE, |
| 69 base::TaskTraits().MayBlock().WithPriority( |
| 70 base::TaskPriority::BACKGROUND), |
| 71 base::Bind(&FeedbackData::CompressLogs, this), |
| 68 base::Bind(&FeedbackData::OnCompressComplete, this)); | 72 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 69 } | 73 } |
| 70 } | 74 } |
| 71 | 75 |
| 72 void FeedbackData::SetAndCompressHistograms( | 76 void FeedbackData::SetAndCompressHistograms( |
| 73 std::unique_ptr<std::string> histograms) { | 77 std::unique_ptr<std::string> histograms) { |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 75 | 79 |
| 76 if (!histograms) | 80 if (!histograms) |
| 77 return; | 81 return; |
| 78 ++pending_op_count_; | 82 ++pending_op_count_; |
| 79 BrowserThread::PostBlockingPoolTaskAndReply( | 83 base::PostTaskWithTraitsAndReply( |
| 80 FROM_HERE, | 84 FROM_HERE, |
| 85 base::TaskTraits().MayBlock().WithPriority( |
| 86 base::TaskPriority::BACKGROUND), |
| 81 base::Bind(&FeedbackData::CompressFile, this, | 87 base::Bind(&FeedbackData::CompressFile, this, |
| 82 base::FilePath(kHistogramsFilename), kHistogramsAttachmentName, | 88 base::FilePath(kHistogramsFilename), kHistogramsAttachmentName, |
| 83 base::Passed(&histograms)), | 89 base::Passed(&histograms)), |
| 84 base::Bind(&FeedbackData::OnCompressComplete, this)); | 90 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 85 } | 91 } |
| 86 | 92 |
| 87 void FeedbackData::AttachAndCompressFileData( | 93 void FeedbackData::AttachAndCompressFileData( |
| 88 std::unique_ptr<std::string> attached_filedata) { | 94 std::unique_ptr<std::string> attached_filedata) { |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 | 96 |
| 91 if (!attached_filedata || attached_filedata->empty()) | 97 if (!attached_filedata || attached_filedata->empty()) |
| 92 return; | 98 return; |
| 93 ++pending_op_count_; | 99 ++pending_op_count_; |
| 94 base::FilePath attached_file = | 100 base::FilePath attached_file = |
| 95 base::FilePath::FromUTF8Unsafe(attached_filename_); | 101 base::FilePath::FromUTF8Unsafe(attached_filename_); |
| 96 BrowserThread::PostBlockingPoolTaskAndReply( | 102 base::PostTaskWithTraitsAndReply( |
| 97 FROM_HERE, base::Bind(&FeedbackData::CompressFile, this, attached_file, | 103 FROM_HERE, |
| 98 std::string(), base::Passed(&attached_filedata)), | 104 base::TaskTraits().MayBlock().WithPriority( |
| 105 base::TaskPriority::BACKGROUND), |
| 106 base::Bind(&FeedbackData::CompressFile, this, attached_file, |
| 107 std::string(), base::Passed(&attached_filedata)), |
| 99 base::Bind(&FeedbackData::OnCompressComplete, this)); | 108 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 100 } | 109 } |
| 101 | 110 |
| 102 void FeedbackData::OnGetTraceData( | 111 void FeedbackData::OnGetTraceData( |
| 103 int trace_id, | 112 int trace_id, |
| 104 scoped_refptr<base::RefCountedString> trace_data) { | 113 scoped_refptr<base::RefCountedString> trace_data) { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 106 TracingManager* manager = TracingManager::Get(); | 115 TracingManager* manager = TracingManager::Get(); |
| 107 if (manager) | 116 if (manager) |
| 108 manager->DiscardTraceData(trace_id); | 117 manager->DiscardTraceData(trace_id); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 130 | 139 |
| 131 void FeedbackData::SendReport() { | 140 void FeedbackData::SendReport() { |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 133 if (IsDataComplete() && !report_sent_) { | 142 if (IsDataComplete() && !report_sent_) { |
| 134 report_sent_ = true; | 143 report_sent_ = true; |
| 135 send_report_.Run(this); | 144 send_report_.Run(this); |
| 136 } | 145 } |
| 137 } | 146 } |
| 138 | 147 |
| 139 } // namespace feedback | 148 } // namespace feedback |
| OLD | NEW |