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

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

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 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
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/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/task_runner.h" 11 #include "base/task_runner.h"
12 12
13 namespace android { 13 namespace android {
14 class AfterStartupTaskUtilsJNI; 14 class AfterStartupTaskUtilsJNI;
15 } 15 }
16 16
17 class AfterStartupTaskUtils { 17 class AfterStartupTaskUtils {
18 public: 18 public:
19 // A helper TaskRunner which merely forwards to 19 // A helper TaskRunner which merely forwards to
20 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero 20 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero
21 // delay. 21 // delay.
22 class Runner : public base::TaskRunner { 22 class Runner : public base::TaskRunner {
23 public: 23 public:
24 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner); 24 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner);
25 25
26 // Overrides from base::TaskRunner: 26 // Overrides from base::TaskRunner:
27 bool PostDelayedTask(const tracked_objects::Location& from_here, 27 bool PostDelayedTask(const tracked_objects::Location& from_here,
28 const base::Closure& task, 28 base::OnceClosure task,
29 base::TimeDelta delay) override; 29 base::TimeDelta delay) override;
30 bool RunsTasksOnCurrentThread() const override; 30 bool RunsTasksOnCurrentThread() const override;
31 31
32 private: 32 private:
33 ~Runner() override; 33 ~Runner() override;
34 34
35 const scoped_refptr<base::TaskRunner> destination_runner_; 35 const scoped_refptr<base::TaskRunner> destination_runner_;
36 36
37 DISALLOW_COPY_AND_ASSIGN(Runner); 37 DISALLOW_COPY_AND_ASSIGN(Runner);
38 }; 38 };
39 39
40 // Observes startup and when complete runs tasks that have accrued. 40 // Observes startup and when complete runs tasks that have accrued.
41 static void StartMonitoringStartup(); 41 static void StartMonitoringStartup();
42 42
43 // Used to augment the behavior of BrowserThread::PostAfterStartupTask 43 // Used to augment the behavior of BrowserThread::PostAfterStartupTask
44 // for chrome. Tasks are queued until startup is complete. 44 // for chrome. Tasks are queued until startup is complete.
45 // Note: see browser_thread.h 45 // Note: see browser_thread.h
46 static void PostTask( 46 static void PostTask(
47 const tracked_objects::Location& from_here, 47 const tracked_objects::Location& from_here,
48 const scoped_refptr<base::TaskRunner>& destination_runner, 48 const scoped_refptr<base::TaskRunner>& destination_runner,
49 const base::Closure& task); 49 base::OnceClosure task);
50 50
51 // Returns true if browser startup is complete. Only use this on a one-off 51 // 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 52 // basis; If you need to poll this function constantly, use the above
53 // PostTask() API instead. 53 // PostTask() API instead.
54 static bool IsBrowserStartupComplete(); 54 static bool IsBrowserStartupComplete();
55 55
56 // For use by unit tests where we don't have normal content loading 56 // For use by unit tests where we don't have normal content loading
57 // infrastructure and thus StartMonitoringStartup() is unsuitable. 57 // infrastructure and thus StartMonitoringStartup() is unsuitable.
58 static void SetBrowserStartupIsCompleteForTesting(); 58 static void SetBrowserStartupIsCompleteForTesting();
59 59
60 static void UnsafeResetForTesting(); 60 static void UnsafeResetForTesting();
61 61
62 private: 62 private:
63 // TODO(wkorman): Look into why Android calls 63 // TODO(wkorman): Look into why Android calls
64 // SetBrowserStartupIsComplete() directly. Ideally it would use 64 // SetBrowserStartupIsComplete() directly. Ideally it would use
65 // StartMonitoringStartup() as the normal approach. 65 // StartMonitoringStartup() as the normal approach.
66 friend class android::AfterStartupTaskUtilsJNI; 66 friend class android::AfterStartupTaskUtilsJNI;
67 67
68 static void SetBrowserStartupIsComplete(); 68 static void SetBrowserStartupIsComplete();
69 69
70 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); 70 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils);
71 }; 71 };
72 72
73 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ 73 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
OLDNEW
« no previous file with comments | « cc/test/ordered_simple_task_runner_unittest.cc ('k') | chrome/browser/after_startup_task_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698