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

Side by Side Diff: remoting/base/auto_thread_task_runner.h

Issue 10829467: [Chromoting] Introducing refcount-based life time management of the message loops in the service (d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bringing back the parent link. Created 8 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_BASE_AUTO_THREAD_TASK_RUNNER_H_
6 #define REMOTING_BASE_AUTO_THREAD_TASK_RUNNER_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h"
12 #include "base/single_thread_task_runner.h"
13
14 class MessageLoop;
15
16 namespace remoting {
17
18 // This class provides automatic life time management for a single thread task
Wez 2012/08/30 18:20:12 nit: ... for a SingleThreadTaskRunner.
alexeypa (please no reviews) 2012/08/30 22:08:07 Done.
19 // runner. The task runner is stopped when the last reference to
20 // |AutoThreadTaskRunner| is dropped.
Wez 2012/08/30 18:20:12 Looking at the implementation, I can't see anythin
alexeypa (please no reviews) 2012/08/30 22:08:07 This is documented in ChromotingHostContext.
Wez 2012/08/30 23:56:43 I can see the comment regarding wrapping the Messa
alexeypa (please no reviews) 2012/08/31 19:57:36 I adopted a modified version of the comment descri
21 class AutoThreadTaskRunner : public base::SingleThreadTaskRunner {
22 public:
23 // Constructs an instance of |AutoThreadTaskRunner| wrapping |task_runner|.
24 // |stop_callback| is called (on arbitraty thread) when the last reference to
25 // the object is dropped.
26 explicit AutoThreadTaskRunner(
27 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
28 AutoThreadTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
29 const base::Closure& stop_callback);
30
31 // TODO(alexeypa): Remove the |parent| reference and contructors taking it
Wez 2012/08/30 18:20:12 typo: constructors
alexeypa (please no reviews) 2012/08/30 22:08:07 I don't see any typo. I rephrased the comment just
Wez 2012/08/30 23:56:43 You'd just missed the 's' in constructors. The new
alexeypa (please no reviews) 2012/08/31 19:57:36 I didn't. There are two constructors that take |pa
32 // once Thread class supports stopping the thread's message loop and joining
33 // the thread separately.
34 //
35 // Background: currently the only legitimate way of stopping a thread is to
36 // call Thread::Stop() from the same thread that started it. Thread::Stop()
37 // will stop the thread message loop by posting a private task and join
38 // the thread. Thread::Stop() verifies that it is called from the right thread
39 // and that the message loop has been stopped by the private task mentioned
40 // above.
41 //
42 // Until Thread::Stop() is split in two separate operations, it should not be
43 // called while any objects use it. It is achieved by keeping a reference to
Wez 2012/08/30 18:20:12 nit: It -> This
alexeypa (please no reviews) 2012/08/30 22:08:07 Done.
44 // the parent loop. Since Thread::Stop() is called after exiting the parent
Wez 2012/08/30 18:20:12 nit: ... parent loop. Since Thread ... -> ... pare
alexeypa (please no reviews) 2012/08/30 22:08:07 Done.
45 // loop, keeping a reference to it gives enough guaratee.
46 AutoThreadTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> parent,
47 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
Wez 2012/08/30 18:20:12 nit: I think it makes more sense for |parent| to c
alexeypa (please no reviews) 2012/08/30 22:08:07 Done.
48 AutoThreadTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> parent,
49 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
50 const base::Closure& stop_callback);
51
52 // SingleThreadTaskRunner implementation
53 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
54 const base::Closure& task,
55 base::TimeDelta delay) OVERRIDE;
56 virtual bool PostNonNestableDelayedTask(
57 const tracked_objects::Location& from_here,
58 const base::Closure& task,
59 base::TimeDelta delay) OVERRIDE;
60 virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
61
62 private:
63 friend class base::DeleteHelper<AutoThreadTaskRunner>;
64
65 virtual ~AutoThreadTaskRunner();
66
67 // An reference to the parent message loop to keep it alive while
68 // |task_runner_| is running.
Wez 2012/08/30 18:20:12 nit: ... is running. -> ... is running, so that a
alexeypa (please no reviews) 2012/08/30 22:08:07 Stop() cannot be posted to it.
Wez 2012/08/30 23:56:43 Because of the plugin shutdown case... it's a PITA
69 scoped_refptr<base::SingleThreadTaskRunner> parent_;
70
71 // This callback quits |task_runner_|. It can be run on any thread.
72 base::Closure stop_callback_;
73
74 // The wrapped task runner.
75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
76
77 DISALLOW_COPY_AND_ASSIGN(AutoThreadTaskRunner);
78 };
79
80 } // namespace remoting
81
82 #endif // REMOTING_BASE_AUTO_THREAD_TASK_RUNNER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/base/auto_thread_task_runner.cc » ('j') | remoting/host/chromoting_host_context.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698