| 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 #include "components/payments/core/can_make_payment_query.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/time/time.h" |
| 14 |
| 15 namespace payments { |
| 16 |
| 17 CanMakePaymentQuery::CanMakePaymentQuery() {} |
| 18 |
| 19 CanMakePaymentQuery::~CanMakePaymentQuery() {} |
| 20 |
| 21 bool CanMakePaymentQuery::CanQuery( |
| 22 const GURL& frame_origin, |
| 23 const std::map<std::string, std::set<std::string>>& query) { |
| 24 const auto& it = queries_.find(frame_origin); |
| 25 if (it == queries_.end()) { |
| 26 std::unique_ptr<base::OneShotTimer> timer = |
| 27 base::MakeUnique<base::OneShotTimer>(); |
| 28 timer->Start(FROM_HERE, base::TimeDelta::FromMinutes(30), |
| 29 base::Bind(&CanMakePaymentQuery::ExpireQuotaForFrameOrigin, |
| 30 base::Unretained(this), frame_origin)); |
| 31 timers_.insert(std::make_pair(frame_origin, std::move(timer))); |
| 32 queries_.insert(std::make_pair(frame_origin, query)); |
| 33 return true; |
| 34 } |
| 35 |
| 36 return it->second == query; |
| 37 } |
| 38 |
| 39 void CanMakePaymentQuery::ExpireQuotaForFrameOrigin(const GURL& frame_origin) { |
| 40 timers_.erase(frame_origin); |
| 41 queries_.erase(frame_origin); |
| 42 } |
| 43 |
| 44 } // namespace payments |
| OLD | NEW |