blob: 9609801ef77790d9860ec7d7a1908a55f0c230c1 [file] [log] [blame]
Anthony Vallee-Duboisc7ae7332017-12-19 20:44:071// 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#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_DISPLAY_MANAGER_H_
6#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_DISPLAY_MANAGER_H_
7
8#include <memory>
9
10#include "base/macros.h"
11#include "components/keyed_service/core/keyed_service.h"
12
13namespace payments {
14
15class ContentPaymentRequestDelegate;
16class PaymentRequest;
17
18// This KeyedService is responsible for displaying and hiding Payment Request
19// UI. It ensures that only one Payment Request is showing per profile.
20class PaymentRequestDisplayManager : public KeyedService {
21 public:
22 class DisplayHandle {
23 public:
24 explicit DisplayHandle(PaymentRequestDisplayManager* display_manager);
25 ~DisplayHandle();
26 void Show(ContentPaymentRequestDelegate* delegate, PaymentRequest* request);
27
28 private:
29 PaymentRequestDisplayManager* display_manager_;
30 DISALLOW_COPY_AND_ASSIGN(DisplayHandle);
31 };
32
33 PaymentRequestDisplayManager();
34 ~PaymentRequestDisplayManager() override;
35
36 // If no PaymentRequest is currently showing, returns a unique_ptr to a
37 // display handle that can be used to display the PaymentRequest dialog. The
38 // UI is considered open until the handle object is deleted.
39 std::unique_ptr<DisplayHandle> TryShow();
40
41 private:
42 void SetHandleAlive(bool handle_alive);
43
44 bool handle_alive_;
45
46 DISALLOW_COPY_AND_ASSIGN(PaymentRequestDisplayManager);
47};
48
49} // namespace payments
50
51#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_DISPLAY_MANAGER_H_