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