Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ios / chrome / app / deferred_initialization_runner.h
blobe1bd59ce5e9006bb2fed80ffb1fd0202fc852000
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
3 // found in the LICENSE file.
5 #ifndef IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_
6 #define IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_
8 #import <Foundation/Foundation.h>
10 #include "base/ios/block_types.h"
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
14 // singleton so that other code can force a deferred block to be run
15 // synchronously if necessary.
16 @interface DeferredInitializationRunner : NSObject
18 // Returns singleton instance.
19 + (DeferredInitializationRunner*)sharedInstance;
21 // 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 // 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 // cancels a previously scheduled block of the same |name| if the block has
26 // not been run yet.
27 - (void)runBlockNamed:(NSString*)name
28 after:(NSTimeInterval)delaySeconds
29 block:(ProceduralBlock)block;
31 // Looks up a previously scheduled block of |name|. If block has not been
32 // run yet, run it synchronously now.
33 - (void)runBlockIfNecessary:(NSString*)name;
35 // Cancels a previously scheduled block of |name|. This is a no-op if the
36 // block has already been executed.
37 - (void)cancelBlockNamed:(NSString*)name;
39 // Number of blocks that have been registered but not executed yet.
40 // Exposed for testing.
41 @property(nonatomic, readonly) NSUInteger numberOfBlocksRemaining;
43 @end
45 #endif // IOS_CHROME_APP_DEFERRED_INITIALIZATION_RUNNER_H_