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

Side by Side Diff: base/message_pump_win.h

Issue 2098020: Jankometer: Generalize the code more. Add better support for monitoring IO thread. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Address darin's comments. Created 10 years, 6 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
« no previous file with comments | « base/message_pump_libevent.cc ('k') | base/message_pump_win.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef BASE_MESSAGE_PUMP_WIN_H_ 5 #ifndef BASE_MESSAGE_PUMP_WIN_H_
6 #define BASE_MESSAGE_PUMP_WIN_H_ 6 #define BASE_MESSAGE_PUMP_WIN_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <list> 10 #include <list>
11 11
12 #include "base/basictypes.h"
12 #include "base/lock.h" 13 #include "base/lock.h"
13 #include "base/message_pump.h" 14 #include "base/message_pump.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/scoped_handle.h" 16 #include "base/scoped_handle.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 18
18 namespace base { 19 namespace base {
19 20
20 // MessagePumpWin serves as the base for specialized versions of the MessagePump 21 // MessagePumpWin serves as the base for specialized versions of the MessagePump
21 // for Windows. It provides basic functionality like handling of observers and 22 // for Windows. It provides basic functionality like handling of observers and
22 // controlling the lifetime of the message pump. 23 // controlling the lifetime of the message pump.
23 class MessagePumpWin : public MessagePump { 24 class MessagePumpWin : public MessagePump {
24 public: 25 public:
25 // An Observer is an object that receives global notifications from the 26 // An Observer is an object that receives global notifications from the
26 // MessageLoop. 27 // UI MessageLoop.
27 // 28 //
28 // NOTE: An Observer implementation should be extremely fast! 29 // NOTE: An Observer implementation should be extremely fast!
29 // 30 //
30 class Observer { 31 class Observer {
31 public: 32 public:
32 virtual ~Observer() {} 33 virtual ~Observer() {}
33 34
34 // This method is called before processing a message. 35 // This method is called before processing a message.
35 // The message may be undefined in which case msg.message is 0 36 // The message may be undefined in which case msg.message is 0
36 virtual void WillProcessMessage(const MSG& msg) = 0; 37 virtual void WillProcessMessage(const MSG& msg) = 0;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 public: 277 public:
277 virtual ~IOHandler() {} 278 virtual ~IOHandler() {}
278 // This will be called once the pending IO operation associated with 279 // This will be called once the pending IO operation associated with
279 // |context| completes. |error| is the Win32 error code of the IO operation 280 // |context| completes. |error| is the Win32 error code of the IO operation
280 // (ERROR_SUCCESS if there was no error). |bytes_transfered| will be zero 281 // (ERROR_SUCCESS if there was no error). |bytes_transfered| will be zero
281 // on error. 282 // on error.
282 virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered, 283 virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
283 DWORD error) = 0; 284 DWORD error) = 0;
284 }; 285 };
285 286
287 // An IOObserver is an object that receives IO notifications from the
288 // MessagePump.
289 //
290 // NOTE: An IOObserver implementation should be extremely fast!
291 class IOObserver {
292 public:
293 IOObserver() {}
294
295 virtual void WillProcessIOEvent() = 0;
296 virtual void DidProcessIOEvent() = 0;
297
298 protected:
299 virtual ~IOObserver() {}
300 };
301
286 // The extended context that should be used as the base structure on every 302 // The extended context that should be used as the base structure on every
287 // overlapped IO operation. |handler| must be set to the registered IOHandler 303 // overlapped IO operation. |handler| must be set to the registered IOHandler
288 // for the given file when the operation is started, and it can be set to NULL 304 // for the given file when the operation is started, and it can be set to NULL
289 // before the operation completes to indicate that the handler should not be 305 // before the operation completes to indicate that the handler should not be
290 // called anymore, and instead, the IOContext should be deleted when the OS 306 // called anymore, and instead, the IOContext should be deleted when the OS
291 // notifies the completion of this operation. Please remember that any buffers 307 // notifies the completion of this operation. Please remember that any buffers
292 // involved with an IO operation should be around until the callback is 308 // involved with an IO operation should be around until the callback is
293 // received, so this technique can only be used for IO that do not involve 309 // received, so this technique can only be used for IO that do not involve
294 // additional buffers (other than the overlapped structure itself). 310 // additional buffers (other than the overlapped structure itself).
295 struct IOContext { 311 struct IOContext {
(...skipping 17 matching lines...) Expand all
313 // up to |timeout| milliseconds. Return true if any IO operation completed, 329 // up to |timeout| milliseconds. Return true if any IO operation completed,
314 // regardless of the involved handler, and false if the timeout expired. If 330 // regardless of the involved handler, and false if the timeout expired. If
315 // the completion port received any message and the involved IO handler 331 // the completion port received any message and the involved IO handler
316 // matches |filter|, the callback is called before returning from this code; 332 // matches |filter|, the callback is called before returning from this code;
317 // if the handler is not the one that we are looking for, the callback will 333 // if the handler is not the one that we are looking for, the callback will
318 // be postponed for another time, so reentrancy problems can be avoided. 334 // be postponed for another time, so reentrancy problems can be avoided.
319 // External use of this method should be reserved for the rare case when the 335 // External use of this method should be reserved for the rare case when the
320 // caller is willing to allow pausing regular task dispatching on this thread. 336 // caller is willing to allow pausing regular task dispatching on this thread.
321 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); 337 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter);
322 338
339 void AddIOObserver(IOObserver* obs);
340 void RemoveIOObserver(IOObserver* obs);
341
323 private: 342 private:
324 struct IOItem { 343 struct IOItem {
325 IOHandler* handler; 344 IOHandler* handler;
326 IOContext* context; 345 IOContext* context;
327 DWORD bytes_transfered; 346 DWORD bytes_transfered;
328 DWORD error; 347 DWORD error;
329 }; 348 };
330 349
331 virtual void DoRunLoop(); 350 virtual void DoRunLoop();
332 void WaitForWork(); 351 void WaitForWork();
333 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item); 352 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item);
334 bool GetIOItem(DWORD timeout, IOItem* item); 353 bool GetIOItem(DWORD timeout, IOItem* item);
335 bool ProcessInternalIOItem(const IOItem& item); 354 bool ProcessInternalIOItem(const IOItem& item);
355 void WillProcessIOEvent();
356 void DidProcessIOEvent();
336 357
337 // The completion port associated with this thread. 358 // The completion port associated with this thread.
338 ScopedHandle port_; 359 ScopedHandle port_;
339 // This list will be empty almost always. It stores IO completions that have 360 // This list will be empty almost always. It stores IO completions that have
340 // not been delivered yet because somebody was doing cleanup. 361 // not been delivered yet because somebody was doing cleanup.
341 std::list<IOItem> completed_io_; 362 std::list<IOItem> completed_io_;
363
364 ObserverList<IOObserver> io_observers_;
342 }; 365 };
343 366
344 } // namespace base 367 } // namespace base
345 368
346 #endif // BASE_MESSAGE_PUMP_WIN_H_ 369 #endif // BASE_MESSAGE_PUMP_WIN_H_
OLDNEW
« no previous file with comments | « base/message_pump_libevent.cc ('k') | base/message_pump_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698