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

Side by Side Diff: remoting/host/host_event_logger_win.cc

Issue 9567010: Making the me2me host compiling and running on Windows. This includes making it a window applicatio… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/host_event_logger_linux.cc ('k') | remoting/host/remoting_host_messages.mc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/host_event_logger.h"
6
7 #include <windows.h>
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14 #include "base/utf_string_conversions.h"
15 #include "net/base/ip_endpoint.h"
16 #include "remoting/host/chromoting_host.h"
17 #include "remoting/host/host_status_observer.h"
18
19 #include "remoting_host_messages.h"
20
21 namespace remoting {
22
23 namespace {
24
25 class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver {
26 public:
27 HostEventLoggerWin(ChromotingHost* host,
28 const std::string& application_name);
29
30 virtual ~HostEventLoggerWin();
31
32 // HostStatusObserver implementation. These methods will be called from the
33 // network thread.
34 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE;
35 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;
36 virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
37 virtual void OnClientRouteChange(
38 const std::string& jid,
39 const std::string& channel_name,
40 const net::IPEndPoint& remote_end_point,
41 const net::IPEndPoint& local_end_point) OVERRIDE;
42 virtual void OnShutdown() OVERRIDE;
43
44 private:
45 void LogString(WORD type, DWORD event_id, const std::string& string);
46 void Log(WORD type, DWORD event_id, const std::vector<string16>& strings);
47
48 scoped_refptr<ChromotingHost> host_;
49
50 // The handle of the application event log.
51 HANDLE event_log_;
52
53 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin);
54 };
55
56 } //namespace
57
58 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host,
59 const std::string& application_name)
60 : host_(host),
61 event_log_(NULL) {
62 event_log_ = RegisterEventSourceW(NULL,
63 ASCIIToUTF16(application_name).c_str());
64 if (event_log_ != NULL) {
65 host_->AddStatusObserver(this);
66 } else {
67 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: "
68 << application_name;
69 }
70 }
71
72 HostEventLoggerWin::~HostEventLoggerWin() {
73 if (event_log_ != NULL) {
74 host_->RemoveStatusObserver(this);
75 DeregisterEventSource(event_log_);
76 }
77 }
78
79 void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) {
80 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid);
81 }
82
83 void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) {
84 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid);
85 }
86
87 void HostEventLoggerWin::OnAccessDenied(const std::string& jid) {
88 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid);
89 }
90
91 void HostEventLoggerWin::OnClientRouteChange(
92 const std::string& jid,
93 const std::string& channel_name,
94 const net::IPEndPoint& remote_end_point,
95 const net::IPEndPoint& local_end_point) {
96 std::vector<string16> strings(4);
97 strings[0] = ASCIIToUTF16(jid);
98 strings[1] = ASCIIToUTF16(remote_end_point.ToString());
99 strings[2] = ASCIIToUTF16(local_end_point.ToString());
100 strings[3] = ASCIIToUTF16(channel_name);
101 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings);
102 }
103
104 void HostEventLoggerWin::OnShutdown() {
105 }
106
107 void HostEventLoggerWin::Log(WORD type,
108 DWORD event_id,
109 const std::vector<string16>& strings) {
110 if (event_log_ == NULL)
111 return;
112
113 // ReportEventW() takes an array of raw string pointers. They should stay
114 // valid for the duration of the call.
115 std::vector<const WCHAR*> raw_strings(strings.size());
116 for (size_t i = 0; i < strings.size(); ++i) {
117 raw_strings[i] = strings[i].c_str();
118 }
119
120 if (!ReportEventW(event_log_,
121 type,
122 HOST_CATEGORY,
123 event_id,
124 NULL,
125 static_cast<WORD>(raw_strings.size()),
126 0,
127 &raw_strings[0],
128 NULL)) {
129 LOG_GETLASTERROR(ERROR) << "Failed to write an event to the event log";
130 }
131 }
132
133 void HostEventLoggerWin::LogString(WORD type,
134 DWORD event_id,
135 const std::string& string) {
136 std::vector<string16> strings;
137 strings.push_back(ASCIIToUTF16(string));
138 Log(type, event_id, strings);
139 }
140
141 // static
142 scoped_ptr<HostEventLogger> HostEventLogger::Create(
143 ChromotingHost* host, const std::string& application_name) {
144 return scoped_ptr<HostEventLogger>(
145 new HostEventLoggerWin(host, application_name));
146 }
147
148 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_event_logger_linux.cc ('k') | remoting/host/remoting_host_messages.mc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698