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

Side by Side Diff: chrome/browser/after_startup_task_utils.h

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: . Created 3 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ 5 #ifndef CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ 6 #define CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h"
sky 2017/03/22 17:34:11 callback_forward?
gab 2017/03/22 17:46:45 Need full type to pass by value.
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/task_runner.h" 12 #include "base/task_runner.h"
12 13
13 namespace android { 14 namespace android {
14 class AfterStartupTaskUtilsJNI; 15 class AfterStartupTaskUtilsJNI;
15 } 16 }
16 17
17 class AfterStartupTaskUtils { 18 class AfterStartupTaskUtils {
18 public: 19 public:
19 // A helper TaskRunner which merely forwards to 20 // A helper TaskRunner which merely forwards to
20 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero 21 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero
21 // delay. 22 // delay.
22 class Runner : public base::TaskRunner { 23 class Runner : public base::TaskRunner {
23 public: 24 public:
24 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner); 25 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner);
25 26
26 // Overrides from base::TaskRunner: 27 // Overrides from base::TaskRunner:
27 bool PostDelayedTask(const tracked_objects::Location& from_here, 28 bool PostDelayedTask(const tracked_objects::Location& from_here,
28 const base::Closure& task, 29 base::Closure task,
29 base::TimeDelta delay) override; 30 base::TimeDelta delay) override;
30 bool RunsTasksOnCurrentThread() const override; 31 bool RunsTasksOnCurrentThread() const override;
31 32
32 private: 33 private:
33 ~Runner() override; 34 ~Runner() override;
34 35
35 const scoped_refptr<base::TaskRunner> destination_runner_; 36 const scoped_refptr<base::TaskRunner> destination_runner_;
36 37
37 DISALLOW_COPY_AND_ASSIGN(Runner); 38 DISALLOW_COPY_AND_ASSIGN(Runner);
38 }; 39 };
39 40
40 // Observes startup and when complete runs tasks that have accrued. 41 // Observes startup and when complete runs tasks that have accrued.
41 static void StartMonitoringStartup(); 42 static void StartMonitoringStartup();
42 43
43 // Used to augment the behavior of BrowserThread::PostAfterStartupTask 44 // Used to augment the behavior of BrowserThread::PostAfterStartupTask
44 // for chrome. Tasks are queued until startup is complete. 45 // for chrome. Tasks are queued until startup is complete.
45 // Note: see browser_thread.h 46 // Note: see browser_thread.h
46 static void PostTask( 47 static void PostTask(
47 const tracked_objects::Location& from_here, 48 const tracked_objects::Location& from_here,
48 const scoped_refptr<base::TaskRunner>& destination_runner, 49 const scoped_refptr<base::TaskRunner>& destination_runner,
49 const base::Closure& task); 50 base::Closure task);
50 51
51 // Returns true if browser startup is complete. Only use this on a one-off 52 // Returns true if browser startup is complete. Only use this on a one-off
52 // basis; If you need to poll this function constantly, use the above 53 // basis; If you need to poll this function constantly, use the above
53 // PostTask() API instead. 54 // PostTask() API instead.
54 static bool IsBrowserStartupComplete(); 55 static bool IsBrowserStartupComplete();
55 56
56 // For use by unit tests where we don't have normal content loading 57 // For use by unit tests where we don't have normal content loading
57 // infrastructure and thus StartMonitoringStartup() is unsuitable. 58 // infrastructure and thus StartMonitoringStartup() is unsuitable.
58 static void SetBrowserStartupIsCompleteForTesting(); 59 static void SetBrowserStartupIsCompleteForTesting();
59 60
60 static void UnsafeResetForTesting(); 61 static void UnsafeResetForTesting();
61 62
62 private: 63 private:
63 // TODO(wkorman): Look into why Android calls 64 // TODO(wkorman): Look into why Android calls
64 // SetBrowserStartupIsComplete() directly. Ideally it would use 65 // SetBrowserStartupIsComplete() directly. Ideally it would use
65 // StartMonitoringStartup() as the normal approach. 66 // StartMonitoringStartup() as the normal approach.
66 friend class android::AfterStartupTaskUtilsJNI; 67 friend class android::AfterStartupTaskUtilsJNI;
67 68
68 static void SetBrowserStartupIsComplete(); 69 static void SetBrowserStartupIsComplete();
69 70
70 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); 71 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils);
71 }; 72 };
72 73
73 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ 74 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698