1 // Copyright 2020 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_AUTOFILL_CORE_BROWSER_PAYMENTS_AUTOFILL_OFFER_MANAGER_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_AUTOFILL_OFFER_MANAGER_H_ 7 8 #include <stdint.h> 9 #include <map> 10 #include <string> 11 #include <vector> 12 13 #include "base/strings/string16.h" 14 #include "base/time/time.h" 15 #include "base/timer/timer.h" 16 #include "components/autofill/core/browser/autofill_client.h" 17 #include "components/autofill/core/browser/data_model/autofill_offer_data.h" 18 #include "components/autofill/core/browser/personal_data_manager.h" 19 #include "components/autofill/core/browser/personal_data_manager_observer.h" 20 #include "components/keyed_service/core/keyed_service.h" 21 #include "url/gurl.h" 22 23 namespace autofill { 24 25 // Manages all Autofill related offers. One per frame; owned by the 26 // AutofillManager. 27 class AutofillOfferManager : public KeyedService, 28 public PersonalDataManagerObserver { 29 public: 30 // Mapping from suggestion backend ID to offer data. 31 using OffersMap = std::map<std::string, AutofillOfferData*>; 32 33 explicit AutofillOfferManager(PersonalDataManager* personal_data); 34 ~AutofillOfferManager() override; 35 AutofillOfferManager(const AutofillOfferManager&) = delete; 36 AutofillOfferManager& operator=(const AutofillOfferManager&) = delete; 37 38 // PersonalDataManagerObserver: 39 void OnPersonalDataChanged() override; 40 41 // Modifies any suggestion in |suggestions| if it has related offer data. 42 void UpdateSuggestionsWithOffers(const GURL& last_committed_url, 43 std::vector<Suggestion>& suggestions); 44 45 private: 46 // Queries |personal_data_| to reset the elements of 47 // |eligible_merchant_domains_| 48 void UpdateEligibleMerchantDomains(); 49 50 // Creates a mapping from Suggestion Backend ID's to eligible Credit Card 51 // Offers. 52 OffersMap CreateOffersMap(const GURL& last_committed_url_origin) const; 53 54 PersonalDataManager* personal_data_; 55 std::set<GURL> eligible_merchant_domains_ = {}; 56 }; 57 58 } // namespace autofill 59 60 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_AUTOFILL_OFFER_MANAGER_H_ 61