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

Side by Side Diff: components/offline_pages/core/task.h

Issue 2359933007: [Offline pages] Introduces TaskQueue to serialize tasks that asynchronously access SQLStore (Closed)
Patch Set: Addressing gn problems, adding missing test file to build Created 4 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_TASK_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_TASK_H_
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/single_thread_task_runner.h"
12
13 namespace offline_pages {
14
15 // Task interface for consumers of the TaskQueue. Implements a mechanism for
16 // task completion.
17 //
18 // To use TaskQueue:
Pete Williamson 2016/09/29 00:54:43 Maybe this would be better as "To use a Task" *
fgorski 2016/09/29 17:37:37 Done.
19 // * Implement your task with as many async operations on the controlled
20 // resource as is required. (In general the smaller the task the better.)
21 // * Whenever the task is terminated, call |Complete|.
22 //
23 // If there is a chance that a task callback will come after the task is
24 // destroyed, it is up to the task to actually implement mechanism to deal with
25 // that, such as using a |base::WeakPtrFactory|.
26 class Task {
27 public:
28 typedef base::Callback<void(Task*)> CompletionCallback;
dougarnett 2016/09/29 15:40:04 TaskCompletionCallback?
fgorski 2016/09/29 17:37:37 Done.
29
30 Task();
31 virtual ~Task();
32
33 // Entry point to the task. This is used by the queue to start the task, and
34 // first step of the task should be implemented by overloading this method.
35 // TODO(fgorski): Consider alternative: protected RunImpl(), so that we can
36 // add things like UMA in the Run method.
Pete Williamson 2016/09/29 00:54:44 maybe add: // The task will have an additional f
fgorski 2016/09/29 17:37:36 Done.
37 virtual void Run() = 0;
38
39 // Sets the completion callback and whatever is set on it before the task is
Pete Williamson 2016/09/29 00:54:44 We have lots of different kinds of completions - l
fgorski 2016/09/29 17:37:36 I went with Doug's suggestion above and added to d
40 // put in the queue, will be overwritten. Setting the runner and callback here
dougarnett 2016/09/29 15:40:05 wording seems a bit confusing wrt overwritten and
fgorski 2016/09/29 17:37:37 Actually this raises a valid point. I'll add DCHEC
41 // allows task owner to inject completion callback and specify appropriate
Pete Williamson 2016/09/29 00:54:44 Naive user question: How does the Task client get
fgorski 2016/09/29 17:37:37 That is actually left for the caller to work out.
42 // thread/runner on which to call it.
43 // If the task is run outside of the queue and completion callback is not
44 // set, it will also work.
45 // Left public for testing.
46 void SetCompletionCallback(scoped_refptr<base::SingleThreadTaskRunner> runner,
47 const CompletionCallback& completion_callback);
48
49 protected:
50 // Call |Complete| at every point when the task is finished so that task queue
dougarnett 2016/09/29 15:40:05 what does "at every point" mean? Is it finished mo
fgorski 2016/09/29 17:37:36 Attempted clarification. Let me know.
51 // can pick up another task.
52 // |completion_callback_| will be scheduled on the provided
53 // |completion_runner_|, which means task code is no longer going to be on
54 // stack, when the next call is made.
55 void Complete();
Pete Williamson 2016/09/29 00:54:44 Maybe TaskComplete() to differentiate it a bit mor
fgorski 2016/09/29 17:37:37 Done.
56
57 private:
58 // Completion callback for this task set by |SetCompletionCallback|.
59 CompletionCallback completion_callback_;
60 // Task runner for calling completion callback.
61 scoped_refptr<base::SingleThreadTaskRunner> completion_runner_;
62
63 DISALLOW_COPY_AND_ASSIGN(Task);
Pete Williamson 2016/09/29 00:54:43 You've disallowed copy and assign, should you also
fgorski 2016/09/29 17:37:36 Cool. It got me thinking. I don't think that is c
64 };
65
66 } // namespace offline_pages
67
68 #endif // COMPONENTS_OFFLINE_PAGES_CORE_TASK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698