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 #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> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 | 289 |
290 // MessagePump methods: | 290 // MessagePump methods: |
291 virtual void ScheduleWork(); | 291 virtual void ScheduleWork(); |
292 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 292 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
293 | 293 |
294 // Register the handler to be used when asynchronous IO for the given file | 294 // Register the handler to be used when asynchronous IO for the given file |
295 // completes. The registration persists as long as |file_handle| is valid, so | 295 // completes. The registration persists as long as |file_handle| is valid, so |
296 // |handler| must be valid as long as there is pending IO for the given file. | 296 // |handler| must be valid as long as there is pending IO for the given file. |
297 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler); | 297 void RegisterIOHandler(HANDLE file_handle, IOHandler* handler); |
298 | 298 |
299 // Register the handler to be used to process job events. The registration | |
300 // persists as long as the job object is live, so |handler| must be valid | |
301 // until the job object is destoyed. | |
302 bool RegisterJobObject(HANDLE job_handle, IOHandler* handler); | |
303 | |
299 // Waits for the next IO completion that should be processed by |filter|, for | 304 // Waits for the next IO completion that should be processed by |filter|, for |
300 // up to |timeout| milliseconds. Return true if any IO operation completed, | 305 // up to |timeout| milliseconds. Return true if any IO operation completed, |
301 // regardless of the involved handler, and false if the timeout expired. If | 306 // regardless of the involved handler, and false if the timeout expired. If |
302 // the completion port received any message and the involved IO handler | 307 // the completion port received any message and the involved IO handler |
303 // matches |filter|, the callback is called before returning from this code; | 308 // matches |filter|, the callback is called before returning from this code; |
304 // if the handler is not the one that we are looking for, the callback will | 309 // if the handler is not the one that we are looking for, the callback will |
305 // be postponed for another time, so reentrancy problems can be avoided. | 310 // be postponed for another time, so reentrancy problems can be avoided. |
306 // External use of this method should be reserved for the rare case when the | 311 // External use of this method should be reserved for the rare case when the |
307 // caller is willing to allow pausing regular task dispatching on this thread. | 312 // caller is willing to allow pausing regular task dispatching on this thread. |
308 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); | 313 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); |
309 | 314 |
310 void AddIOObserver(IOObserver* obs); | 315 void AddIOObserver(IOObserver* obs); |
311 void RemoveIOObserver(IOObserver* obs); | 316 void RemoveIOObserver(IOObserver* obs); |
312 | 317 |
313 private: | 318 private: |
314 struct IOItem { | 319 struct IOItem { |
315 IOHandler* handler; | 320 IOHandler* handler; |
316 IOContext* context; | 321 IOContext* context; |
317 DWORD bytes_transfered; | 322 DWORD bytes_transfered; |
318 DWORD error; | 323 DWORD error; |
324 | |
325 // |true| if |context| is a valid IOContext pointer. | |
326 bool has_context; | |
jar (doing other things)
2012/08/11 02:30:01
With a pointer, it is confusing to have a bool, an
alexeypa (please no reviews)
2012/08/13 15:15:14
Done.
| |
319 }; | 327 }; |
320 | 328 |
321 virtual void DoRunLoop(); | 329 virtual void DoRunLoop(); |
322 void WaitForWork(); | 330 void WaitForWork(); |
323 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item); | 331 bool MatchCompletedIOItem(IOHandler* filter, IOItem* item); |
324 bool GetIOItem(DWORD timeout, IOItem* item); | 332 bool GetIOItem(DWORD timeout, IOItem* item); |
325 bool ProcessInternalIOItem(const IOItem& item); | 333 bool ProcessInternalIOItem(const IOItem& item); |
326 void WillProcessIOEvent(); | 334 void WillProcessIOEvent(); |
327 void DidProcessIOEvent(); | 335 void DidProcessIOEvent(); |
328 | 336 |
337 // Converts an IOHandler pointer to a completion port key. |has_context| | |
338 // specifies whether complation packets will have valid OVERLAPPED pointers. | |
jar (doing other things)
2012/08/11 02:30:01
typo: complation
alexeypa (please no reviews)
2012/08/13 15:15:14
Done.
| |
339 static ULONG_PTR HandlerToKey(IOHandler* handler, bool has_context); | |
340 | |
341 // Converts a completion port key to an IOHandler pointer. | |
342 static IOHandler* KeyToHandler(ULONG_PTR key, bool* has_context_out); | |
343 | |
329 // The completion port associated with this thread. | 344 // The completion port associated with this thread. |
330 win::ScopedHandle port_; | 345 win::ScopedHandle port_; |
331 // This list will be empty almost always. It stores IO completions that have | 346 // This list will be empty almost always. It stores IO completions that have |
332 // not been delivered yet because somebody was doing cleanup. | 347 // not been delivered yet because somebody was doing cleanup. |
333 std::list<IOItem> completed_io_; | 348 std::list<IOItem> completed_io_; |
334 | 349 |
335 ObserverList<IOObserver> io_observers_; | 350 ObserverList<IOObserver> io_observers_; |
336 }; | 351 }; |
337 | 352 |
338 } // namespace base | 353 } // namespace base |
339 | 354 |
340 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 355 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |