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

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

Issue 2310683002: Remove most ScopedVector usage from c/b/extensions. (Closed)
Patch Set: remove scoped_vector includes Created 4 years, 3 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
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #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"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/common/extensions/api/signed_in_devices.h" 19 #include "chrome/common/extensions/api/signed_in_devices.h"
20 #include "components/browser_sync/browser/profile_sync_service.h" 20 #include "components/browser_sync/browser/profile_sync_service.h"
21 #include "components/sync/device_info/device_info.h" 21 #include "components/sync/device_info/device_info.h"
22 #include "extensions/browser/event_router.h" 22 #include "extensions/browser/event_router.h"
23 #include "extensions/browser/extension_registry.h" 23 #include "extensions/browser/extension_registry.h"
(...skipping 30 matching lines...) Expand all
54 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_); 54 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_);
55 if (pss) { 55 if (pss) {
56 DCHECK(pss->GetDeviceInfoTracker()); 56 DCHECK(pss->GetDeviceInfoTracker());
57 pss->GetDeviceInfoTracker()->RemoveObserver(this); 57 pss->GetDeviceInfoTracker()->RemoveObserver(this);
58 } 58 }
59 } 59 }
60 60
61 void SignedInDevicesChangeObserver::OnDeviceInfoChange() { 61 void SignedInDevicesChangeObserver::OnDeviceInfoChange() {
62 // There is a change in the list of devices. Get all devices and send them to 62 // There is a change in the list of devices. Get all devices and send them to
63 // the listener. 63 // the listener.
64 ScopedVector<DeviceInfo> devices = GetAllSignedInDevices(extension_id_, 64 std::vector<std::unique_ptr<DeviceInfo>> devices =
65 profile_); 65 GetAllSignedInDevices(extension_id_, profile_);
66 66
67 std::vector<api::signed_in_devices::DeviceInfo> args; 67 std::vector<api::signed_in_devices::DeviceInfo> args;
68 for (const DeviceInfo* info : devices) { 68 for (const std::unique_ptr<DeviceInfo>& info : devices) {
69 api::signed_in_devices::DeviceInfo api_device; 69 api::signed_in_devices::DeviceInfo api_device;
70 FillDeviceInfo(*info, &api_device); 70 FillDeviceInfo(*info, &api_device);
71 args.push_back(std::move(api_device)); 71 args.push_back(std::move(api_device));
72 } 72 }
73 73
74 std::unique_ptr<base::ListValue> result = 74 std::unique_ptr<base::ListValue> result =
75 api::signed_in_devices::OnDeviceInfoChange::Create(args); 75 api::signed_in_devices::OnDeviceInfoChange::Create(args);
76 std::unique_ptr<Event> event( 76 std::unique_ptr<Event> event(
77 new Event(events::SIGNED_IN_DEVICES_ON_DEVICE_INFO_CHANGE, 77 new Event(events::SIGNED_IN_DEVICES_ON_DEVICE_INFO_CHANGE,
78 api::signed_in_devices::OnDeviceInfoChange::kEventName, 78 api::signed_in_devices::OnDeviceInfoChange::kEventName,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SignedInDevicesManager::~SignedInDevicesManager() { 115 SignedInDevicesManager::~SignedInDevicesManager() {
116 if (profile_) { 116 if (profile_) {
117 EventRouter* router = EventRouter::Get(profile_); 117 EventRouter* router = EventRouter::Get(profile_);
118 if (router) 118 if (router)
119 router->UnregisterObserver(this); 119 router->UnregisterObserver(this);
120 } 120 }
121 } 121 }
122 122
123 void SignedInDevicesManager::OnListenerAdded( 123 void SignedInDevicesManager::OnListenerAdded(
124 const EventListenerInfo& details) { 124 const EventListenerInfo& details) {
125 for (ScopedVector<SignedInDevicesChangeObserver>::const_iterator it = 125 for (const std::unique_ptr<SignedInDevicesChangeObserver>& observer :
126 change_observers_.begin(); 126 change_observers_) {
127 it != change_observers_.end(); 127 if (observer->extension_id() == details.extension_id) {
128 ++it) {
129 if ((*it)->extension_id() == details.extension_id) {
130 DCHECK(false) <<"OnListenerAded fired twice for same extension"; 128 DCHECK(false) <<"OnListenerAded fired twice for same extension";
131 return; 129 return;
132 } 130 }
133 } 131 }
134 132
135 change_observers_.push_back(new SignedInDevicesChangeObserver( 133 change_observers_.push_back(base::MakeUnique<SignedInDevicesChangeObserver>(
136 details.extension_id, 134 details.extension_id, profile_));
137 profile_));
138 } 135 }
139 136
140 void SignedInDevicesManager::OnListenerRemoved( 137 void SignedInDevicesManager::OnListenerRemoved(
141 const EventListenerInfo& details) { 138 const EventListenerInfo& details) {
142 RemoveChangeObserverForExtension(details.extension_id); 139 RemoveChangeObserverForExtension(details.extension_id);
143 } 140 }
144 141
145 void SignedInDevicesManager::RemoveChangeObserverForExtension( 142 void SignedInDevicesManager::RemoveChangeObserverForExtension(
146 const std::string& extension_id) { 143 const std::string& extension_id) {
147 for (ScopedVector<SignedInDevicesChangeObserver>::iterator it = 144 for (std::vector<std::unique_ptr<SignedInDevicesChangeObserver>>::iterator
148 change_observers_.begin(); 145 it = change_observers_.begin();
149 it != change_observers_.end(); 146 it != change_observers_.end(); ++it) {
150 ++it) {
151 if ((*it)->extension_id() == extension_id) { 147 if ((*it)->extension_id() == extension_id) {
152 change_observers_.erase(it); 148 change_observers_.erase(it);
153 return; 149 return;
154 } 150 }
155 } 151 }
156 } 152 }
157 153
158 void SignedInDevicesManager::OnExtensionUnloaded( 154 void SignedInDevicesManager::OnExtensionUnloaded(
159 content::BrowserContext* browser_context, 155 content::BrowserContext* browser_context,
160 const Extension* extension, 156 const Extension* extension,
161 UnloadedExtensionInfo::Reason reason) { 157 UnloadedExtensionInfo::Reason reason) {
162 RemoveChangeObserverForExtension(extension->id()); 158 RemoveChangeObserverForExtension(extension->id());
163 } 159 }
164 160
165 } // namespace extensions 161 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698