| 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_data.h" | 5 #include "chrome/browser/feedback/feedback_data.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 FeedbackData::FeedbackData() : profile_(NULL), | 73 FeedbackData::FeedbackData() : profile_(NULL), |
| 74 feedback_page_data_complete_(false), | 74 feedback_page_data_complete_(false), |
| 75 syslogs_compression_complete_(false), | 75 syslogs_compression_complete_(false), |
| 76 report_sent_(false) { | 76 report_sent_(false) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 FeedbackData::~FeedbackData() { | 79 FeedbackData::~FeedbackData() { |
| 80 } | 80 } |
| 81 | 81 |
| 82 void FeedbackData::OnFeedbackPageDataComplete() { |
| 83 feedback_page_data_complete_ = true; |
| 84 SendReport(); |
| 85 } |
| 86 |
| 87 void FeedbackData::SetAndCompressSystemInfo( |
| 88 scoped_ptr<FeedbackData::SystemLogsMap> sys_info) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 |
| 91 sys_info_ = sys_info.Pass(); |
| 92 if (sys_info_.get()) { |
| 93 std::string* compressed_logs_ptr = new std::string; |
| 94 scoped_ptr<std::string> compressed_logs(compressed_logs_ptr); |
| 95 BrowserThread::PostBlockingPoolTaskAndReply( |
| 96 FROM_HERE, |
| 97 base::Bind(&ZipLogs, |
| 98 sys_info_.get(), |
| 99 compressed_logs_ptr), |
| 100 base::Bind(&FeedbackData::OnCompressLogsComplete, |
| 101 this, |
| 102 base::Passed(&compressed_logs))); |
| 103 } |
| 104 } |
| 105 |
| 106 void FeedbackData::OnCompressLogsComplete( |
| 107 scoped_ptr<std::string> compressed_logs) { |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 109 |
| 110 compressed_logs_ = compressed_logs.Pass(); |
| 111 syslogs_compression_complete_ = true; |
| 112 |
| 113 SendReport(); |
| 114 } |
| 115 |
| 82 bool FeedbackData::IsDataComplete() { | 116 bool FeedbackData::IsDataComplete() { |
| 83 return (syslogs_compression_complete_ || !sys_info_.get()) && | 117 return (syslogs_compression_complete_ || !sys_info_.get()) && |
| 84 feedback_page_data_complete_; | 118 feedback_page_data_complete_; |
| 85 } | 119 } |
| 120 |
| 86 void FeedbackData::SendReport() { | 121 void FeedbackData::SendReport() { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 88 if (IsDataComplete() && !report_sent_) { | 123 if (IsDataComplete() && !report_sent_) { |
| 89 report_sent_ = true; | 124 report_sent_ = true; |
| 90 feedback_util::SendReport(this); | 125 feedback_util::SendReport(this); |
| 91 } | 126 } |
| 92 } | 127 } |
| 93 | |
| 94 void FeedbackData::OnFeedbackPageDataComplete() { | |
| 95 feedback_page_data_complete_ = true; | |
| 96 SendReport(); | |
| 97 } | |
| 98 | |
| 99 void FeedbackData::set_sys_info( | |
| 100 scoped_ptr<FeedbackData::SystemLogsMap> sys_info) { | |
| 101 if (sys_info.get()) | |
| 102 CompressSyslogs(sys_info.Pass()); | |
| 103 } | |
| 104 | |
| 105 void FeedbackData::CompressSyslogs( | |
| 106 scoped_ptr<FeedbackData::SystemLogsMap> sys_info) { | |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 108 | |
| 109 // We get the pointer first since base::Passed will nullify the scoper, hence | |
| 110 // it's not safe to use <scoper>.get() as a parameter to PostTaskAndReply. | |
| 111 FeedbackData::SystemLogsMap* sys_info_ptr = sys_info.get(); | |
| 112 std::string* compressed_logs_ptr = new std::string; | |
| 113 scoped_ptr<std::string> compressed_logs(compressed_logs_ptr); | |
| 114 BrowserThread::PostBlockingPoolTaskAndReply( | |
| 115 FROM_HERE, | |
| 116 base::Bind(&ZipLogs, | |
| 117 sys_info_ptr, | |
| 118 compressed_logs_ptr), | |
| 119 base::Bind(&FeedbackData::OnCompressLogsComplete, | |
| 120 this, | |
| 121 base::Passed(&sys_info), | |
| 122 base::Passed(&compressed_logs))); | |
| 123 } | |
| 124 | |
| 125 void FeedbackData::OnCompressLogsComplete( | |
| 126 scoped_ptr<FeedbackData::SystemLogsMap> sys_info, | |
| 127 scoped_ptr<std::string> compressed_logs) { | |
| 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 129 | |
| 130 sys_info_ = sys_info.Pass(); | |
| 131 compressed_logs_ = compressed_logs.Pass(); | |
| 132 syslogs_compression_complete_ = true; | |
| 133 | |
| 134 SendReport(); | |
| 135 } | |
| OLD | NEW |