| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/payments/content/payment_manifest_parser_host.h" | 5 #include "components/payments/content/payment_manifest_parser_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const std::vector<GURL>& web_app_manifest_urls) { | 75 const std::vector<GURL>& web_app_manifest_urls) { |
| 76 const auto& pending_callback_it = | 76 const auto& pending_callback_it = |
| 77 pending_payment_method_callbacks_.find(callback_identifier); | 77 pending_payment_method_callbacks_.find(callback_identifier); |
| 78 if (pending_callback_it == pending_payment_method_callbacks_.end()) { | 78 if (pending_callback_it == pending_payment_method_callbacks_.end()) { |
| 79 // If unable to find the pending callback, then something went wrong in the | 79 // If unable to find the pending callback, then something went wrong in the |
| 80 // utility process. Stop the utility process and notify all callbacks. | 80 // utility process. Stop the utility process and notify all callbacks. |
| 81 OnUtilityProcessStopped(); | 81 OnUtilityProcessStopped(); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 PaymentMethodCallback callback = std::move(pending_callback_it->second); | |
| 86 pending_payment_method_callbacks_.erase(pending_callback_it); | |
| 87 | |
| 88 const size_t kMaximumNumberOfWebAppUrls = 100U; | 85 const size_t kMaximumNumberOfWebAppUrls = 100U; |
| 89 if (web_app_manifest_urls.size() > kMaximumNumberOfWebAppUrls) { | 86 if (web_app_manifest_urls.size() > kMaximumNumberOfWebAppUrls) { |
| 90 // If more than 100 items, then something went wrong in the utility | 87 // If more than 100 items, then something went wrong in the utility |
| 91 // process. Stop the utility process and notify all callbacks. | 88 // process. Stop the utility process and notify all callbacks. |
| 92 OnUtilityProcessStopped(); | 89 OnUtilityProcessStopped(); |
| 93 return; | 90 return; |
| 94 } | 91 } |
| 95 | 92 |
| 96 for (const auto& url : web_app_manifest_urls) { | 93 for (const auto& url : web_app_manifest_urls) { |
| 97 if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme)) { | 94 if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme)) { |
| 98 // If not a valid URL with HTTPS scheme, then something went wrong in the | 95 // If not a valid URL with HTTPS scheme, then something went wrong in the |
| 99 // utility process. Stop the utility process and notify all callbacks. | 96 // utility process. Stop the utility process and notify all callbacks. |
| 100 OnUtilityProcessStopped(); | 97 OnUtilityProcessStopped(); |
| 101 return; | 98 return; |
| 102 } | 99 } |
| 103 } | 100 } |
| 104 | 101 |
| 102 PaymentMethodCallback callback = std::move(pending_callback_it->second); |
| 103 pending_payment_method_callbacks_.erase(pending_callback_it); |
| 104 |
| 105 // Can trigger synchronous deletion of this object, so can't access any of | 105 // Can trigger synchronous deletion of this object, so can't access any of |
| 106 // the member variables after this block. | 106 // the member variables after this block. |
| 107 std::move(callback).Run(web_app_manifest_urls); | 107 std::move(callback).Run(web_app_manifest_urls); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void PaymentManifestParserHost::OnWebAppParse( | 110 void PaymentManifestParserHost::OnWebAppParse( |
| 111 int64_t callback_identifier, | 111 int64_t callback_identifier, |
| 112 std::vector<mojom::WebAppManifestSectionPtr> manifest) { | 112 std::vector<mojom::WebAppManifestSectionPtr> manifest) { |
| 113 const auto& pending_callback_it = | 113 const auto& pending_callback_it = |
| 114 pending_web_app_callbacks_.find(callback_identifier); | 114 pending_web_app_callbacks_.find(callback_identifier); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 for (auto& callback : web_app_callbacks) { | 162 for (auto& callback : web_app_callbacks) { |
| 163 // Can trigger synchronous deletion of this object, so can't access any of | 163 // Can trigger synchronous deletion of this object, so can't access any of |
| 164 // the member variables after this line. | 164 // the member variables after this line. |
| 165 std::move(callback.second) | 165 std::move(callback.second) |
| 166 .Run(std::vector<mojom::WebAppManifestSectionPtr>()); | 166 .Run(std::vector<mojom::WebAppManifestSectionPtr>()); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace payments | 170 } // namespace payments |
| OLD | NEW |