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

Side by Side Diff: device/usb/usb_service.h

Issue 2204713006: Add chrome://usb-internals page for adding and removing test devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use typemaped types in the TestDeviceInfo struct. Created 4 years, 4 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/common/url_constants.cc ('k') | device/usb/usb_service.cc » ('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 #ifndef DEVICE_USB_USB_SERVICE_H_ 5 #ifndef DEVICE_USB_USB_SERVICE_H_
6 #define DEVICE_USB_USB_SERVICE_H_ 6 #define DEVICE_USB_USB_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <unordered_map> 10 #include <unordered_map>
11 #include <unordered_set>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
18 19
19 namespace base { 20 namespace base {
20 class SequencedTaskRunner; 21 class SequencedTaskRunner;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual ~UsbService(); 58 virtual ~UsbService();
58 59
59 scoped_refptr<UsbDevice> GetDevice(const std::string& guid); 60 scoped_refptr<UsbDevice> GetDevice(const std::string& guid);
60 61
61 // Enumerates available devices. 62 // Enumerates available devices.
62 virtual void GetDevices(const GetDevicesCallback& callback); 63 virtual void GetDevices(const GetDevicesCallback& callback);
63 64
64 void AddObserver(Observer* observer); 65 void AddObserver(Observer* observer);
65 void RemoveObserver(Observer* observer); 66 void RemoveObserver(Observer* observer);
66 67
68 // Methods to add and remove devices for testing purposes. Only a device added
69 // by this method can be removed by RemoveDeviceForTesting().
70 void AddDeviceForTesting(scoped_refptr<UsbDevice> device);
71 void RemoveDeviceForTesting(const std::string& device_guid);
72 void GetTestDevices(std::vector<scoped_refptr<UsbDevice>>* devices);
73
67 protected: 74 protected:
68 UsbService(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 75 UsbService(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
69 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); 76 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
70 77
71 void NotifyDeviceAdded(scoped_refptr<UsbDevice> device); 78 void NotifyDeviceAdded(scoped_refptr<UsbDevice> device);
72 void NotifyDeviceRemoved(scoped_refptr<UsbDevice> device); 79 void NotifyDeviceRemoved(scoped_refptr<UsbDevice> device);
73 80
74 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { 81 scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
75 return task_runner_; 82 return task_runner_;
76 } 83 }
77 84
78 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner() { 85 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner() {
79 return blocking_task_runner_; 86 return blocking_task_runner_;
80 } 87 }
81 88
82 std::unordered_map<std::string, scoped_refptr<UsbDevice>>& devices() { 89 std::unordered_map<std::string, scoped_refptr<UsbDevice>>& devices() {
83 return devices_; 90 return devices_;
84 } 91 }
85 92
86 private: 93 private:
87 friend void base::DeletePointer<UsbService>(UsbService* service); 94 friend void base::DeletePointer<UsbService>(UsbService* service);
88 95
89 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 96 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
90 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 97 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
91 std::unordered_map<std::string, scoped_refptr<UsbDevice>> devices_; 98 std::unordered_map<std::string, scoped_refptr<UsbDevice>> devices_;
99 std::unordered_set<std::string> testing_devices_;
92 base::ObserverList<Observer, true> observer_list_; 100 base::ObserverList<Observer, true> observer_list_;
93 101
94 DISALLOW_COPY_AND_ASSIGN(UsbService); 102 DISALLOW_COPY_AND_ASSIGN(UsbService);
95 }; 103 };
96 104
97 } // namespace device 105 } // namespace device
98 106
99 #endif // DEVICE_USB_USB_SERVICE_H_ 107 #endif // DEVICE_USB_USB_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/common/url_constants.cc ('k') | device/usb/usb_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698