summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/log_private
diff options
context:
space:
mode:
authortnagel@chromium.org <tnagel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 21:12:57 +0000
committertnagel@chromium.org <tnagel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 21:12:57 +0000
commitc3701ebc95bef612f6cb8250390f348aae4cd0a1 (patch)
tree6c6e8dd36a86f1225ee24a59989cf93d96c0692b /chrome/browser/extensions/api/log_private
parent37833cee2f1a320c22d0eda7d2444e9dbde6878c (diff)
downloadchromium_src-c3701ebc95bef612f6cb8250390f348aae4cd0a1.zip
chromium_src-c3701ebc95bef612f6cb8250390f348aae4cd0a1.tar.gz
chromium_src-c3701ebc95bef612f6cb8250390f348aae4cd0a1.tar.bz2
Extend PR_ParseTimeString() to accept some ISO 8601 formats to fix timezone parsing in SyslogParser.
Previously, SyslogParser::ParseTime() would parse time, reformat it in a way that is understood by NSPR and then hand it off to PR_ParseTimeString() where it is parsed again. This double-parsing is unnecessarily convoluted and slow. Extending PR_ParseTimeString() simplifies and speeds up SyslogParser::ParseTime() which is time-critical in case of large log files. BUG=370509 Review URL: https://codereview.chromium.org/266193002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/log_private')
-rw-r--r--chrome/browser/extensions/api/log_private/syslog_parser.cc30
-rw-r--r--chrome/browser/extensions/api/log_private/syslog_parser_unittest.cc35
2 files changed, 19 insertions, 46 deletions
diff --git a/chrome/browser/extensions/api/log_private/syslog_parser.cc b/chrome/browser/extensions/api/log_private/syslog_parser.cc
index 5479886..4f26653 100644
--- a/chrome/browser/extensions/api/log_private/syslog_parser.cc
+++ b/chrome/browser/extensions/api/log_private/syslog_parser.cc
@@ -23,8 +23,6 @@ namespace extensions {
namespace {
-const int kExpectedTimeTokenNum = 7;
-const char kLogEntryDelimiters[] = "-:T";
const char kProcessInfoDelimiters[] = "[]";
} // namespace
@@ -71,39 +69,15 @@ SyslogParser::Error SyslogParser::ParseEntry(
return SyslogParser::SUCCESS;
}
-SyslogParser::Error ParseTimeHelper(base::StringTokenizer* tokenizer,
- std::string* output) {
- if (!tokenizer->GetNext()) {
- LOG(ERROR) << "Error when parsing time";
- return SyslogParser::PARSE_ERROR;
- }
- *output = tokenizer->token();
- return SyslogParser::SUCCESS;
-}
-
SyslogParser::Error SyslogParser::ParseTime(const std::string& input,
double* output) const {
- base::StringTokenizer tokenizer(input, kLogEntryDelimiters);
- std::string tokens[kExpectedTimeTokenNum];
- for (int i = 0; i < kExpectedTimeTokenNum; i++) {
- if (ParseTimeHelper(&tokenizer, &(tokens[i])) != SyslogParser::SUCCESS)
- return SyslogParser::PARSE_ERROR;
- }
-
- std::string buffer = tokens[1] + '-' + tokens[2] + '-' + tokens[0] + ' ' +
- tokens[3] + ':' + tokens[4] + ":00";
-
base::Time parsed_time;
- if (!base::Time::FromString(buffer.c_str(), &parsed_time)) {
+ if (!base::Time::FromString(input.c_str(), &parsed_time)) {
LOG(ERROR) << "Error when parsing time";
return SyslogParser::PARSE_ERROR;
}
- double seconds;
- base::StringToDouble(tokens[5], &seconds);
- *output = parsed_time.ToJsTime() +
- (seconds * base::Time::kMillisecondsPerSecond);
-
+ *output = parsed_time.ToJsTime();
return SyslogParser::SUCCESS;
}
diff --git a/chrome/browser/extensions/api/log_private/syslog_parser_unittest.cc b/chrome/browser/extensions/api/log_private/syslog_parser_unittest.cc
index 2c0b8f0..2830818 100644
--- a/chrome/browser/extensions/api/log_private/syslog_parser_unittest.cc
+++ b/chrome/browser/extensions/api/log_private/syslog_parser_unittest.cc
@@ -2,28 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <stdio.h>
#include <string>
#include <vector>
-#include "base/json/json_writer.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
+#include "base/memory/linked_ptr.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h"
-#include "chrome/browser/extensions/api/log_private/log_private_api.h"
+#include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/api/log_private/syslog_parser.h"
-#include "chrome/common/extensions/api/log_private.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
const char kShillLogEntry[] =
- "2013-07-08T11:28:12.440308-07:00 localhost shill:"
+ "2013-07-08T11:28:12.440308+02:00 localhost shill:"
"[0708/112812:ERROR:manager.cc(480)] Skipping unload of service";
const char kWpaSupplicantLogEntry[] =
- "2013-07-08T12:39:07.443100-07:00 localhost wpa_supplicant[894]:"
+ "2013-07-18T12:39:07.443100-07:00 localhost wpa_supplicant[894]:"
"dbus: Failed to construct signal";
} // namespace
@@ -38,18 +34,21 @@ TEST_F(ExtensionSyslogParserTest, ParseLog) {
SyslogParser p;
// Test shill log
p.Parse(kShillLogEntry, &output, &filter_handler);
- EXPECT_STREQ(output[0]->level.c_str(), "error");
- EXPECT_STREQ(output[0]->process.c_str(), "shill:");
- EXPECT_STREQ(output[0]->process_id.c_str(), "unknown");
- EXPECT_STREQ(output[0]->full_entry.c_str(), kShillLogEntry);
- EXPECT_EQ(output[0]->timestamp, 1373308092440.308);
+ ASSERT_EQ(1u, output.size());
+ EXPECT_STREQ("error", output[0]->level.c_str());
+ EXPECT_STREQ("shill:", output[0]->process.c_str());
+ EXPECT_STREQ("unknown", output[0]->process_id.c_str());
+ EXPECT_STREQ(kShillLogEntry, output[0]->full_entry.c_str());
+ EXPECT_DOUBLE_EQ(1373275692440.308, output[0]->timestamp);
+
// Test WpaSupplicant log
p.Parse(kWpaSupplicantLogEntry, &output, &filter_handler);
- EXPECT_STREQ(output[1]->level.c_str(), "unknown");
- EXPECT_STREQ(output[1]->process.c_str(), "wpa_supplicant");
- EXPECT_STREQ(output[1]->process_id.c_str(), "894");
- EXPECT_STREQ(output[1]->full_entry.c_str(), kWpaSupplicantLogEntry);
- EXPECT_EQ(output[1]->timestamp, 1373312347443.1);
+ ASSERT_EQ(2u, output.size());
+ EXPECT_STREQ("unknown", output[1]->level.c_str());
+ EXPECT_STREQ("wpa_supplicant", output[1]->process.c_str());
+ EXPECT_STREQ("894", output[1]->process_id.c_str());
+ EXPECT_STREQ(kWpaSupplicantLogEntry, output[1]->full_entry.c_str());
+ EXPECT_DOUBLE_EQ(1374176347443.1, output[1]->timestamp);
}
} // namespace extensions