| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/extensions/api/autofill_private/autofill_private_event_
router.h" | 5 #include "chrome/browser/extensions/api/autofill_private/autofill_private_event_
router.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/api/autofill_private/autofill_util.h" | 15 #include "chrome/browser/extensions/api/autofill_private/autofill_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/common/extensions/api/autofill_private.h" | 18 #include "chrome/common/extensions/api/autofill_private.h" |
| 19 #include "components/autofill/core/browser/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
| 20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 21 | 21 |
| 22 using AddressEntryList = std::vector<linked_ptr< | |
| 23 extensions::api::autofill_private::AddressEntry> >; | |
| 24 using CreditCardEntryList = std::vector<linked_ptr< | |
| 25 extensions::api::autofill_private::CreditCardEntry> >; | |
| 26 | |
| 27 namespace extensions { | 22 namespace extensions { |
| 28 | 23 |
| 29 AutofillPrivateEventRouter::AutofillPrivateEventRouter( | 24 AutofillPrivateEventRouter::AutofillPrivateEventRouter( |
| 30 content::BrowserContext* context) | 25 content::BrowserContext* context) |
| 31 : context_(context), | 26 : context_(context), |
| 32 event_router_(nullptr), | 27 event_router_(nullptr), |
| 33 personal_data_(nullptr), | 28 personal_data_(nullptr), |
| 34 listening_(false) { | 29 listening_(false) { |
| 35 // Register with the event router so we know when renderers are listening to | 30 // Register with the event router so we know when renderers are listening to |
| 36 // our events. We first check and see if there *is* an event router, because | 31 // our events. We first check and see if there *is* an event router, because |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 67 |
| 73 void AutofillPrivateEventRouter::OnListenerRemoved( | 68 void AutofillPrivateEventRouter::OnListenerRemoved( |
| 74 const EventListenerInfo& details) { | 69 const EventListenerInfo& details) { |
| 75 // Stop listening to events if there are no more listeners. | 70 // Stop listening to events if there are no more listeners. |
| 76 StartOrStopListeningForChanges(); | 71 StartOrStopListeningForChanges(); |
| 77 } | 72 } |
| 78 | 73 |
| 79 void AutofillPrivateEventRouter::OnPersonalDataChanged() { | 74 void AutofillPrivateEventRouter::OnPersonalDataChanged() { |
| 80 DCHECK(personal_data_ && personal_data_->IsDataLoaded()); | 75 DCHECK(personal_data_ && personal_data_->IsDataLoaded()); |
| 81 | 76 |
| 82 scoped_ptr<AddressEntryList> addressList = | 77 autofill_util::AddressEntryList addressList = |
| 83 extensions::autofill_util::GenerateAddressList(*personal_data_); | 78 extensions::autofill_util::GenerateAddressList(*personal_data_); |
| 84 scoped_ptr<base::ListValue> args( | 79 scoped_ptr<base::ListValue> args( |
| 85 api::autofill_private::OnAddressListChanged::Create(*addressList) | 80 api::autofill_private::OnAddressListChanged::Create(addressList) |
| 86 .release()); | 81 .release()); |
| 87 scoped_ptr<Event> extension_event( | 82 scoped_ptr<Event> extension_event( |
| 88 new Event(events::AUTOFILL_PRIVATE_ON_ADDRESS_LIST_CHANGED, | 83 new Event(events::AUTOFILL_PRIVATE_ON_ADDRESS_LIST_CHANGED, |
| 89 api::autofill_private::OnAddressListChanged::kEventName, | 84 api::autofill_private::OnAddressListChanged::kEventName, |
| 90 std::move(args))); | 85 std::move(args))); |
| 91 event_router_->BroadcastEvent(std::move(extension_event)); | 86 event_router_->BroadcastEvent(std::move(extension_event)); |
| 92 | 87 |
| 93 scoped_ptr<CreditCardEntryList> creditCardList = | 88 autofill_util::CreditCardEntryList creditCardList = |
| 94 extensions::autofill_util::GenerateCreditCardList(*personal_data_); | 89 extensions::autofill_util::GenerateCreditCardList(*personal_data_); |
| 95 args.reset( | 90 args.reset( |
| 96 api::autofill_private::OnCreditCardListChanged::Create(*creditCardList) | 91 api::autofill_private::OnCreditCardListChanged::Create(creditCardList) |
| 97 .release()); | 92 .release()); |
| 98 extension_event.reset( | 93 extension_event.reset( |
| 99 new Event(events::AUTOFILL_PRIVATE_ON_CREDIT_CARD_LIST_CHANGED, | 94 new Event(events::AUTOFILL_PRIVATE_ON_CREDIT_CARD_LIST_CHANGED, |
| 100 api::autofill_private::OnCreditCardListChanged::kEventName, | 95 api::autofill_private::OnCreditCardListChanged::kEventName, |
| 101 std::move(args))); | 96 std::move(args))); |
| 102 event_router_->BroadcastEvent(std::move(extension_event)); | 97 event_router_->BroadcastEvent(std::move(extension_event)); |
| 103 } | 98 } |
| 104 | 99 |
| 105 void AutofillPrivateEventRouter::StartOrStopListeningForChanges() { | 100 void AutofillPrivateEventRouter::StartOrStopListeningForChanges() { |
| 106 if (!personal_data_ || !personal_data_->IsDataLoaded()) | 101 if (!personal_data_ || !personal_data_->IsDataLoaded()) |
| 107 return; | 102 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 120 | 115 |
| 121 listening_ = should_listen; | 116 listening_ = should_listen; |
| 122 } | 117 } |
| 123 | 118 |
| 124 AutofillPrivateEventRouter* AutofillPrivateEventRouter::Create( | 119 AutofillPrivateEventRouter* AutofillPrivateEventRouter::Create( |
| 125 content::BrowserContext* context) { | 120 content::BrowserContext* context) { |
| 126 return new AutofillPrivateEventRouter(context); | 121 return new AutofillPrivateEventRouter(context); |
| 127 } | 122 } |
| 128 | 123 |
| 129 } // namespace extensions | 124 } // namespace extensions |
| OLD | NEW |