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

Unified Diff: components/device_event_log/device_event_log_impl.cc

Issue 919183002: Move chromeos::device_event_log into components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shut down in PostDestroyThreads. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/device_event_log/device_event_log_impl.cc
diff --git a/chromeos/device_event_log_impl.cc b/components/device_event_log/device_event_log_impl.cc
similarity index 91%
rename from chromeos/device_event_log_impl.cc
rename to components/device_event_log/device_event_log_impl.cc
index 8df670b73d9f5fd89797710716b93eb7c0898168..b2609914e5687c683038a9f4d7e68cb9f3e401a0 100644
--- a/chromeos/device_event_log_impl.cc
+++ b/components/device_event_log/device_event_log_impl.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chromeos/device_event_log_impl.h"
+#include "components/device_event_log/device_event_log_impl.h"
#include <cmath>
#include <list>
#include <set>
-#include "base/files/file_path.h"
+#include "base/containers/adapters.h"
#include "base/json/json_string_value_serializer.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
@@ -20,8 +20,6 @@
#include "base/values.h"
#include "net/base/escape.h"
-namespace chromeos {
-
namespace device_event_log {
namespace {
@@ -325,32 +323,30 @@ std::string DeviceEventLogImpl::GetAsString(StringOrder order,
// determine the first entry to include.
size_t shown_events = 0;
size_t num_entries = 0;
- for (LogEntryList::const_reverse_iterator riter = entries_.rbegin();
- riter != entries_.rend(); ++riter) {
+ for (const LogEntry& entry : base::Reversed(entries_)) {
++num_entries;
- if (!LogEntryMatchesTypes(*riter, include_types, exclude_types))
+ if (!LogEntryMatchesTypes(entry, include_types, exclude_types))
continue;
- if (riter->log_level > max_level)
+ if (entry.log_level > max_level)
continue;
if (++shown_events >= max_events)
break;
}
offset = entries_.size() - num_entries;
}
- for (LogEntryList::const_iterator iter = entries_.begin();
- iter != entries_.end(); ++iter) {
+ for (const LogEntry& entry : entries_) {
if (offset > 0) {
--offset;
continue;
}
- if (!LogEntryMatchesTypes(*iter, include_types, exclude_types))
+ if (!LogEntryMatchesTypes(entry, include_types, exclude_types))
continue;
- if (iter->log_level > max_level)
+ if (entry.log_level > max_level)
continue;
if (format_json) {
- log_entries.AppendString(LogEntryAsJSON(*iter));
+ log_entries.AppendString(LogEntryAsJSON(entry));
} else {
- result += LogEntryToString(*iter, show_time, show_file, show_type,
+ result += LogEntryToString(entry, show_time, show_file, show_type,
show_level, format_html);
result += "\n";
}
@@ -358,16 +354,15 @@ std::string DeviceEventLogImpl::GetAsString(StringOrder order,
} else {
size_t nlines = 0;
// Iterate backwards through the list to show the most recent entries first.
- for (LogEntryList::const_reverse_iterator riter = entries_.rbegin();
- riter != entries_.rend(); ++riter) {
- if (!LogEntryMatchesTypes(*riter, include_types, exclude_types))
+ for (const LogEntry& entry : base::Reversed(entries_)) {
+ if (!LogEntryMatchesTypes(entry, include_types, exclude_types))
continue;
- if (riter->log_level > max_level)
+ if (entry.log_level > max_level)
continue;
if (format_json) {
- log_entries.AppendString(LogEntryAsJSON(*riter));
+ log_entries.AppendString(LogEntryAsJSON(entry));
} else {
- result += LogEntryToString(*riter, show_time, show_file, show_type,
+ result += LogEntryToString(entry, show_time, show_file, show_type,
show_level, format_html);
result += "\n";
}
@@ -394,10 +389,13 @@ DeviceEventLogImpl::LogEntry::LogEntry(const char* filedesc,
event(event),
time(base::Time::Now()),
count(1) {
- if (filedesc)
- file = base::FilePath(std::string(filedesc)).BaseName().value();
+ if (filedesc) {
+ file = filedesc;
+ size_t last_slash_pos = file.find_last_of("\\/");
+ if (last_slash_pos != std::string::npos) {
+ file.erase(0, last_slash_pos + 1);
+ }
+ }
}
} // namespace device_event_log
-
-} // namespace chromeos
« no previous file with comments | « components/device_event_log/device_event_log_impl.h ('k') | components/device_event_log/device_event_log_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698