Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: components/feedback/feedback_common.cc

Issue 1918083002: Convert //components/[f-n]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: … Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/feedback/feedback_common.h ('k') | components/feedback/feedback_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_common.h" 5 #include "components/feedback/feedback_common.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "components/feedback/proto/common.pb.h" 11 #include "components/feedback/proto/common.pb.h"
11 #include "components/feedback/proto/dom.pb.h" 12 #include "components/feedback/proto/dom.pb.h"
12 #include "components/feedback/proto/extension.pb.h" 13 #include "components/feedback/proto/extension.pb.h"
13 #include "components/feedback/proto/math.pb.h" 14 #include "components/feedback/proto/math.pb.h"
14 15
15 namespace { 16 namespace {
16 17
17 const char kMultilineIndicatorString[] = "<multiline>\n"; 18 const char kMultilineIndicatorString[] = "<multiline>\n";
18 const char kMultilineStartString[] = "---------- START ----------\n"; 19 const char kMultilineStartString[] = "---------- START ----------\n";
19 const char kMultilineEndString[] = "---------- END ----------\n\n"; 20 const char kMultilineEndString[] = "---------- END ----------\n\n";
20 21
21 const size_t kFeedbackMaxLength = 4 * 1024; 22 const size_t kFeedbackMaxLength = 4 * 1024;
22 const size_t kFeedbackMaxLineCount = 40; 23 const size_t kFeedbackMaxLineCount = 40;
23 24
24 const base::FilePath::CharType kLogsFilename[] = 25 const base::FilePath::CharType kLogsFilename[] =
25 FILE_PATH_LITERAL("system_logs.txt"); 26 FILE_PATH_LITERAL("system_logs.txt");
26 const char kLogsAttachmentName[] = "system_logs.zip"; 27 const char kLogsAttachmentName[] = "system_logs.zip";
27 28
28 const char kZipExt[] = ".zip"; 29 const char kZipExt[] = ".zip";
29 30
30 const char kPngMimeType[] = "image/png"; 31 const char kPngMimeType[] = "image/png";
31 const char kArbitraryMimeType[] = "application/octet-stream"; 32 const char kArbitraryMimeType[] = "application/octet-stream";
32 33
33 // Converts the system logs into a string that we can compress and send 34 // Converts the system logs into a string that we can compress and send
34 // with the report. This method only converts those logs that we want in 35 // with the report. This method only converts those logs that we want in
35 // the compressed zip file sent with the report, hence it ignores any logs 36 // the compressed zip file sent with the report, hence it ignores any logs
36 // below the size threshold of what we want compressed. 37 // below the size threshold of what we want compressed.
37 std::string* LogsToString(const FeedbackCommon::SystemLogsMap& sys_info) { 38 // TODO(dcheng): This should probably just take advantage of string's move
38 std::string* syslogs_string = new std::string; 39 // constructor.
40 std::unique_ptr<std::string> LogsToString(
41 const FeedbackCommon::SystemLogsMap& sys_info) {
42 std::unique_ptr<std::string> syslogs_string(new std::string);
39 for (FeedbackCommon::SystemLogsMap::const_iterator it = sys_info.begin(); 43 for (FeedbackCommon::SystemLogsMap::const_iterator it = sys_info.begin();
40 it != sys_info.end(); 44 it != sys_info.end();
41 ++it) { 45 ++it) {
42 std::string key = it->first; 46 std::string key = it->first;
43 std::string value = it->second; 47 std::string value = it->second;
44 48
45 if (FeedbackCommon::BelowCompressionThreshold(value)) 49 if (FeedbackCommon::BelowCompressionThreshold(value))
46 continue; 50 continue;
47 51
48 base::TrimString(key, "\n ", &key); 52 base::TrimString(key, "\n ", &key);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 userfeedback::ProductSpecificBinaryData* attachment = 87 userfeedback::ProductSpecificBinaryData* attachment =
84 feedback_data->add_product_specific_binary_data(); 88 feedback_data->add_product_specific_binary_data();
85 attachment->set_mime_type(kArbitraryMimeType); 89 attachment->set_mime_type(kArbitraryMimeType);
86 attachment->set_name(name); 90 attachment->set_name(name);
87 attachment->set_data(data); 91 attachment->set_data(data);
88 } 92 }
89 93
90 } // namespace 94 } // namespace
91 95
92 FeedbackCommon::AttachedFile::AttachedFile(const std::string& filename, 96 FeedbackCommon::AttachedFile::AttachedFile(const std::string& filename,
93 scoped_ptr<std::string> data) 97 std::unique_ptr<std::string> data)
94 : name(filename), data(std::move(data)) {} 98 : name(filename), data(std::move(data)) {}
95 99
96 FeedbackCommon::AttachedFile::~AttachedFile() {} 100 FeedbackCommon::AttachedFile::~AttachedFile() {}
97 101
98 102
99 FeedbackCommon::FeedbackCommon() : product_id_(0) {} 103 FeedbackCommon::FeedbackCommon() : product_id_(0) {}
100 104
101 FeedbackCommon::~FeedbackCommon() {} 105 FeedbackCommon::~FeedbackCommon() {}
102 106
103 // static 107 // static
104 bool FeedbackCommon::BelowCompressionThreshold(const std::string& content) { 108 bool FeedbackCommon::BelowCompressionThreshold(const std::string& content) {
105 if (content.length() > kFeedbackMaxLength) 109 if (content.length() > kFeedbackMaxLength)
106 return false; 110 return false;
107 const size_t line_count = std::count(content.begin(), content.end(), '\n'); 111 const size_t line_count = std::count(content.begin(), content.end(), '\n');
108 if (line_count > kFeedbackMaxLineCount) 112 if (line_count > kFeedbackMaxLineCount)
109 return false; 113 return false;
110 return true; 114 return true;
111 } 115 }
112 116
113 void FeedbackCommon::CompressFile(const base::FilePath& filename, 117 void FeedbackCommon::CompressFile(const base::FilePath& filename,
114 const std::string& zipname, 118 const std::string& zipname,
115 scoped_ptr<std::string> data) { 119 std::unique_ptr<std::string> data) {
116 AttachedFile* file = new AttachedFile( 120 std::unique_ptr<AttachedFile> file(
117 zipname, scoped_ptr<std::string>(new std::string())); 121 new AttachedFile(zipname, base::WrapUnique(new std::string())));
118 if (file->name.empty()) { 122 if (file->name.empty()) {
119 // We need to use the UTF8Unsafe methods here to accomodate Windows, which 123 // We need to use the UTF8Unsafe methods here to accomodate Windows, which
120 // uses wide strings to store filepaths. 124 // uses wide strings to store filepaths.
121 file->name = filename.BaseName().AsUTF8Unsafe(); 125 file->name = filename.BaseName().AsUTF8Unsafe();
122 file->name.append(kZipExt); 126 file->name.append(kZipExt);
123 } 127 }
124 if (feedback_util::ZipString(filename, *(data.get()), file->data.get())) { 128 if (feedback_util::ZipString(filename, *data, file->data.get())) {
125 base::AutoLock lock(attachments_lock_); 129 base::AutoLock lock(attachments_lock_);
126 attachments_.push_back(file); 130 attachments_.push_back(file.release());
127 } else {
128 delete file;
129 } 131 }
130 } 132 }
131 133
132 void FeedbackCommon::AddFile(const std::string& filename, 134 void FeedbackCommon::AddFile(const std::string& filename,
133 scoped_ptr<std::string> data) { 135 std::unique_ptr<std::string> data) {
134 base::AutoLock lock(attachments_lock_); 136 base::AutoLock lock(attachments_lock_);
135 attachments_.push_back(new AttachedFile(filename, std::move(data))); 137 attachments_.push_back(new AttachedFile(filename, std::move(data)));
136 } 138 }
137 139
138 void FeedbackCommon::AddLog(const std::string& name, const std::string& value) { 140 void FeedbackCommon::AddLog(const std::string& name, const std::string& value) {
139 if (!logs_.get()) 141 if (!logs_.get())
140 logs_ = scoped_ptr<SystemLogsMap>(new SystemLogsMap); 142 logs_ = base::WrapUnique(new SystemLogsMap);
141 (*logs_.get())[name] = value; 143 (*logs_)[name] = value;
142 } 144 }
143 145
144 void FeedbackCommon::AddLogs(scoped_ptr<SystemLogsMap> logs) { 146 void FeedbackCommon::AddLogs(std::unique_ptr<SystemLogsMap> logs) {
145 if (logs_) { 147 if (logs_) {
146 logs_->insert(logs->begin(), logs->end()); 148 logs_->insert(logs->begin(), logs->end());
147 } else { 149 } else {
148 logs_ = std::move(logs); 150 logs_ = std::move(logs);
149 } 151 }
150 } 152 }
151 153
152 void FeedbackCommon::CompressLogs() { 154 void FeedbackCommon::CompressLogs() {
153 if (!logs_) 155 if (!logs_)
154 return; 156 return;
155 std::string* logs = LogsToString(*logs_.get()); 157 std::unique_ptr<std::string> logs = LogsToString(*logs_);
156 if (!logs->empty()) 158 if (!logs->empty()) {
157 CompressFile( 159 CompressFile(base::FilePath(kLogsFilename), kLogsAttachmentName,
158 base::FilePath(kLogsFilename), kLogsAttachmentName, 160 std::move(logs));
159 scoped_ptr<std::string>(logs)); 161 }
160 } 162 }
161 163
162 void FeedbackCommon::AddFilesAndLogsToReport( 164 void FeedbackCommon::AddFilesAndLogsToReport(
163 userfeedback::ExtensionSubmit* feedback_data) const { 165 userfeedback::ExtensionSubmit* feedback_data) const {
164 if (sys_info()) { 166 if (sys_info()) {
165 for (FeedbackCommon::SystemLogsMap::const_iterator i = sys_info()->begin(); 167 for (FeedbackCommon::SystemLogsMap::const_iterator i = sys_info()->begin();
166 i != sys_info()->end(); 168 i != sys_info()->end();
167 ++i) { 169 ++i) {
168 if (BelowCompressionThreshold(i->second)) 170 if (BelowCompressionThreshold(i->second))
169 AddFeedbackData(feedback_data, i->first, i->second); 171 AddFeedbackData(feedback_data, i->first, i->second);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 209
208 *(screenshot.mutable_dimensions()) = dimensions; 210 *(screenshot.mutable_dimensions()) = dimensions;
209 screenshot.set_binary_content(*image()); 211 screenshot.set_binary_content(*image());
210 212
211 *(feedback_data->mutable_screenshot()) = screenshot; 213 *(feedback_data->mutable_screenshot()) = screenshot;
212 } 214 }
213 215
214 if (category_tag().size()) 216 if (category_tag().size())
215 feedback_data->set_bucket(category_tag()); 217 feedback_data->set_bucket(category_tag());
216 } 218 }
OLDNEW
« no previous file with comments | « components/feedback/feedback_common.h ('k') | components/feedback/feedback_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698