OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signed_in_devices/signed_in_devices_mana
ger.h" | 5 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_mana
ger.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return g_factory.Pointer(); | 97 return g_factory.Pointer(); |
98 } | 98 } |
99 | 99 |
100 SignedInDevicesManager::SignedInDevicesManager() | 100 SignedInDevicesManager::SignedInDevicesManager() |
101 : profile_(NULL), extension_registry_observer_(this) { | 101 : profile_(NULL), extension_registry_observer_(this) { |
102 } | 102 } |
103 | 103 |
104 SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context) | 104 SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context) |
105 : profile_(Profile::FromBrowserContext(context)), | 105 : profile_(Profile::FromBrowserContext(context)), |
106 extension_registry_observer_(this) { | 106 extension_registry_observer_(this) { |
107 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); | 107 EventRouter* router = EventRouter::Get(profile_); |
108 if (router) { | 108 if (router) { |
109 router->RegisterObserver( | 109 router->RegisterObserver( |
110 this, api::signed_in_devices::OnDeviceInfoChange::kEventName); | 110 this, api::signed_in_devices::OnDeviceInfoChange::kEventName); |
111 } | 111 } |
112 | 112 |
113 // Register for unload event so we could clear all our listeners when | 113 // Register for unload event so we could clear all our listeners when |
114 // extensions have unloaded. | 114 // extensions have unloaded. |
115 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 115 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
116 } | 116 } |
117 | 117 |
118 SignedInDevicesManager::~SignedInDevicesManager() {} | 118 SignedInDevicesManager::~SignedInDevicesManager() { |
| 119 if (profile_) { |
| 120 EventRouter* router = EventRouter::Get(profile_); |
| 121 if (router) |
| 122 router->UnregisterObserver(this); |
| 123 } |
| 124 } |
119 | 125 |
120 void SignedInDevicesManager::OnListenerAdded( | 126 void SignedInDevicesManager::OnListenerAdded( |
121 const EventListenerInfo& details) { | 127 const EventListenerInfo& details) { |
122 for (ScopedVector<SignedInDevicesChangeObserver>::const_iterator it = | 128 for (ScopedVector<SignedInDevicesChangeObserver>::const_iterator it = |
123 change_observers_.begin(); | 129 change_observers_.begin(); |
124 it != change_observers_.end(); | 130 it != change_observers_.end(); |
125 ++it) { | 131 ++it) { |
126 if ((*it)->extension_id() == details.extension_id) { | 132 if ((*it)->extension_id() == details.extension_id) { |
127 DCHECK(false) <<"OnListenerAded fired twice for same extension"; | 133 DCHECK(false) <<"OnListenerAded fired twice for same extension"; |
128 return; | 134 return; |
(...skipping 24 matching lines...) Expand all Loading... |
153 } | 159 } |
154 | 160 |
155 void SignedInDevicesManager::OnExtensionUnloaded( | 161 void SignedInDevicesManager::OnExtensionUnloaded( |
156 content::BrowserContext* browser_context, | 162 content::BrowserContext* browser_context, |
157 const Extension* extension, | 163 const Extension* extension, |
158 UnloadedExtensionInfo::Reason reason) { | 164 UnloadedExtensionInfo::Reason reason) { |
159 RemoveChangeObserverForExtension(extension->id()); | 165 RemoveChangeObserverForExtension(extension->id()); |
160 } | 166 } |
161 | 167 |
162 } // namespace extensions | 168 } // namespace extensions |
OLD | NEW |