1 // Copyright 2019 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 #ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_CALLBACK_MANAGER_H_
6 #define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_CALLBACK_MANAGER_H_
7 
8 #include <memory>
9 
10 #include "ios/chrome/browser/overlays/public/overlay_dispatch_callback.h"
11 #include "ios/chrome/browser/overlays/public/overlay_user_data.h"
12 
13 class OverlayResponse;
14 // Completion callback for OverlayRequests.  If an overlay requires a completion
15 // block to be executed after its UI is dismissed, OverlayPresenter clients can
16 // provide a callback that uses the OverlayResponse provided to the request.
17 // |response| may be null if no response has been provided.
18 typedef base::OnceCallback<void(OverlayResponse* response)>
19     OverlayCompletionCallback;
20 
21 // Helper object owned by an OverlayRequest that is used to communicate overlay
22 // UI interaction information back to the overlay's requester.  Supports
23 // completion calllbacks, which are executed when the overlay is finished.
24 class OverlayCallbackManager {
25  public:
26   OverlayCallbackManager() = default;
27   virtual ~OverlayCallbackManager() = default;
28 
29   // The completion response object for the request whose callbacks are being
30   // managed by this object.  |response| is passed as the argument for
31   // completion callbacks when the overlay UI is finished or the request is
32   // cancelled.
33   virtual void SetCompletionResponse(
34       std::unique_ptr<OverlayResponse> response) = 0;
35   virtual OverlayResponse* GetCompletionResponse() const = 0;
36 
37   // Adds a completion callback.  Provided callbacks are guaranteed to be
38   // executed once with the completion response when the overlay UI is finished
39   // or the request is cancelled.
40   virtual void AddCompletionCallback(OverlayCompletionCallback callback) = 0;
41 
42   // Dispatches |response| to all callbacks that have been added for its
43   // info type.  Used to send user interaction information back to the overlay's
44   // requester for ongoing overlay UI.
45   virtual void DispatchResponse(std::unique_ptr<OverlayResponse> response) = 0;
46 
47   // Adds |callback| to be executed for dispatched responses.  The provided
48   // callbacks are not guaranteed to be called, as there is no guarantee that a
49   // supported response will be sent for the overlay.
50   virtual void AddDispatchCallback(OverlayDispatchCallback callback) = 0;
51 };
52 
53 #endif  // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_CALLBACK_MANAGER_H_
54