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

Side by Side Diff: trunk/src/base/event_recorder_win.cc

Issue 105823009: Revert 239280 "Move more file_util functions to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | « no previous file | trunk/src/base/file_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stddef.h> 5 #include <stddef.h>
6 #include <windows.h> 6 #include <windows.h>
7 #include <mmsystem.h> 7 #include <mmsystem.h>
8 8
9 #include "base/event_recorder.h" 9 #include "base/event_recorder.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 bool EventRecorder::StartRecording(const FilePath& filename) { 44 bool EventRecorder::StartRecording(const FilePath& filename) {
45 if (journal_hook_ != NULL) 45 if (journal_hook_ != NULL)
46 return false; 46 return false;
47 if (is_recording_ || is_playing_) 47 if (is_recording_ || is_playing_)
48 return false; 48 return false;
49 49
50 // Open the recording file. 50 // Open the recording file.
51 DCHECK(!file_); 51 DCHECK(!file_);
52 file_ = OpenFile(filename, "wb+"); 52 file_ = file_util::OpenFile(filename, "wb+");
53 if (!file_) { 53 if (!file_) {
54 DLOG(ERROR) << "EventRecorder could not open log file"; 54 DLOG(ERROR) << "EventRecorder could not open log file";
55 return false; 55 return false;
56 } 56 }
57 57
58 // Set the faster clock, if possible. 58 // Set the faster clock, if possible.
59 ::timeBeginPeriod(1); 59 ::timeBeginPeriod(1);
60 60
61 // Set the recording hook. JOURNALRECORD can only be used as a global hook. 61 // Set the recording hook. JOURNALRECORD can only be used as a global hook.
62 journal_hook_ = ::SetWindowsHookEx(WH_JOURNALRECORD, StaticRecordWndProc, 62 journal_hook_ = ::SetWindowsHookEx(WH_JOURNALRECORD, StaticRecordWndProc,
63 GetModuleHandle(NULL), 0); 63 GetModuleHandle(NULL), 0);
64 if (!journal_hook_) { 64 if (!journal_hook_) {
65 DLOG(ERROR) << "EventRecorder Record Hook failed"; 65 DLOG(ERROR) << "EventRecorder Record Hook failed";
66 CloseFile(file_); 66 file_util::CloseFile(file_);
67 return false; 67 return false;
68 } 68 }
69 69
70 is_recording_ = true; 70 is_recording_ = true;
71 return true; 71 return true;
72 } 72 }
73 73
74 void EventRecorder::StopRecording() { 74 void EventRecorder::StopRecording() {
75 if (is_recording_) { 75 if (is_recording_) {
76 DCHECK(journal_hook_ != NULL); 76 DCHECK(journal_hook_ != NULL);
77 77
78 if (!::UnhookWindowsHookEx(journal_hook_)) { 78 if (!::UnhookWindowsHookEx(journal_hook_)) {
79 DLOG(ERROR) << "EventRecorder Unhook failed"; 79 DLOG(ERROR) << "EventRecorder Unhook failed";
80 // Nothing else we can really do here. 80 // Nothing else we can really do here.
81 return; 81 return;
82 } 82 }
83 83
84 ::timeEndPeriod(1); 84 ::timeEndPeriod(1);
85 85
86 DCHECK(file_ != NULL); 86 DCHECK(file_ != NULL);
87 CloseFile(file_); 87 file_util::CloseFile(file_);
88 file_ = NULL; 88 file_ = NULL;
89 89
90 journal_hook_ = NULL; 90 journal_hook_ = NULL;
91 is_recording_ = false; 91 is_recording_ = false;
92 } 92 }
93 } 93 }
94 94
95 bool EventRecorder::StartPlayback(const FilePath& filename) { 95 bool EventRecorder::StartPlayback(const FilePath& filename) {
96 if (journal_hook_ != NULL) 96 if (journal_hook_ != NULL)
97 return false; 97 return false;
98 if (is_recording_ || is_playing_) 98 if (is_recording_ || is_playing_)
99 return false; 99 return false;
100 100
101 // Open the recording file. 101 // Open the recording file.
102 DCHECK(!file_); 102 DCHECK(!file_);
103 file_ = OpenFile(filename, "rb"); 103 file_ = file_util::OpenFile(filename, "rb");
104 if (!file_) { 104 if (!file_) {
105 DLOG(ERROR) << "EventRecorder Playback could not open log file"; 105 DLOG(ERROR) << "EventRecorder Playback could not open log file";
106 return false; 106 return false;
107 } 107 }
108 // Read the first event from the record. 108 // Read the first event from the record.
109 if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1) { 109 if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1) {
110 DLOG(ERROR) << "EventRecorder Playback has no records!"; 110 DLOG(ERROR) << "EventRecorder Playback has no records!";
111 CloseFile(file_); 111 file_util::CloseFile(file_);
112 return false; 112 return false;
113 } 113 }
114 114
115 // Set the faster clock, if possible. 115 // Set the faster clock, if possible.
116 ::timeBeginPeriod(1); 116 ::timeBeginPeriod(1);
117 117
118 // Playback time is tricky. When playing back, we read a series of events, 118 // Playback time is tricky. When playing back, we read a series of events,
119 // each with timeouts. Simply subtracting the delta between two timers will 119 // each with timeouts. Simply subtracting the delta between two timers will
120 // lead to fast playback (about 2x speed). The API has two events, one 120 // lead to fast playback (about 2x speed). The API has two events, one
121 // which advances to the next event (HC_SKIP), and another that requests the 121 // which advances to the next event (HC_SKIP), and another that requests the
(...skipping 21 matching lines...) Expand all
143 void EventRecorder::StopPlayback() { 143 void EventRecorder::StopPlayback() {
144 if (is_playing_) { 144 if (is_playing_) {
145 DCHECK(journal_hook_ != NULL); 145 DCHECK(journal_hook_ != NULL);
146 146
147 if (!::UnhookWindowsHookEx(journal_hook_)) { 147 if (!::UnhookWindowsHookEx(journal_hook_)) {
148 DLOG(ERROR) << "EventRecorder Unhook failed"; 148 DLOG(ERROR) << "EventRecorder Unhook failed";
149 // Nothing else we can really do here. 149 // Nothing else we can really do here.
150 } 150 }
151 151
152 DCHECK(file_ != NULL); 152 DCHECK(file_ != NULL);
153 CloseFile(file_); 153 file_util::CloseFile(file_);
154 file_ = NULL; 154 file_ = NULL;
155 155
156 ::timeEndPeriod(1); 156 ::timeEndPeriod(1);
157 157
158 journal_hook_ = NULL; 158 journal_hook_ = NULL;
159 is_playing_ = false; 159 is_playing_ = false;
160 } 160 }
161 } 161 }
162 162
163 // Windows callback hook for the recorder. 163 // Windows callback hook for the recorder.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // indicating that the message is not removed from the message queue after 249 // indicating that the message is not removed from the message queue after
250 // PeekMessage processing. 250 // PeekMessage processing.
251 case HC_NOREMOVE: 251 case HC_NOREMOVE:
252 break; 252 break;
253 } 253 }
254 254
255 return CallNextHookEx(journal_hook_, nCode, wParam, lParam); 255 return CallNextHookEx(journal_hook_, nCode, wParam, lParam);
256 } 256 }
257 257
258 } // namespace base 258 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | trunk/src/base/file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698