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

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

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/can_make_payment_query.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/core/can_make_payment_query.cc
diff --git a/components/payments/core/can_make_payment_query.cc b/components/payments/core/can_make_payment_query.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c4264be89be3d767e62669779f2cea2b7c0a4c44
--- /dev/null
+++ b/components/payments/core/can_make_payment_query.cc
@@ -0,0 +1,44 @@
+// 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.
+
+#include "components/payments/core/can_make_payment_query.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/location.h"
+#include "base/memory/ptr_util.h"
+#include "base/time/time.h"
+
+namespace payments {
+
+CanMakePaymentQuery::CanMakePaymentQuery() {}
+
+CanMakePaymentQuery::~CanMakePaymentQuery() {}
+
+bool CanMakePaymentQuery::CanQuery(
+ const GURL& frame_origin,
+ const std::map<std::string, std::set<std::string>>& query) {
+ const auto& it = queries_.find(frame_origin);
+ if (it == queries_.end()) {
+ std::unique_ptr<base::OneShotTimer> timer =
+ base::MakeUnique<base::OneShotTimer>();
+ timer->Start(FROM_HERE, base::TimeDelta::FromMinutes(30),
+ base::Bind(&CanMakePaymentQuery::ExpireQuotaForFrameOrigin,
+ base::Unretained(this), frame_origin));
+ timers_.insert(std::make_pair(frame_origin, std::move(timer)));
+ queries_.insert(std::make_pair(frame_origin, query));
+ return true;
+ }
+
+ return it->second == query;
+}
+
+void CanMakePaymentQuery::ExpireQuotaForFrameOrigin(const GURL& frame_origin) {
+ timers_.erase(frame_origin);
+ queries_.erase(frame_origin);
+}
+
+} // namespace payments
« no previous file with comments | « components/payments/core/can_make_payment_query.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698