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

Side by Side Diff: base/worker_pool_job.cc

Issue 5710002: Create base::WorkerPoolJob. Use it for HostResolverImpl and DirectoryLister. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 10 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
OLDNEW
(Empty)
1 // Copyright (c) 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 "base/worker_pool_job.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop_proxy.h"
9 #include "base/worker_pool.h"
10
11 namespace base {
12
13 WorkerPoolJob::WorkerPoolJob()
14 : origin_loop_(base::MessageLoopProxy::CreateForCurrentThread()),
15 canceled_(false),
16 state_(NONE) {}
17
18 WorkerPoolJob::~WorkerPoolJob() {}
19
20 void WorkerPoolJob::StartJob() {
21 DCHECK(thread_checker_.CalledOnValidThread());
22 DCHECK_EQ(state_, NONE);
eroman 2011/01/05 01:24:52 Can the state DCHECK be more restrictive? i.e, I
23 state_ = RUNNING;
24 bool posted = WorkerPool::PostTask(
25 FROM_HERE,
26 NewRunnableMethod(this, &WorkerPoolJob::RunJobOnWorkerPool),
27 true /* is_slow */);
28 DCHECK(posted);
29 }
30
31 void WorkerPoolJob::CancelJob() {
32 DCHECK(thread_checker_.CalledOnValidThread());
33 DCHECK_NE(state_, NONE);
34 DCHECK_NE(state_, DONE);
eroman 2011/01/05 01:24:52 Can these two checks be combined into: DCHECK_EQ(R
35 DCHECK(!canceled_);
36 canceled_ = true;
37 }
38
39 bool WorkerPoolJob::canceled() const {
40 // No thread check since RunJob() implementations may check to see if they've
41 // been canceled so they can bail out early.
eroman 2011/01/05 01:24:52 I don't think this comment is true anymore.
42 DCHECK_NE(state_, NONE);
43 return canceled_;
44 }
45
46 void WorkerPoolJob::RunJobOnWorkerPool() {
47 DCHECK(!thread_checker_.CalledOnValidThread());
48
49 RunJob();
50
51 origin_loop_->PostTask(
52 FROM_HERE,
53 NewRunnableMethod(this, &WorkerPoolJob::CompleteJobOnOriginLoop));
54 }
55
56 void WorkerPoolJob::CompleteJobOnOriginLoop() {
57 DCHECK(thread_checker_.CalledOnValidThread());
58 DCHECK_NE(state_, NONE);
eroman 2011/01/05 01:24:52 Can these two statnments be combined into: DCHECK
59 DCHECK_NE(state_, DONE);
60
61 // No need to lock, since writes only happen on origin loop.
62 if (canceled_) {
63 state_ = DONE;
64 return;
65 }
66
67 OnJobCompleted();
68
69 state_ = DONE;
eroman 2011/01/05 01:24:52 nit: I wander if you want to set state_ to DONE be
70 }
71
72 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698