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

Side by Side Diff: device/hid/hid_service.cc

Issue 1074963003: Clean up potentially leaky use of base::DeletePointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed another probleb Created 5 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
« no previous file with comments | « device/hid/hid_service.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "device/hid/hid_service.h" 5 #include "device/hid/hid_service.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 27 matching lines...) Expand all
38 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) { 38 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
39 if (g_service == NULL) { 39 if (g_service == NULL) {
40 #if defined(OS_LINUX) && defined(USE_UDEV) 40 #if defined(OS_LINUX) && defined(USE_UDEV)
41 g_service = new HidServiceLinux(file_task_runner); 41 g_service = new HidServiceLinux(file_task_runner);
42 #elif defined(OS_MACOSX) 42 #elif defined(OS_MACOSX)
43 g_service = new HidServiceMac(file_task_runner); 43 g_service = new HidServiceMac(file_task_runner);
44 #elif defined(OS_WIN) 44 #elif defined(OS_WIN)
45 g_service = new HidServiceWin(file_task_runner); 45 g_service = new HidServiceWin(file_task_runner);
46 #endif 46 #endif
47 if (g_service != nullptr) { 47 if (g_service != nullptr) {
48 scoped_ptr<HidService> owned_service(g_service);
48 base::AtExitManager::RegisterTask(base::Bind( 49 base::AtExitManager::RegisterTask(base::Bind(
49 &base::DeletePointer<HidService>, base::Unretained(g_service))); 50 &base::DeletePointer<HidService>, base::Passed(&owned_service)));
50 } 51 }
51 } 52 }
52 return g_service; 53 return g_service;
53 } 54 }
54 55
55 void HidService::SetInstanceForTest(HidService* instance) { 56 void HidService::SetInstanceForTest(HidService* instance) {
56 DCHECK(!g_service); 57 DCHECK(!g_service);
57 g_service = instance; 58 g_service = instance;
59 scoped_ptr<HidService> owned_service(instance);
58 base::AtExitManager::RegisterTask(base::Bind(&base::DeletePointer<HidService>, 60 base::AtExitManager::RegisterTask(base::Bind(&base::DeletePointer<HidService>,
59 base::Unretained(g_service))); 61 base::Passed(&owned_service)));
60 } 62 }
61 63
62 void HidService::GetDevices(const GetDevicesCallback& callback) { 64 void HidService::GetDevices(const GetDevicesCallback& callback) {
63 DCHECK(thread_checker_.CalledOnValidThread()); 65 DCHECK(thread_checker_.CalledOnValidThread());
64 if (enumeration_ready_) { 66 if (enumeration_ready_) {
65 std::vector<scoped_refptr<HidDeviceInfo>> devices; 67 std::vector<scoped_refptr<HidDeviceInfo>> devices;
66 for (const auto& map_entry : devices_) { 68 for (const auto& map_entry : devices_) {
67 devices.push_back(map_entry.second); 69 devices.push_back(map_entry.second);
68 } 70 }
69 base::MessageLoop::current()->PostTask(FROM_HERE, 71 base::MessageLoop::current()->PostTask(FROM_HERE,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 143 }
142 144
143 for (const GetDevicesCallback& callback : pending_enumerations_) { 145 for (const GetDevicesCallback& callback : pending_enumerations_) {
144 callback.Run(devices); 146 callback.Run(devices);
145 } 147 }
146 pending_enumerations_.clear(); 148 pending_enumerations_.clear();
147 } 149 }
148 } 150 }
149 151
150 } // namespace device 152 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_service.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698