Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
19 #include "PluginDebug.h" | 19 #include "PluginDebug.h" |
20 #include "PluginClientBase.h" | |
20 #include "PluginMutex.h" | 21 #include "PluginMutex.h" |
21 #include "PluginClient.h" | 22 #include "PluginClientBase.h" |
22 #include "../shared/Utils.h" | 23 #include "../shared/Utils.h" |
23 #include <iomanip> | 24 #include <iomanip> |
25 #include <memory> | |
24 | 26 |
25 namespace | 27 namespace |
26 { | 28 { |
27 class CPluginDebugLock | 29 class CPluginDebugLock |
28 : public CPluginMutex | 30 : public CPluginMutex |
29 { | 31 { |
30 private: | 32 private: |
31 static CComAutoCriticalSection s_criticalSectionDebugLock; | 33 static CComAutoCriticalSection s_criticalSectionDebugLock; |
32 | 34 |
33 public: | 35 public: |
34 CPluginDebugLock() | 36 CPluginDebugLock() |
35 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) | 37 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) |
36 { | 38 { |
37 s_criticalSectionDebugLock.Lock(); | 39 s_criticalSectionDebugLock.Lock(); |
38 } | 40 } |
39 | 41 |
40 ~CPluginDebugLock() | 42 ~CPluginDebugLock() |
41 { | 43 { |
42 s_criticalSectionDebugLock.Unlock(); | 44 s_criticalSectionDebugLock.Unlock(); |
43 } | 45 } |
44 }; | 46 }; |
45 | 47 |
46 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; | 48 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; |
47 | 49 |
48 class LogText | 50 class LogText |
49 { | 51 { |
50 public: | 52 public: |
51 virtual std::string Text() const = 0; | 53 virtual std::string Text() const = 0; |
54 virtual ~LogText() {}; | |
52 }; | 55 }; |
53 | 56 |
54 class LogTextFixed | 57 class LogTextFixed |
sergei
2015/12/02 13:53:00
What about naming of classes differently?
Let's a
Eric
2015/12/02 15:01:24
No.
Naming the subclasses of 'class LogText' with
| |
55 : public LogText | 58 : public LogText |
56 { | 59 { |
57 protected: | 60 protected: |
58 const std::string fixedText; | 61 const std::string fixedText; |
59 | 62 |
60 public: | 63 public: |
61 explicit LogTextFixed(const std::string& text) | 64 explicit LogTextFixed(const std::string& text) |
62 : fixedText(text) | 65 : fixedText(text) |
63 {} | 66 {} |
64 | 67 |
65 explicit LogTextFixed(const std::exception& ex) | 68 explicit LogTextFixed(const std::exception& ex) |
66 : fixedText(std::string("!!! Exception: ") + ex.what()) | 69 : fixedText(std::string("!!! Exception: ") + ex.what()) |
67 {} | 70 {} |
68 | 71 |
69 virtual std::string Text() const override | 72 virtual std::string Text() const override |
sergei
2015/11/30 14:15:03
I would propose to omit `virtual` when we use `ove
Eric
2015/11/30 17:39:01
It's good to have both in place. Makes the intent
sergei
2015/11/30 18:14:29
Actually, I would like to note that it's not relat
Eric
2015/12/01 20:43:58
OK.
| |
70 { | 73 { |
71 return fixedText; | 74 return fixedText; |
72 } | 75 } |
73 }; | 76 }; |
74 | 77 |
75 class LogTextErrorCode | 78 class LogTextErrorCode |
76 : public LogTextFixed | 79 : public LogTextFixed |
77 { | 80 { |
78 protected: | 81 protected: |
79 const DWORD errorCode; | 82 const DWORD errorCode; |
(...skipping 20 matching lines...) Expand all Loading... | |
100 : public SYSTEMTIME | 103 : public SYSTEMTIME |
101 { | 104 { |
102 SystemTime() | 105 SystemTime() |
103 { | 106 { |
104 ::GetSystemTime(static_cast<SYSTEMTIME*>(this)); | 107 ::GetSystemTime(static_cast<SYSTEMTIME*>(this)); |
105 } | 108 } |
106 }; | 109 }; |
107 | 110 |
108 class LogEntry | 111 class LogEntry |
109 { | 112 { |
110 const std::unique_ptr<LogText> text; | 113 const std::unique_ptr<LogText> text; |
sergei
2015/12/02 13:53:00
Just in case, what is the reason of extensively pu
Eric
2015/12/02 15:01:24
'const' members mean "initialized only at construc
| |
111 | 114 |
112 std::string InitialPrefix() const | 115 std::string InitialPrefix() const |
113 { | 116 { |
114 std::stringstream ss; | 117 std::stringstream ss; |
115 ss << std::setfill('0') << std::setw(2) << st.wHour; | 118 ss << std::setfill('0') << std::setw(2) << st.wHour; |
116 ss << ":"; | 119 ss << ":"; |
117 ss << std::setfill('0') << std::setw(2) << st.wMinute; | 120 ss << std::setfill('0') << std::setw(2) << st.wMinute; |
118 ss << ":"; | 121 ss << ":"; |
119 ss << std::setfill('0') << std::setw(2) << st.wSecond; | 122 ss << std::setfill('0') << std::setw(2) << st.wSecond; |
120 ss << "."; | 123 ss << "."; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 linePosition = eolPosition + 1; | 180 linePosition = eolPosition + 1; |
178 } | 181 } |
179 } | 182 } |
180 out.flush(); | 183 out.flush(); |
181 } | 184 } |
182 } | 185 } |
183 | 186 |
184 void WriteFile(const std::wstring& logFileName) const | 187 void WriteFile(const std::wstring& logFileName) const |
185 { | 188 { |
186 std::ofstream out; | 189 std::ofstream out; |
187 out.open(logFileName, std::ios::app); | 190 out.open(logFileName, std::ios::app); |
sergei
2015/12/02 13:53:00
I wonder whether we need a synchronization here. E
Eric
2015/12/02 15:01:24
Easy answer: This locking behavior is the same as
| |
188 Write(out); | 191 Write(out); |
189 } | 192 } |
190 }; | 193 }; |
191 | 194 |
192 std::wstring GetDataPath(const std::wstring& filename) | 195 std::wstring GetDataPath(const std::wstring& filename) |
193 { | 196 { |
194 return GetAppDataPath() + L"\\" + filename; | 197 return GetAppDataPath() + L"\\" + filename; |
195 } | 198 } |
196 | 199 |
197 void LogWriteDefault(const LogEntry& le) | 200 void LogWriteDefault(const LogEntry& le) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 317 |
315 | 318 |
316 #ifdef ENABLE_DEBUG_RESULT_IGNORED | 319 #ifdef ENABLE_DEBUG_RESULT_IGNORED |
317 | 320 |
318 void CPluginDebug::DebugResultIgnoring(const std::wstring& type, const std::wstr ing& src, const std::wstring& domain) | 321 void CPluginDebug::DebugResultIgnoring(const std::wstring& type, const std::wstr ing& src, const std::wstring& domain) |
319 { | 322 { |
320 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c)); | 323 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c)); |
321 } | 324 } |
322 | 325 |
323 #endif // ENABLE_DEBUG_RESULT_IGNORED | 326 #endif // ENABLE_DEBUG_RESULT_IGNORED |
LEFT | RIGHT |