Commit ce69e2ad authored by reillyg's avatar reillyg Committed by Commit bot

Make the device::HidService destructor protected.

This prevents anything other than device::HidService::Destroyer from
calling the destructor. For example, scoped_ptr, as was the case in
HidConnectionTest.

BUG=

Review URL: https://codereview.chromium.org/542153004

Cr-Commit-Position: refs/heads/master@{#293623}
parent 4e279527
......@@ -73,8 +73,7 @@ class HidConnectionTest : public testing::Test {
if (!UsbTestGadget::IsTestEnabled()) return;
message_loop_.reset(new base::MessageLoopForIO());
service_.reset(HidService::GetInstance(
message_loop_->message_loop_proxy()));
service_ = HidService::GetInstance(message_loop_->message_loop_proxy());
ASSERT_TRUE(service_);
test_gadget_ = UsbTestGadget::Claim();
......@@ -119,7 +118,7 @@ class HidConnectionTest : public testing::Test {
}
scoped_ptr<base::MessageLoopForIO> message_loop_;
scoped_ptr<HidService> service_;
HidService* service_;
scoped_ptr<UsbTestGadget> test_gadget_;
HidDeviceId device_id_;
};
......
......@@ -25,11 +25,13 @@ namespace {
HidService* g_service = NULL;
class HidServiceDestroyer : public base::MessageLoop::DestructionObserver {
} // namespace
class HidService::Destroyer : public base::MessageLoop::DestructionObserver {
public:
explicit HidServiceDestroyer(HidService* hid_service)
explicit Destroyer(HidService* hid_service)
: hid_service_(hid_service) {}
virtual ~HidServiceDestroyer() {}
virtual ~Destroyer() {}
private:
// base::MessageLoop::DestructionObserver implementation.
......@@ -43,8 +45,6 @@ class HidServiceDestroyer : public base::MessageLoop::DestructionObserver {
HidService* hid_service_;
};
} // namespace
HidService* HidService::GetInstance(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
if (g_service == NULL) {
......@@ -56,7 +56,7 @@ HidService* HidService::GetInstance(
g_service = new HidServiceWin();
#endif
if (g_service != NULL) {
HidServiceDestroyer* destroyer = new HidServiceDestroyer(g_service);
Destroyer* destroyer = new Destroyer(g_service);
base::MessageLoop::current()->AddDestructionObserver(destroyer);
}
}
......
......@@ -23,8 +23,6 @@ class HidService {
static HidService* GetInstance(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
virtual ~HidService();
// Enumerates and returns a list of device identifiers.
virtual void GetDevices(std::vector<HidDeviceInfo>* devices);
......@@ -41,6 +39,7 @@ class HidService {
typedef std::map<HidDeviceId, HidDeviceInfo> DeviceMap;
HidService();
virtual ~HidService();
void AddDevice(const HidDeviceInfo& info);
void RemoveDevice(const HidDeviceId& device_id);
......@@ -49,6 +48,8 @@ class HidService {
base::ThreadChecker thread_checker_;
private:
class Destroyer;
DeviceMap devices_;
DISALLOW_COPY_AND_ASSIGN(HidService);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment