Chromium Code Reviews| Index: components/payments/core/can_make_payment_query.h |
| diff --git a/components/payments/core/can_make_payment_query.h b/components/payments/core/can_make_payment_query.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8369e762afc5c7d8be59f42e6db764b2488d89eb |
| --- /dev/null |
| +++ b/components/payments/core/can_make_payment_query.h |
| @@ -0,0 +1,50 @@ |
| +// 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 COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |
| +#define COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |
| + |
| +#include <map> |
| +#include <memory> |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| +#include "base/timer/timer.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| +#include "url/gurl.h" |
| + |
| +namespace payments { |
| + |
| +// Keeps track of canMakePayment() queries per browser context. |
| +class CanMakePaymentQuery : public KeyedService { |
| + public: |
| + CanMakePaymentQuery(); |
| + ~CanMakePaymentQuery() override; |
| + |
| + // Returns whether |iframe_origin| can call canMakePayment() with |query|, |
| + // which is a mapping of payment method names to the corresponding |
| + // JSON-stringified payment method data. Remembers the iframe-to-query mapping |
|
Mathieu
2017/05/08 15:28:11
see other comment, name this *frame instead of ifr
please use gerrit instead
2017/05/08 17:28:47
Done.
|
| + // for 30 minutes to enforce the quota. |
| + bool CanQuery(const GURL& iframe_origin, |
| + const std::map<std::string, std::set<std::string>>& query); |
| + |
| + private: |
| + void ExpireQuotaForIframeOrigin(const GURL& iframe_origin); |
| + |
| + // A mapping of iframe origin to the timer that, when fired, allows the iframe |
| + // to invoke canMakePayment() with a different query. |
| + std::map<GURL, std::unique_ptr<base::OneShotTimer>> timers_; |
| + |
| + // A mapping of iframe origin to its last query. Each query is a mapping of |
| + // payment method names to the corresponding JSON-stringified payment method |
| + // data. |
| + std::map<GURL, std::map<std::string, std::set<std::string>>> queries_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CanMakePaymentQuery); |
| +}; |
| + |
| +} // namespace payments |
| + |
| +#endif // COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |