Commit 9e214733 authored by Anqing Zhao's avatar Anqing Zhao Committed by Commit Bot

Extract CheckCsvUploadListOutOfRange to an independent method

Before supporting a new json format for uploads.log file, it's worthy to
extract the cleanup codes for CSV format to an independent method. It
can improve the readability.

Bug: 1040078
Change-Id: I661bf875f799a6d56875b890c22f1fb1730c8d9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2057763
Commit-Queue: Anqing Zhao <anqing@google.com>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747150}
parent 735e0d29
......@@ -27,6 +27,32 @@ std::vector<std::string> SplitIntoComponents(const std::string& line) {
base::SPLIT_WANT_ALL);
}
bool CheckCsvUploadListOutOfRange(const std::string& line,
const base::Time& begin,
const base::Time& end) {
std::vector<std::string> components = SplitIntoComponents(line);
double seconds_since_epoch;
if (components.size() > kUploadTimeIndex &&
!components[kUploadTimeIndex].empty() &&
base::StringToDouble(components[kUploadTimeIndex],
&seconds_since_epoch)) {
base::Time upload_time = base::Time::FromDoubleT(seconds_since_epoch);
if (begin <= upload_time && upload_time <= end)
return false;
}
if (components.size() > kCaptureTimeIndex &&
!components[kCaptureTimeIndex].empty() &&
base::StringToDouble(components[kCaptureTimeIndex],
&seconds_since_epoch)) {
base::Time capture_time = base::Time::FromDoubleT(seconds_since_epoch);
if (begin <= capture_time && capture_time <= end)
return false;
}
return true;
}
// Tries to parse one upload log line based on CSV format, then converts it to
// a UploadInfo entry. If the conversion succeeds, it returns true and a valid
// |info|. Otherwise, it returns false.
......@@ -98,26 +124,7 @@ void TextLogUploadList::ClearUploadList(const base::Time& begin,
std::ostringstream new_contents_stream;
for (const std::string& line : log_entries) {
std::vector<std::string> components = SplitIntoComponents(line);
double seconds_since_epoch;
if (components.size() > kUploadTimeIndex &&
!components[kUploadTimeIndex].empty() &&
base::StringToDouble(components[kUploadTimeIndex],
&seconds_since_epoch)) {
base::Time upload_time = base::Time::FromDoubleT(seconds_since_epoch);
if (begin <= upload_time && upload_time <= end)
continue;
}
if (components.size() > kCaptureTimeIndex &&
!components[kCaptureTimeIndex].empty() &&
base::StringToDouble(components[kCaptureTimeIndex],
&seconds_since_epoch)) {
base::Time capture_time = base::Time::FromDoubleT(seconds_since_epoch);
if (begin <= capture_time && capture_time <= end)
continue;
}
if (CheckCsvUploadListOutOfRange(line, begin, end))
new_contents_stream << line << std::endl;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment