| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 FeedbackData::~FeedbackData() { | 39 FeedbackData::~FeedbackData() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void FeedbackData::OnFeedbackPageDataComplete() { | 42 void FeedbackData::OnFeedbackPageDataComplete() { |
| 43 pending_op_count_--; | 43 pending_op_count_--; |
| 44 SendReport(); | 44 SendReport(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void FeedbackData::SetAndCompressSystemInfo( | 47 void FeedbackData::SetAndCompressSystemInfo( |
| 48 scoped_ptr<FeedbackData::SystemLogsMap> sys_info) { | 48 std::unique_ptr<FeedbackData::SystemLogsMap> sys_info) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 | 50 |
| 51 if (trace_id_ != 0) { | 51 if (trace_id_ != 0) { |
| 52 TracingManager* manager = TracingManager::Get(); | 52 TracingManager* manager = TracingManager::Get(); |
| 53 ++pending_op_count_; | 53 ++pending_op_count_; |
| 54 if (!manager || | 54 if (!manager || |
| 55 !manager->GetTraceData( | 55 !manager->GetTraceData( |
| 56 trace_id_, | 56 trace_id_, |
| 57 base::Bind(&FeedbackData::OnGetTraceData, this, trace_id_))) { | 57 base::Bind(&FeedbackData::OnGetTraceData, this, trace_id_))) { |
| 58 pending_op_count_--; | 58 pending_op_count_--; |
| 59 trace_id_ = 0; | 59 trace_id_ = 0; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 if (sys_info.get()) { | 63 if (sys_info.get()) { |
| 64 ++pending_op_count_; | 64 ++pending_op_count_; |
| 65 AddLogs(std::move(sys_info)); | 65 AddLogs(std::move(sys_info)); |
| 66 BrowserThread::PostBlockingPoolTaskAndReply( | 66 BrowserThread::PostBlockingPoolTaskAndReply( |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(&FeedbackCommon::CompressLogs, this), | 68 base::Bind(&FeedbackCommon::CompressLogs, this), |
| 69 base::Bind(&FeedbackData::OnCompressComplete, this)); | 69 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void FeedbackData::SetAndCompressHistograms( | 73 void FeedbackData::SetAndCompressHistograms( |
| 74 scoped_ptr<std::string> histograms) { | 74 std::unique_ptr<std::string> histograms) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 76 | 76 |
| 77 if (!histograms.get()) | 77 if (!histograms.get()) |
| 78 return; | 78 return; |
| 79 ++pending_op_count_; | 79 ++pending_op_count_; |
| 80 BrowserThread::PostBlockingPoolTaskAndReply( | 80 BrowserThread::PostBlockingPoolTaskAndReply( |
| 81 FROM_HERE, | 81 FROM_HERE, |
| 82 base::Bind(&FeedbackCommon::CompressFile, | 82 base::Bind(&FeedbackCommon::CompressFile, |
| 83 this, | 83 this, |
| 84 base::FilePath(kHistogramsFilename), | 84 base::FilePath(kHistogramsFilename), |
| 85 kHistogramsAttachmentName, | 85 kHistogramsAttachmentName, |
| 86 base::Passed(&histograms)), | 86 base::Passed(&histograms)), |
| 87 base::Bind(&FeedbackData::OnCompressComplete, this)); | 87 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void FeedbackData::AttachAndCompressFileData( | 90 void FeedbackData::AttachAndCompressFileData( |
| 91 scoped_ptr<std::string> attached_filedata) { | 91 std::unique_ptr<std::string> attached_filedata) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 | 93 |
| 94 if (!attached_filedata.get() || attached_filedata->empty()) | 94 if (!attached_filedata.get() || attached_filedata->empty()) |
| 95 return; | 95 return; |
| 96 ++pending_op_count_; | 96 ++pending_op_count_; |
| 97 base::FilePath attached_file = | 97 base::FilePath attached_file = |
| 98 base::FilePath::FromUTF8Unsafe(attached_filename_); | 98 base::FilePath::FromUTF8Unsafe(attached_filename_); |
| 99 BrowserThread::PostBlockingPoolTaskAndReply( | 99 BrowserThread::PostBlockingPoolTaskAndReply( |
| 100 FROM_HERE, | 100 FROM_HERE, |
| 101 base::Bind(&FeedbackCommon::CompressFile, | 101 base::Bind(&FeedbackCommon::CompressFile, |
| 102 this, | 102 this, |
| 103 attached_file, | 103 attached_file, |
| 104 std::string(), | 104 std::string(), |
| 105 base::Passed(&attached_filedata)), | 105 base::Passed(&attached_filedata)), |
| 106 base::Bind(&FeedbackData::OnCompressComplete, this)); | 106 base::Bind(&FeedbackData::OnCompressComplete, this)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void FeedbackData::OnGetTraceData( | 109 void FeedbackData::OnGetTraceData( |
| 110 int trace_id, | 110 int trace_id, |
| 111 scoped_refptr<base::RefCountedString> trace_data) { | 111 scoped_refptr<base::RefCountedString> trace_data) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 TracingManager* manager = TracingManager::Get(); | 113 TracingManager* manager = TracingManager::Get(); |
| 114 if (manager) | 114 if (manager) |
| 115 manager->DiscardTraceData(trace_id); | 115 manager->DiscardTraceData(trace_id); |
| 116 | 116 |
| 117 scoped_ptr<std::string> data(new std::string); | 117 std::unique_ptr<std::string> data(new std::string); |
| 118 data->swap(trace_data->data()); | 118 data->swap(trace_data->data()); |
| 119 | 119 |
| 120 AddFile(kTraceFilename, std::move(data)); | 120 AddFile(kTraceFilename, std::move(data)); |
| 121 | 121 |
| 122 set_category_tag(kPerformanceCategoryTag); | 122 set_category_tag(kPerformanceCategoryTag); |
| 123 --pending_op_count_; | 123 --pending_op_count_; |
| 124 trace_id_ = 0; | 124 trace_id_ = 0; |
| 125 SendReport(); | 125 SendReport(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void FeedbackData::OnCompressComplete() { | 128 void FeedbackData::OnCompressComplete() { |
| 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 130 --pending_op_count_; | 130 --pending_op_count_; |
| 131 SendReport(); | 131 SendReport(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool FeedbackData::IsDataComplete() { | 134 bool FeedbackData::IsDataComplete() { |
| 135 return pending_op_count_ == 0; | 135 return pending_op_count_ == 0; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void FeedbackData::SendReport() { | 138 void FeedbackData::SendReport() { |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 140 if (IsDataComplete() && !report_sent_) { | 140 if (IsDataComplete() && !report_sent_) { |
| 141 report_sent_ = true; | 141 report_sent_ = true; |
| 142 send_report_.Run(this); | 142 send_report_.Run(this); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace feedback | 146 } // namespace feedback |
| OLD | NEW |