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

Side by Side Diff: components/device_event_log/device_event_log_impl.cc

Issue 941063003: Log device/usb messages to chrome://device-log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and adjust log levels. 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 unified diff | Download patch
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/device_event_log/device_event_log_impl.h" 5 #include "components/device_event_log/device_event_log_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <list> 8 #include <list>
9 #include <set> 9 #include <set>
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 namespace device_event_log { 23 namespace device_event_log {
24 24
25 namespace { 25 namespace {
26 26
27 const char* kLogLevelName[] = {"Error", "User", "Event", "Debug"}; 27 const char* kLogLevelName[] = {"Error", "User", "Event", "Debug"};
28 28
29 const char* kLogTypeNetworkDesc = "Network"; 29 const char* kLogTypeNetworkDesc = "Network";
30 const char* kLogTypePowerDesc = "Power"; 30 const char* kLogTypePowerDesc = "Power";
31 const char* kLogTypeLoginDesc = "Login"; 31 const char* kLogTypeLoginDesc = "Login";
32 const char* kLogTypeUsbDesc = "USB";
32 33
33 std::string GetLogTypeString(LogType type) { 34 std::string GetLogTypeString(LogType type) {
34 if (type == LOG_TYPE_NETWORK) 35 switch (type) {
35 return kLogTypeNetworkDesc; 36 case LOG_TYPE_NETWORK:
36 if (type == LOG_TYPE_POWER) 37 return kLogTypeNetworkDesc;
37 return kLogTypePowerDesc; 38 case LOG_TYPE_POWER:
38 if (type == LOG_TYPE_LOGIN) 39 return kLogTypePowerDesc;
39 return kLogTypeLoginDesc; 40 case LOG_TYPE_LOGIN:
40 NOTREACHED(); 41 return kLogTypeLoginDesc;
41 return "Unknown"; 42 case LOG_TYPE_USB:
43 return kLogTypeUsbDesc;
44 default:
45 NOTREACHED();
46 return "Unknown";
47 }
42 } 48 }
43 49
44 std::string DateAndTimeWithMicroseconds(const base::Time& time) { 50 std::string DateAndTimeWithMicroseconds(const base::Time& time) {
45 base::Time::Exploded exploded; 51 base::Time::Exploded exploded;
46 time.LocalExplode(&exploded); 52 time.LocalExplode(&exploded);
47 // base::Time::Exploded does not include microseconds, but sometimes we need 53 // base::Time::Exploded does not include microseconds, but sometimes we need
48 // microseconds, so append '.' + usecs to the end of the formatted string. 54 // microseconds, so append '.' + usecs to the end of the formatted string.
49 int usecs = static_cast<int>(fmod(time.ToDoubleT() * 1000000, 1000000)); 55 int usecs = static_cast<int>(fmod(time.ToDoubleT() * 1000000, 1000000));
50 return base::StringPrintf("%04d/%02d/%02d %02d:%02d:%02d.%06d", exploded.year, 56 return base::StringPrintf("%04d/%02d/%02d %02d:%02d:%02d.%06d", exploded.year,
51 exploded.month, exploded.day_of_month, 57 exploded.month, exploded.day_of_month,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 if (filedesc) { 398 if (filedesc) {
393 file = filedesc; 399 file = filedesc;
394 size_t last_slash_pos = file.find_last_of("\\/"); 400 size_t last_slash_pos = file.find_last_of("\\/");
395 if (last_slash_pos != std::string::npos) { 401 if (last_slash_pos != std::string::npos) {
396 file.erase(0, last_slash_pos + 1); 402 file.erase(0, last_slash_pos + 1);
397 } 403 }
398 } 404 }
399 } 405 }
400 406
401 } // namespace device_event_log 407 } // namespace device_event_log
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698