| Index: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_scheduler.mm
|
| diff --git a/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_scheduler.mm b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_scheduler.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e7e9b277bac089167fa4cb4401553b2c7bfb2982
|
| --- /dev/null
|
| +++ b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_scheduler.mm
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_scheduler.h"
|
| +
|
| +#include <list>
|
| +
|
| +#include "base/logging.h"
|
| +#import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h"
|
| +#import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h"
|
| +#import "ios/web/public/web_state/web_state.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +@interface WebOverlayScheduler () {
|
| + // The WebStates that have queued overlays.
|
| + std::list<web::WebState*> web_states_;
|
| +}
|
| +
|
| +// The dispatcher passed on initialization.
|
| +@property(nonatomic, readonly, weak)
|
| + id<TabGridCommands, WebOverlayPresentationCommands>
|
| + dispatcher;
|
| +
|
| +// Attempts to show the next queued overlay.
|
| +- (void)tryToStartNextOverlay;
|
| +
|
| +@end
|
| +
|
| +@implementation WebOverlayScheduler
|
| +
|
| +@synthesize dispatcher = _dispatcher;
|
| +
|
| +- (instancetype)initWithDispatcher:
|
| + (id<TabGridCommands, WebOverlayPresentationCommands>)dispatcher {
|
| + if ((self = [super init]))
|
| + _dispatcher = dispatcher;
|
| + return self;
|
| +}
|
| +
|
| +#pragma mark - WebOverlayCommands
|
| +
|
| +- (void)scheduleWebOverlayForWebState:(web::WebState*)webState {
|
| + DCHECK(webState);
|
| + web_states_.push_back(webState);
|
| + [self tryToStartNextOverlay];
|
| +}
|
| +
|
| +- (void)webOverlayWasStoppedForWebState:(web::WebState*)webState {
|
| + DCHECK(!web_states_.empty());
|
| + DCHECK_EQ(web_states_.front(), webState);
|
| + web_states_.pop_front();
|
| + [self tryToStartNextOverlay];
|
| +}
|
| +
|
| +- (void)cancelWebOverlaysForWebState:(web::WebState*)webState {
|
| + DCHECK(webState);
|
| + // Remove all scheduled instances of |webState| from the queue.
|
| + auto i = web_states_.begin();
|
| + while (i != web_states_.end()) {
|
| + if (*i == webState)
|
| + web_states_.erase(i);
|
| + }
|
| + // Remove all overlays from |webState|'s queue.
|
| + WebOverlayQueue::FromWebState(webState)->CancelOverlays();
|
| + [self tryToStartNextOverlay];
|
| +}
|
| +
|
| +#pragma mark -
|
| +
|
| +- (void)tryToStartNextOverlay {
|
| + // Early return if there are no overlays to show.
|
| + if (web_states_.empty())
|
| + return;
|
| + // Also early return if the front queue is already presenting an overlay.
|
| + WebOverlayQueue* queue = WebOverlayQueue::FromWebState(web_states_.front());
|
| + if (queue->IsShowingOverlay())
|
| + return;
|
| + // Show the next WebState's content view and start its overlay.
|
| + [self.dispatcher showTabGridTabWithWebState:web_states_.front()];
|
| + [self.dispatcher startNextWebOverlayForWebState:web_states_.front()];
|
| +}
|
| +
|
| +@end
|
|
|