OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/host/host_event_logger.h" | 5 #include "remoting/host/host_event_logger.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 HANDLE event_log_; | 52 HANDLE event_log_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); | 54 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); |
55 }; | 55 }; |
56 | 56 |
57 } //namespace | 57 } //namespace |
58 | 58 |
59 HostEventLoggerWin::HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor, | 59 HostEventLoggerWin::HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor, |
60 const std::string& application_name) | 60 const std::string& application_name) |
61 : monitor_(monitor), | 61 : monitor_(monitor), |
62 event_log_(NULL) { | 62 event_log_(nullptr) { |
63 event_log_ = RegisterEventSourceW( | 63 event_log_ = RegisterEventSourceW( |
64 NULL, base::UTF8ToUTF16(application_name).c_str()); | 64 nullptr, base::UTF8ToUTF16(application_name).c_str()); |
65 if (event_log_ != NULL) { | 65 if (event_log_ != nullptr) { |
66 monitor_->AddStatusObserver(this); | 66 monitor_->AddStatusObserver(this); |
67 } else { | 67 } else { |
68 PLOG(ERROR) << "Failed to register the event source: " << application_name; | 68 PLOG(ERROR) << "Failed to register the event source: " << application_name; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 HostEventLoggerWin::~HostEventLoggerWin() { | 72 HostEventLoggerWin::~HostEventLoggerWin() { |
73 if (event_log_ != NULL) { | 73 if (event_log_ != nullptr) { |
74 if (monitor_) | 74 if (monitor_) |
75 monitor_->RemoveStatusObserver(this); | 75 monitor_->RemoveStatusObserver(this); |
76 DeregisterEventSource(event_log_); | 76 DeregisterEventSource(event_log_); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { | 80 void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { |
81 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid); | 81 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid); |
82 } | 82 } |
83 | 83 |
(...skipping 22 matching lines...) Expand all Loading... |
106 // TODO(rmsousa): Fix host shutdown to actually call this, and add a log line. | 106 // TODO(rmsousa): Fix host shutdown to actually call this, and add a log line. |
107 } | 107 } |
108 | 108 |
109 void HostEventLoggerWin::OnStart(const std::string& xmpp_login) { | 109 void HostEventLoggerWin::OnStart(const std::string& xmpp_login) { |
110 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_STARTED, xmpp_login); | 110 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_STARTED, xmpp_login); |
111 } | 111 } |
112 | 112 |
113 void HostEventLoggerWin::Log(WORD type, | 113 void HostEventLoggerWin::Log(WORD type, |
114 DWORD event_id, | 114 DWORD event_id, |
115 const std::vector<std::string>& strings) { | 115 const std::vector<std::string>& strings) { |
116 if (event_log_ == NULL) | 116 if (event_log_ == nullptr) |
117 return; | 117 return; |
118 | 118 |
119 // ReportEventW() takes an array of raw string pointers. They should stay | 119 // ReportEventW() takes an array of raw string pointers. They should stay |
120 // valid for the duration of the call. | 120 // valid for the duration of the call. |
121 std::vector<const WCHAR*> raw_strings(strings.size()); | 121 std::vector<const WCHAR*> raw_strings(strings.size()); |
122 std::vector<base::string16> utf16_strings(strings.size()); | 122 std::vector<base::string16> utf16_strings(strings.size()); |
123 for (size_t i = 0; i < strings.size(); ++i) { | 123 for (size_t i = 0; i < strings.size(); ++i) { |
124 utf16_strings[i] = base::UTF8ToUTF16(strings[i]); | 124 utf16_strings[i] = base::UTF8ToUTF16(strings[i]); |
125 raw_strings[i] = utf16_strings[i].c_str(); | 125 raw_strings[i] = utf16_strings[i].c_str(); |
126 } | 126 } |
127 | 127 |
128 if (!ReportEventW(event_log_, | 128 if (!ReportEventW(event_log_, |
129 type, | 129 type, |
130 HOST_CATEGORY, | 130 HOST_CATEGORY, |
131 event_id, | 131 event_id, |
132 NULL, | 132 nullptr, |
133 static_cast<WORD>(raw_strings.size()), | 133 static_cast<WORD>(raw_strings.size()), |
134 0, | 134 0, |
135 &raw_strings[0], | 135 &raw_strings[0], |
136 NULL)) { | 136 nullptr)) { |
137 PLOG(ERROR) << "Failed to write an event to the event log"; | 137 PLOG(ERROR) << "Failed to write an event to the event log"; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 void HostEventLoggerWin::LogString(WORD type, | 141 void HostEventLoggerWin::LogString(WORD type, |
142 DWORD event_id, | 142 DWORD event_id, |
143 const std::string& string) { | 143 const std::string& string) { |
144 std::vector<std::string> strings; | 144 std::vector<std::string> strings; |
145 strings.push_back(string); | 145 strings.push_back(string); |
146 Log(type, event_id, strings); | 146 Log(type, event_id, strings); |
147 } | 147 } |
148 | 148 |
149 // static | 149 // static |
150 scoped_ptr<HostEventLogger> HostEventLogger::Create( | 150 scoped_ptr<HostEventLogger> HostEventLogger::Create( |
151 base::WeakPtr<HostStatusMonitor> monitor, | 151 base::WeakPtr<HostStatusMonitor> monitor, |
152 const std::string& application_name) { | 152 const std::string& application_name) { |
153 return make_scoped_ptr(new HostEventLoggerWin(monitor, application_name)); | 153 return make_scoped_ptr(new HostEventLoggerWin(monitor, application_name)); |
154 } | 154 } |
155 | 155 |
156 } // namespace remoting | 156 } // namespace remoting |
OLD | NEW |