| OLD | NEW |
| (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 #ifndef COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |
| 6 #define COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 #include <set> |
| 11 #include <string> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace payments { |
| 19 |
| 20 // Keeps track of canMakePayment() queries per browser context. |
| 21 class CanMakePaymentQuery : public KeyedService { |
| 22 public: |
| 23 CanMakePaymentQuery(); |
| 24 ~CanMakePaymentQuery() override; |
| 25 |
| 26 // Returns whether |frame_origin| can call canMakePayment() with |query|, |
| 27 // which is a mapping of payment method names to the corresponding |
| 28 // JSON-stringified payment method data. Remembers the frame-to-query mapping |
| 29 // for 30 minutes to enforce the quota. |
| 30 bool CanQuery(const GURL& frame_origin, |
| 31 const std::map<std::string, std::set<std::string>>& query); |
| 32 |
| 33 private: |
| 34 void ExpireQuotaForFrameOrigin(const GURL& frame_origin); |
| 35 |
| 36 // A mapping of frame origin to the timer that, when fired, allows the frame |
| 37 // to invoke canMakePayment() with a different query. |
| 38 std::map<GURL, std::unique_ptr<base::OneShotTimer>> timers_; |
| 39 |
| 40 // A mapping of frame origin to its last query. Each query is a mapping of |
| 41 // payment method names to the corresponding JSON-stringified payment method |
| 42 // data. |
| 43 std::map<GURL, std::map<std::string, std::set<std::string>>> queries_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(CanMakePaymentQuery); |
| 46 }; |
| 47 |
| 48 } // namespace payments |
| 49 |
| 50 #endif // COMPONENTS_PAYMENTS_CORE_CAN_MAKE_PAYMENT_QUERY_H_ |
| OLD | NEW |