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/passwords_private/passwords_private_even
t_router.h" | 5 #include "chrome/browser/extensions/api/passwords_private/passwords_private_even
t_router.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 api::passwords_private::OnPlaintextPasswordRetrieved::kEventName); | 41 api::passwords_private::OnPlaintextPasswordRetrieved::kEventName); |
42 } | 42 } |
43 | 43 |
44 PasswordsPrivateEventRouter::~PasswordsPrivateEventRouter() {} | 44 PasswordsPrivateEventRouter::~PasswordsPrivateEventRouter() {} |
45 | 45 |
46 void PasswordsPrivateEventRouter::Shutdown() { | 46 void PasswordsPrivateEventRouter::Shutdown() { |
47 if (event_router_) | 47 if (event_router_) |
48 event_router_->UnregisterObserver(this); | 48 event_router_->UnregisterObserver(this); |
49 | 49 |
50 PasswordsPrivateDelegate* delegate = | 50 PasswordsPrivateDelegate* delegate = |
51 PasswordsPrivateDelegateFactory::GetForBrowserContext(context_); | 51 PasswordsPrivateDelegateFactory::GetForBrowserContext(context_, |
52 delegate->RemoveObserver(this); | 52 false /* create */); |
| 53 if (delegate) |
| 54 delegate->RemoveObserver(this); |
53 } | 55 } |
54 | 56 |
55 void PasswordsPrivateEventRouter::OnListenerAdded( | 57 void PasswordsPrivateEventRouter::OnListenerAdded( |
56 const EventListenerInfo& details) { | 58 const EventListenerInfo& details) { |
57 // Start listening to change events and propagate the original lists to | 59 // Start listening to change events and propagate the original lists to |
58 // listeners. | 60 // listeners. |
59 StartOrStopListeningForChanges(); | 61 StartOrStopListeningForChanges(); |
60 SendSavedPasswordListToListeners(); | 62 SendSavedPasswordListToListeners(); |
61 SendPasswordExceptionListToListeners(); | 63 SendPasswordExceptionListToListeners(); |
62 } | 64 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 event_router_->HasEventListener( | 136 event_router_->HasEventListener( |
135 api::passwords_private::OnPasswordExceptionsListChanged::kEventName); | 137 api::passwords_private::OnPasswordExceptionsListChanged::kEventName); |
136 bool should_listen_for_plaintext_password_retrieval = | 138 bool should_listen_for_plaintext_password_retrieval = |
137 event_router_->HasEventListener( | 139 event_router_->HasEventListener( |
138 api::passwords_private::OnPlaintextPasswordRetrieved::kEventName); | 140 api::passwords_private::OnPlaintextPasswordRetrieved::kEventName); |
139 bool should_listen = should_listen_for_saved_password_changes || | 141 bool should_listen = should_listen_for_saved_password_changes || |
140 should_listen_for_password_exception_changes || | 142 should_listen_for_password_exception_changes || |
141 should_listen_for_plaintext_password_retrieval; | 143 should_listen_for_plaintext_password_retrieval; |
142 | 144 |
143 PasswordsPrivateDelegate* delegate = | 145 PasswordsPrivateDelegate* delegate = |
144 PasswordsPrivateDelegateFactory::GetForBrowserContext(context_); | 146 PasswordsPrivateDelegateFactory::GetForBrowserContext(context_, |
| 147 true /* create */); |
145 if (should_listen && !listening_) | 148 if (should_listen && !listening_) |
146 delegate->AddObserver(this); | 149 delegate->AddObserver(this); |
147 else if (!should_listen && listening_) | 150 else if (!should_listen && listening_) |
148 delegate->RemoveObserver(this); | 151 delegate->RemoveObserver(this); |
149 | 152 |
150 listening_ = should_listen; | 153 listening_ = should_listen; |
151 } | 154 } |
152 | 155 |
153 PasswordsPrivateEventRouter* PasswordsPrivateEventRouter::Create( | 156 PasswordsPrivateEventRouter* PasswordsPrivateEventRouter::Create( |
154 content::BrowserContext* context) { | 157 content::BrowserContext* context) { |
155 return new PasswordsPrivateEventRouter(context); | 158 return new PasswordsPrivateEventRouter(context); |
156 } | 159 } |
157 | 160 |
158 } // namespace extensions | 161 } // namespace extensions |
OLD | NEW |