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

Side by Side Diff: net/disk_cache/in_flight_io.cc

Issue 2819032: Revert 51312 - Disk cache: Switch the disk cache to use the cache_thread.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 5 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 | « net/disk_cache/in_flight_io.h ('k') | net/disk_cache/sparse_control.cc » ('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) 2006-2010 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 "net/disk_cache/in_flight_io.h"
6
7 #include "base/logging.h"
8
9 namespace disk_cache {
10
11 // Runs on the IO thread.
12 void BackgroundIO::OnIOSignalled() {
13 if (controller_)
14 controller_->InvokeCallback(this, false);
15 }
16
17 void BackgroundIO::Cancel() {
18 DCHECK(controller_);
19 controller_ = NULL;
20 }
21
22 // Runs on the background thread.
23 void BackgroundIO::NotifyController() {
24 controller_->OnIOComplete(this);
25 }
26
27 // ---------------------------------------------------------------------------
28
29 void InFlightIO::WaitForPendingIO() {
30 while (!io_list_.empty()) {
31 // Block the current thread until all pending IO completes.
32 IOList::iterator it = io_list_.begin();
33 InvokeCallback(*it, true);
34 }
35 }
36
37 // Runs on a background thread.
38 void InFlightIO::OnIOComplete(BackgroundIO* operation) {
39 callback_thread_->PostTask(FROM_HERE,
40 NewRunnableMethod(operation,
41 &BackgroundIO::OnIOSignalled));
42 operation->io_completed()->Signal();
43 }
44
45 // Runs on the IO thread.
46 void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) {
47 operation->io_completed()->Wait();
48
49 if (cancel_task)
50 operation->Cancel();
51
52 // Make sure that we remove the operation from the list before invoking the
53 // callback (so that a subsequent cancel does not invoke the callback again).
54 DCHECK(io_list_.find(operation) != io_list_.end());
55 io_list_.erase(operation);
56 OnOperationComplete(operation, cancel_task);
57 }
58
59 // Runs on the IO thread.
60 void InFlightIO::OnOperationPosted(BackgroundIO* operation) {
61 io_list_.insert(operation);
62 }
63
64 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/in_flight_io.h ('k') | net/disk_cache/sparse_control.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698