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

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

Issue 2238603002: Introduce AfterStartupTaskUtils::Runner for callsites that want to use AfterStartupTaskUtils but ne… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b9_sequenced_worker_pool_redirection
Patch Set: merge up to r411308 Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/after_startup_task_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12
12 namespace android { 13 namespace android {
13 class AfterStartupTaskUtilsJNI; 14 class AfterStartupTaskUtilsJNI;
14 } 15 }
15 16
16 namespace base {
17 class TaskRunner;
18 }
19 namespace tracked_objects {
20 class Location;
21 };
22
23 class AfterStartupTaskUtils { 17 class AfterStartupTaskUtils {
24 public: 18 public:
19 // A helper TaskRunner which merely forwards to
20 // AfterStartupTaskUtils::PostTask(). Doesn't support tasks with a non-zero
21 // delay.
22 class Runner : public base::TaskRunner {
23 public:
24 explicit Runner(scoped_refptr<base::TaskRunner> destination_runner);
25
26 // Overrides from base::TaskRunner:
27 bool PostDelayedTask(const tracked_objects::Location& from_here,
28 const base::Closure& task,
29 base::TimeDelta delay) override;
30 bool RunsTasksOnCurrentThread() const override;
31
32 private:
33 ~Runner() override;
34
35 const scoped_refptr<base::TaskRunner> destination_runner_;
36
37 DISALLOW_COPY_AND_ASSIGN(Runner);
38 };
39
25 // Observes startup and when complete runs tasks that have accrued. 40 // Observes startup and when complete runs tasks that have accrued.
26 static void StartMonitoringStartup(); 41 static void StartMonitoringStartup();
27 42
28 // Used to augment the behavior of BrowserThread::PostAfterStartupTask 43 // Used to augment the behavior of BrowserThread::PostAfterStartupTask
29 // for chrome. Tasks are queued until startup is complete. 44 // for chrome. Tasks are queued until startup is complete.
30 // Note: see browser_thread.h 45 // Note: see browser_thread.h
31 static void PostTask(const tracked_objects::Location& from_here, 46 static void PostTask(
32 const scoped_refptr<base::TaskRunner>& task_runner, 47 const tracked_objects::Location& from_here,
33 const base::Closure& task); 48 const scoped_refptr<base::TaskRunner>& destination_runner,
49 const base::Closure& task);
34 50
35 // 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
36 // 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
37 // PostTask() API instead. 53 // PostTask() API instead.
38 static bool IsBrowserStartupComplete(); 54 static bool IsBrowserStartupComplete();
39 55
40 // 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
41 // infrastructure and thus StartMonitoringStartup() is unsuitable. 57 // infrastructure and thus StartMonitoringStartup() is unsuitable.
42 static void SetBrowserStartupIsCompleteForTesting(); 58 static void SetBrowserStartupIsCompleteForTesting();
43 59
44 static void UnsafeResetForTesting(); 60 static void UnsafeResetForTesting();
45 61
46 private: 62 private:
47 // TODO(wkorman): Look into why Android calls 63 // TODO(wkorman): Look into why Android calls
48 // SetBrowserStartupIsComplete() directly. Ideally it would use 64 // SetBrowserStartupIsComplete() directly. Ideally it would use
49 // StartMonitoringStartup() as the normal approach. 65 // StartMonitoringStartup() as the normal approach.
50 friend class android::AfterStartupTaskUtilsJNI; 66 friend class android::AfterStartupTaskUtilsJNI;
51 67
52 static void SetBrowserStartupIsComplete(); 68 static void SetBrowserStartupIsComplete();
53 69
54 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils); 70 DISALLOW_IMPLICIT_CONSTRUCTORS(AfterStartupTaskUtils);
55 }; 71 };
56 72
57 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_ 73 #endif // CHROME_BROWSER_AFTER_STARTUP_TASK_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/after_startup_task_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698