Index: ios/clean/chrome/browser/ui/overlay_service/internal/overlay_scheduler.h |
diff --git a/ios/clean/chrome/browser/ui/overlay_service/internal/overlay_scheduler.h b/ios/clean/chrome/browser/ui/overlay_service/internal/overlay_scheduler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d4571bc56808d428184d2d93c77f53ebc79eb88 |
--- /dev/null |
+++ b/ios/clean/chrome/browser/ui/overlay_service/internal/overlay_scheduler.h |
@@ -0,0 +1,88 @@ |
+// 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. |
+ |
+#ifndef IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_INTERNAL_OVERLAY_SCHEDULER_H_ |
+#define IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_INTERNAL_OVERLAY_SCHEDULER_H_ |
+ |
+#include <Foundation/Foundation.h> |
+#include <list> |
+ |
+#import "ios/chrome/browser/web_state_list/web_state_list_observer.h" |
+#import "ios/clean/chrome/browser/ui/overlay_service/internal/overlay_queue_observer.h" |
+#import "ios/shared/chrome/browser/ui/browser_list/browser_user_data.h" |
+ |
+@class BrowserCoordinator; |
+@protocol OverlayPresentationCommands; |
+@protocol TabGridCommands; |
+ |
+namespace web { |
+class WebState; |
+} |
+ |
+// An object that manages scheduling when overlays from various OverlayQueues |
+// can be started. If an OverlayQueue requires a WebState's content area to be |
+// visible, this class will update the WebStateLists's active WebState. |
+class OverlayScheduler : public BrowserUserData<OverlayScheduler>, |
marq (ping after 24h)
2017/06/23 10:42:01
Unit tests for this class?
|
+ public OverlayQueueObserver, |
+ public WebStateListObserver { |
+ public: |
+ ~OverlayScheduler() override; |
+ |
+ // Starts or stops observing |browser_|'s WebStateList and OverlayQueues. |
+ void StartObservingBrowser(); |
+ void StopObservingBrowser(); |
+ |
+ // Whether a scheduled overlay is currently being shown. |
+ bool IsShowingOverlay() const; |
+ |
+ // Replaces the currently visible overlay with |overlay_coordinator|. |
+ void ReplaceVisibleOverlay(BrowserCoordinator* overlay_coordinator); |
+ |
+ // Cancels all scheduled overlays and empties overlay queues. |
+ void CancelOverlays(); |
+ |
+ private: |
+ friend class BrowserUserData<OverlayScheduler>; |
+ // The Browser for which this object is scheduling overlays. |
+ Browser* browser_; |
+ // Whether the sheduler is currently observing |browser_|'s WebStateList and |
+ // OverlayQueues. |
+ bool observing_; |
+ // The OverlayQueues that have queued overlays. After an overlay is stopped, |
+ // the first queue is popped and the first ovelay in the next queue is |
+ // started. |
+ std::list<OverlayQueue*> overlay_queues_; |
+ |
+ // Private constructor used by factory method. |
+ explicit OverlayScheduler(Browser* browser); |
+ |
+ // OverlayQueueObserver: |
+ void OverlayQueueDidAddOverlay(OverlayQueue* queue) override; |
+ void OverlayQueueWillReplaceVisibleOverlay(OverlayQueue* queue) override; |
+ void OverlayQueueDidStopVisibleOverlay(OverlayQueue* queue) override; |
+ void OverlayQueueDidCancelOverlays(OverlayQueue* queue) override; |
+ |
+ // WebStateListObserver: |
+ void WebStateInsertedAt(WebStateList* web_state_list, |
+ web::WebState* web_state, |
+ int index) override; |
+ void WebStateDetachedAt(WebStateList* web_state_list, |
+ web::WebState* web_state, |
+ int index) override; |
+ |
+ // Attempts to show the next queued overlay. |
+ void TryToStartNextOverlay(); |
+ // Starts observing |web_state_list|. Also starts observing the OverlayQueue |
+ // for each WebState in the list. |
+ void StartObservingWebStateList(WebStateList* web_state_list); |
+ // Stops observing |web_state_list| and the OverlayQueues for each WebState in |
+ // the list. Also cancels any queues overlays. |
+ void StopObservingWebStateList(WebStateList* web_state_list); |
+ // Lazily creates an OverlayQueue for |web_state| and starts observing it. |
+ void StartObservingQueueForWebState(web::WebState* web_state); |
+ // Cancels the overlays in |web_state|'s OverlayQueue and stops observing it. |
+ void StopObservingQueueForWebState(web::WebState* web_state); |
+}; |
+ |
+#endif // IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_INTERNAL_OVERLAY_SCHEDULER_H_ |