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

Side by Side Diff: ios/chrome/app/deferred_initialization_runner.h

Issue 2217083002: Add sequential dispatching for InitializationRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_ 5 #ifndef IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_
6 #define IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_ 6 #define IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_
7 7
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 9
10 #include "base/ios/block_types.h" 10 #include "base/ios/block_types.h"
11 11
12 // A singleton object to run initialization code asynchronously. Blocks are 12 // A singleton object to run initialization code asynchronously. Blocks are
13 // scheduled to be run after a delay. The block is named when added to the 13 // scheduled to be run after a delay. The block is named when added to the
14 // singleton so that other code can force a deferred block to be run 14 // singleton so that other code can force a deferred block to be run
15 // synchronously if necessary. 15 // synchronously if necessary.
16 @interface DeferredInitializationRunner : NSObject 16 @interface DeferredInitializationRunner : NSObject
17 17
18 // Returns singleton instance. 18 // Returns singleton instance.
19 + (DeferredInitializationRunner*)sharedInstance; 19 + (DeferredInitializationRunner*)sharedInstance;
20 20
21 // Deprecated.
21 // Schedules |block| to be run after |delaySeconds| on the current queue. 22 // Schedules |block| to be run after |delaySeconds| on the current queue.
22 // This |block| is stored as |name| so code can force this initialization to 23 // This |block| is stored as |name| so code can force this initialization to
23 // be run synchronously if necessary. This method may be called more than 24 // be run synchronously if necessary. This method may be called more than
24 // once with the same |name| parameter. Any block with the same |name| 25 // once with the same |name| parameter. Any block with the same |name|
25 // cancels a previously scheduled block of the same |name| if the block has 26 // cancels a previously scheduled block of the same |name| if the block has
26 // not been run yet. 27 // not been run yet.
27 - (void)runBlockNamed:(NSString*)name 28 - (void)runBlockNamed:(NSString*)name
28 after:(NSTimeInterval)delaySeconds 29 after:(NSTimeInterval)delaySeconds
29 block:(ProceduralBlock)block; 30 block:(ProceduralBlock)block;
30 31
32 // Adds |block| to a block queue containing all block not run. The blocks in the
pkl (ping after 24h if needed) 2016/08/08 23:41:53 s/all block/all blocks/
gambard 2016/08/09 08:17:05 Done.
33 // queue are runned sequentially with a small delay between each block.
pkl (ping after 24h if needed) 2016/08/08 23:41:53 s/runned/ran/
gambard 2016/08/09 08:17:05 Done.
34 // If the queue is empty |block| is run after a small delay.
35 // This |block| is stored as |name| so code can force this initialization to
36 // be run synchronously if necessary. This method may be called more than
37 // once with the same |name| parameter. Any block with the same |name|
38 // cancels a previously scheduled block of the same |name| if the block has
39 // not been run yet.
40 - (void)enqueueBlockNamed:(NSString*)name block:(ProceduralBlock)block;
41
31 // Looks up a previously scheduled block of |name|. If block has not been 42 // Looks up a previously scheduled block of |name|. If block has not been
32 // run yet, run it synchronously now. 43 // run yet, run it synchronously now.
33 - (void)runBlockIfNecessary:(NSString*)name; 44 - (void)runBlockIfNecessary:(NSString*)name;
34 45
35 // Cancels a previously scheduled block of |name|. This is a no-op if the 46 // Cancels a previously scheduled block of |name|. This is a no-op if the
36 // block has already been executed. 47 // block has already been executed.
37 - (void)cancelBlockNamed:(NSString*)name; 48 - (void)cancelBlockNamed:(NSString*)name;
38 49
39 // Number of blocks that have been registered but not executed yet. 50 // Number of blocks that have been registered but not executed yet.
40 // Exposed for testing. 51 // Exposed for testing.
41 @property(nonatomic, readonly) NSUInteger numberOfBlocksRemaining; 52 @property(nonatomic, readonly) NSUInteger numberOfBlocksRemaining;
42 53
54 // Time interval between two blocks. Default value is 200ms.
pkl (ping after 24h if needed) 2016/08/08 23:41:53 Is this @property really part of the API or exists
gambard 2016/08/09 08:17:05 For now it is used for testing but I think it is r
55 @property(nonatomic) NSTimeInterval delayBetweenBlocks;
56
43 @end 57 @end
44 58
45 #endif // IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_ 59 #endif // IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698