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

Side by Side Diff: chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager.cc

Issue 263393002: Remove NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED from c/b/e/api (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 6 years, 7 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/signed_in_devices/signed_in_devices_manager.h ('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 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"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api. h" 15 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api. h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sync/glue/device_info.h" 18 #include "chrome/browser/sync/glue/device_info.h"
20 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
21 #include "chrome/browser/sync/profile_sync_service_factory.h" 20 #include "chrome/browser/sync/profile_sync_service_factory.h"
22 #include "chrome/common/extensions/api/signed_in_devices.h" 21 #include "chrome/common/extensions/api/signed_in_devices.h"
23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h"
28 #include "extensions/browser/event_router.h" 22 #include "extensions/browser/event_router.h"
23 #include "extensions/browser/extension_registry.h"
29 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
30 25
31 using browser_sync::DeviceInfo; 26 using browser_sync::DeviceInfo;
32 namespace extensions { 27 namespace extensions {
33 28
34 namespace { 29 namespace {
35 void FillDeviceInfo(const DeviceInfo& device_info, 30 void FillDeviceInfo(const DeviceInfo& device_info,
36 api::signed_in_devices::DeviceInfo* api_device_info) { 31 api::signed_in_devices::DeviceInfo* api_device_info) {
37 api_device_info->id = device_info.public_id(); 32 api_device_info->id = device_info.public_id();
38 api_device_info->name = device_info.client_name(); 33 api_device_info->name = device_info.client_name();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 BrowserContextKeyedAPIFactory<SignedInDevicesManager> > g_factory = 90 BrowserContextKeyedAPIFactory<SignedInDevicesManager> > g_factory =
96 LAZY_INSTANCE_INITIALIZER; 91 LAZY_INSTANCE_INITIALIZER;
97 92
98 // static 93 // static
99 BrowserContextKeyedAPIFactory<SignedInDevicesManager>* 94 BrowserContextKeyedAPIFactory<SignedInDevicesManager>*
100 SignedInDevicesManager::GetFactoryInstance() { 95 SignedInDevicesManager::GetFactoryInstance() {
101 return g_factory.Pointer(); 96 return g_factory.Pointer();
102 } 97 }
103 98
104 SignedInDevicesManager::SignedInDevicesManager() 99 SignedInDevicesManager::SignedInDevicesManager()
105 : profile_(NULL) {} 100 : profile_(NULL), extension_registry_observer_(this) {
101 }
106 102
107 SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context) 103 SignedInDevicesManager::SignedInDevicesManager(content::BrowserContext* context)
108 : profile_(Profile::FromBrowserContext(context)) { 104 : profile_(Profile::FromBrowserContext(context)),
105 extension_registry_observer_(this) {
109 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); 106 extensions::EventRouter* router = extensions::EventRouter::Get(profile_);
110 if (router) { 107 if (router) {
111 router->RegisterObserver( 108 router->RegisterObserver(
112 this, api::signed_in_devices::OnDeviceInfoChange::kEventName); 109 this, api::signed_in_devices::OnDeviceInfoChange::kEventName);
113 } 110 }
114 111
115 // Register for unload event so we could clear all our listeners when 112 // Register for unload event so we could clear all our listeners when
116 // extensions have unloaded. 113 // extensions have unloaded.
117 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 114 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
118 content::Source<Profile>(profile_->GetOriginalProfile()));
119 } 115 }
120 116
121 SignedInDevicesManager::~SignedInDevicesManager() {} 117 SignedInDevicesManager::~SignedInDevicesManager() {}
122 118
123 void SignedInDevicesManager::OnListenerAdded( 119 void SignedInDevicesManager::OnListenerAdded(
124 const EventListenerInfo& details) { 120 const EventListenerInfo& details) {
125 for (ScopedVector<SignedInDevicesChangeObserver>::const_iterator it = 121 for (ScopedVector<SignedInDevicesChangeObserver>::const_iterator it =
126 change_observers_.begin(); 122 change_observers_.begin();
127 it != change_observers_.end(); 123 it != change_observers_.end();
128 ++it) { 124 ++it) {
129 if ((*it)->extension_id() == details.extension_id) { 125 if ((*it)->extension_id() == details.extension_id) {
130 DCHECK(false) <<"OnListenerAded fired twice for same extension"; 126 DCHECK(false) <<"OnListenerAded fired twice for same extension";
131 return; 127 return;
132 } 128 }
133 } 129 }
134 130
135 change_observers_.push_back(new SignedInDevicesChangeObserver( 131 change_observers_.push_back(new SignedInDevicesChangeObserver(
136 details.extension_id, 132 details.extension_id,
137 profile_)); 133 profile_));
138 } 134 }
139 135
140 void SignedInDevicesManager::OnListenerRemoved( 136 void SignedInDevicesManager::OnListenerRemoved(
141 const EventListenerInfo& details) { 137 const EventListenerInfo& details) {
142 RemoveChangeObserverForExtension(details.extension_id); 138 RemoveChangeObserverForExtension(details.extension_id);
143 } 139 }
144 140
145
146 void SignedInDevicesManager::RemoveChangeObserverForExtension( 141 void SignedInDevicesManager::RemoveChangeObserverForExtension(
147 const std::string& extension_id) { 142 const std::string& extension_id) {
148 for (ScopedVector<SignedInDevicesChangeObserver>::iterator it = 143 for (ScopedVector<SignedInDevicesChangeObserver>::iterator it =
149 change_observers_.begin(); 144 change_observers_.begin();
150 it != change_observers_.end(); 145 it != change_observers_.end();
151 ++it) { 146 ++it) {
152 if ((*it)->extension_id() == extension_id) { 147 if ((*it)->extension_id() == extension_id) {
153 change_observers_.erase(it); 148 change_observers_.erase(it);
154 return; 149 return;
155 } 150 }
156 } 151 }
157 } 152 }
158 153
159 void SignedInDevicesManager::Observe( 154 void SignedInDevicesManager::OnExtensionUnloaded(
160 int type, 155 content::BrowserContext* browser_context,
161 const content::NotificationSource& source, 156 const Extension* extension,
162 const content::NotificationDetails& details) { 157 UnloadedExtensionInfo::Reason reason) {
163 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED); 158 RemoveChangeObserverForExtension(extension->id());
164 UnloadedExtensionInfo* reason =
165 content::Details<UnloadedExtensionInfo>(details).ptr();
166 RemoveChangeObserverForExtension(reason->extension->id());
167 } 159 }
168 160
169 } // namespace extensions 161 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/signed_in_devices/signed_in_devices_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698