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

Side by Side Diff: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: self review Created 3 years, 6 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
(Empty)
1 // Copyright 2017 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.
4
5 #import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h"
6
7 #include "base/logging.h"
8 #import "ios/clean/chrome/browser/ui/commands/web_overlay_commands.h"
9 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 DEFINE_WEB_STATE_USER_DATA_KEY(WebOverlayQueue);
16
17 // static
18 void WebOverlayQueue::CreateForWebState(
19 web::WebState* web_state,
20 id<WebOverlaySchedulerCommands> dispatcher) {
21 DCHECK(web_state);
22 DCHECK(dispatcher);
23 if (!FromWebState(web_state)) {
24 std::unique_ptr<WebOverlayQueue> queue =
25 base::WrapUnique(new WebOverlayQueue(web_state, dispatcher));
26 web_state->SetUserData(UserDataKey(), std::move(queue));
27 }
28 }
29
30 WebOverlayQueue::WebOverlayQueue(web::WebState* web_state,
31 id<WebOverlaySchedulerCommands> dispatcher)
32 : web_state_(web_state),
33 dispatcher_(dispatcher),
34 overlays_([[NSMutableArray alloc] init]),
35 showing_overlay_(false) {
36 DCHECK(web_state);
37 DCHECK(dispatcher);
38 }
39
40 WebOverlayQueue::~WebOverlayQueue() {}
41
42 void WebOverlayQueue::AddWebOverlay(
43 WebOverlayCoordinator* overlay_coordinator) {
44 // Add the overlay coordinator to the queue, then notify the scheduler.
45 DCHECK(overlay_coordinator);
46 [overlays_ addObject:overlay_coordinator];
47 [dispatcher_ scheduleWebOverlayForWebState:web_state_];
48 }
49
50 bool WebOverlayQueue::HasQueuedOverlays() const {
51 return [overlays_ count] > 0U;
52 }
53
54 void WebOverlayQueue::StartNextOverlay(BrowserCoordinator* web_coordinator) {
55 DCHECK(web_coordinator);
56 DCHECK(HasQueuedOverlays());
57 DCHECK(!IsShowingOverlay());
58 [[overlays_ firstObject] startOverlayingWebCoordinator:web_coordinator];
59 showing_overlay_ = true;
60 }
61
62 bool WebOverlayQueue::IsShowingOverlay() const {
63 return showing_overlay_;
64 }
65
66 void WebOverlayQueue::WebOverlayWasStopped(
67 WebOverlayCoordinator* overlay_coordinator) {
68 DCHECK(overlay_coordinator);
69 DCHECK_EQ([overlays_ firstObject], overlay_coordinator);
70 DCHECK(showing_overlay_);
71 [overlays_ removeObjectAtIndex:0];
72 showing_overlay_ = false;
73 }
74
75 void WebOverlayQueue::CancelOverlays() {
76 // Call the WebKit completion blocks for all queued overlays.
77 for (WebOverlayCoordinator* overlay_coordinator in overlays_.get()) {
78 [overlay_coordinator cancelWebKitCompletion];
79 }
80 // Stop the currently visible one, if necessary.
81 if (showing_overlay_)
82 [[overlays_ firstObject] stop];
83 // Empty the queue.
84 [overlays_ removeAllObjects];
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698