Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc

Issue 1228813006: Avoid creating PasswordsPrivateDelegate when shutting down. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review issues. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698