Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: components/payments/core/can_make_payment_query.h

Issue 2866623003: PaymentRequest.canMakePayment() query quota on desktop. (Closed)
Patch Set: frame Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/payments/core/DEPS ('k') | components/payments/core/can_make_payment_query.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..69da576145362c12519f9d9676ea2bae87c78dc9
--- /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 |frame_origin| can call canMakePayment() with |query|,
+ // which is a mapping of payment method names to the corresponding
+ // JSON-stringified payment method data. Remembers the frame-to-query mapping
+ // for 30 minutes to enforce the quota.
+ bool CanQuery(const GURL& frame_origin,
+ const std::map<std::string, std::set<std::string>>& query);
+
+ private:
+ void ExpireQuotaForFrameOrigin(const GURL& frame_origin);
+
+ // A mapping of frame origin to the timer that, when fired, allows the frame
+ // to invoke canMakePayment() with a different query.
+ std::map<GURL, std::unique_ptr<base::OneShotTimer>> timers_;
+
+ // A mapping of frame 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_
« no previous file with comments | « components/payments/core/DEPS ('k') | components/payments/core/can_make_payment_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698