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

Side by Side Diff: extensions/browser/api/system_info/system_info_api.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 "extensions/browser/api/system_info/system_info_api.h" 5 #include "extensions/browser/api/system_info/system_info_api.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory>
9 #include <set> 10 #include <set>
10 #include <utility> 11 #include <utility>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "components/storage_monitor/removable_storage_observer.h" 19 #include "components/storage_monitor/removable_storage_observer.h"
20 #include "components/storage_monitor/storage_info.h" 20 #include "components/storage_monitor/storage_info.h"
21 #include "components/storage_monitor/storage_monitor.h" 21 #include "components/storage_monitor/storage_monitor.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "extensions/browser/api/system_storage/storage_info_provider.h" 23 #include "extensions/browser/api/system_storage/storage_info_provider.h"
24 #include "extensions/browser/extensions_browser_client.h" 24 #include "extensions/browser/extensions_browser_client.h"
25 #include "extensions/common/api/system_display.h" 25 #include "extensions/common/api/system_display.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // RemovableStorageObserver implementation. 71 // RemovableStorageObserver implementation.
72 void OnRemovableStorageAttached( 72 void OnRemovableStorageAttached(
73 const storage_monitor::StorageInfo& info) override; 73 const storage_monitor::StorageInfo& info) override;
74 void OnRemovableStorageDetached( 74 void OnRemovableStorageDetached(
75 const storage_monitor::StorageInfo& info) override; 75 const storage_monitor::StorageInfo& info) override;
76 76
77 // Called from any thread to dispatch the systemInfo event to all extension 77 // Called from any thread to dispatch the systemInfo event to all extension
78 // processes cross multiple profiles. 78 // processes cross multiple profiles.
79 void DispatchEvent(events::HistogramValue histogram_value, 79 void DispatchEvent(events::HistogramValue histogram_value,
80 const std::string& event_name, 80 const std::string& event_name,
81 scoped_ptr<base::ListValue> args); 81 std::unique_ptr<base::ListValue> args);
82 82
83 // Called to dispatch the systemInfo.display.onDisplayChanged event. 83 // Called to dispatch the systemInfo.display.onDisplayChanged event.
84 void OnDisplayChanged(); 84 void OnDisplayChanged();
85 85
86 // Used to record the event names being watched. 86 // Used to record the event names being watched.
87 std::multiset<std::string> watching_event_set_; 87 std::multiset<std::string> watching_event_set_;
88 88
89 bool has_storage_monitor_observer_; 89 bool has_storage_monitor_observer_;
90 90
91 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); 91 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 StorageMonitor::GetInstance()->RemoveObserver(this); 159 StorageMonitor::GetInstance()->RemoveObserver(this);
160 has_storage_monitor_observer_ = false; 160 has_storage_monitor_observer_ = false;
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 void SystemInfoEventRouter::OnRemovableStorageAttached( 165 void SystemInfoEventRouter::OnRemovableStorageAttached(
166 const storage_monitor::StorageInfo& info) { 166 const storage_monitor::StorageInfo& info) {
167 StorageUnitInfo unit; 167 StorageUnitInfo unit;
168 systeminfo::BuildStorageUnitInfo(info, &unit); 168 systeminfo::BuildStorageUnitInfo(info, &unit);
169 scoped_ptr<base::ListValue> args(new base::ListValue); 169 std::unique_ptr<base::ListValue> args(new base::ListValue);
170 args->Append(unit.ToValue().release()); 170 args->Append(unit.ToValue().release());
171 DispatchEvent(events::SYSTEM_STORAGE_ON_ATTACHED, 171 DispatchEvent(events::SYSTEM_STORAGE_ON_ATTACHED,
172 system_storage::OnAttached::kEventName, std::move(args)); 172 system_storage::OnAttached::kEventName, std::move(args));
173 } 173 }
174 174
175 void SystemInfoEventRouter::OnRemovableStorageDetached( 175 void SystemInfoEventRouter::OnRemovableStorageDetached(
176 const storage_monitor::StorageInfo& info) { 176 const storage_monitor::StorageInfo& info) {
177 scoped_ptr<base::ListValue> args(new base::ListValue); 177 std::unique_ptr<base::ListValue> args(new base::ListValue);
178 std::string transient_id = 178 std::string transient_id =
179 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( 179 StorageMonitor::GetInstance()->GetTransientIdForDeviceId(
180 info.device_id()); 180 info.device_id());
181 args->AppendString(transient_id); 181 args->AppendString(transient_id);
182 182
183 DispatchEvent(events::SYSTEM_STORAGE_ON_DETACHED, 183 DispatchEvent(events::SYSTEM_STORAGE_ON_DETACHED,
184 system_storage::OnDetached::kEventName, std::move(args)); 184 system_storage::OnDetached::kEventName, std::move(args));
185 } 185 }
186 186
187 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { 187 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) {
188 OnDisplayChanged(); 188 OnDisplayChanged();
189 } 189 }
190 190
191 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { 191 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) {
192 OnDisplayChanged(); 192 OnDisplayChanged();
193 } 193 }
194 194
195 void SystemInfoEventRouter::OnDisplayMetricsChanged(const gfx::Display& display, 195 void SystemInfoEventRouter::OnDisplayMetricsChanged(const gfx::Display& display,
196 uint32_t metrics) { 196 uint32_t metrics) {
197 OnDisplayChanged(); 197 OnDisplayChanged();
198 } 198 }
199 199
200 void SystemInfoEventRouter::OnDisplayChanged() { 200 void SystemInfoEventRouter::OnDisplayChanged() {
201 scoped_ptr<base::ListValue> args(new base::ListValue()); 201 std::unique_ptr<base::ListValue> args(new base::ListValue());
202 DispatchEvent(events::SYSTEM_DISPLAY_ON_DISPLAY_CHANGED, 202 DispatchEvent(events::SYSTEM_DISPLAY_ON_DISPLAY_CHANGED,
203 system_display::OnDisplayChanged::kEventName, std::move(args)); 203 system_display::OnDisplayChanged::kEventName, std::move(args));
204 } 204 }
205 205
206 void SystemInfoEventRouter::DispatchEvent( 206 void SystemInfoEventRouter::DispatchEvent(
207 events::HistogramValue histogram_value, 207 events::HistogramValue histogram_value,
208 const std::string& event_name, 208 const std::string& event_name,
209 scoped_ptr<base::ListValue> args) { 209 std::unique_ptr<base::ListValue> args) {
210 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers( 210 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(
211 histogram_value, event_name, std::move(args)); 211 histogram_value, event_name, std::move(args));
212 } 212 }
213 213
214 void AddEventListener(const std::string& event_name) { 214 void AddEventListener(const std::string& event_name) {
215 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); 215 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name);
216 } 216 }
217 217
218 void RemoveEventListener(const std::string& event_name) { 218 void RemoveEventListener(const std::string& event_name) {
219 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); 219 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 257 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
258 if (IsSystemStorageEvent(details.event_name)) { 258 if (IsSystemStorageEvent(details.event_name)) {
259 StorageMonitor::GetInstance()->EnsureInitialized( 259 StorageMonitor::GetInstance()->EnsureInitialized(
260 base::Bind(&RemoveEventListener, details.event_name)); 260 base::Bind(&RemoveEventListener, details.event_name));
261 } else { 261 } else {
262 RemoveEventListener(details.event_name); 262 RemoveEventListener(details.event_name);
263 } 263 }
264 } 264 }
265 265
266 } // namespace extensions 266 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698