| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/usb/usb_device_resource.h" | 5 #include "extensions/browser/api/usb/usb_device_resource.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "chrome/common/extensions/api/usb.h" | |
| 14 #include "components/usb_service/usb_device_handle.h" | 13 #include "components/usb_service/usb_device_handle.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "extensions/browser/api/api_resource.h" | 15 #include "extensions/browser/api/api_resource.h" |
| 16 #include "extensions/common/api/usb.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 using usb_service::UsbDeviceHandle; | 19 using usb_service::UsbDeviceHandle; |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 static base::LazyInstance< | 23 static base::LazyInstance< |
| 24 BrowserContextKeyedAPIFactory<ApiResourceManager<UsbDeviceResource> > > | 24 BrowserContextKeyedAPIFactory<ApiResourceManager<UsbDeviceResource> > > |
| 25 g_factory = LAZY_INSTANCE_INITIALIZER; | 25 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 template <> | 28 template <> |
| 29 BrowserContextKeyedAPIFactory<ApiResourceManager<UsbDeviceResource> >* | 29 BrowserContextKeyedAPIFactory<ApiResourceManager<UsbDeviceResource> >* |
| 30 ApiResourceManager<UsbDeviceResource>::GetFactoryInstance() { | 30 ApiResourceManager<UsbDeviceResource>::GetFactoryInstance() { |
| 31 return g_factory.Pointer(); | 31 return g_factory.Pointer(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 UsbDeviceResource::UsbDeviceResource(const std::string& owner_extension_id, | 34 UsbDeviceResource::UsbDeviceResource(const std::string& owner_extension_id, |
| 35 scoped_refptr<UsbDeviceHandle> device) | 35 scoped_refptr<UsbDeviceHandle> device) |
| 36 : ApiResource(owner_extension_id), device_(device) {} | 36 : ApiResource(owner_extension_id), device_(device) { |
| 37 } |
| 37 | 38 |
| 38 UsbDeviceResource::~UsbDeviceResource() { | 39 UsbDeviceResource::~UsbDeviceResource() { |
| 39 BrowserThread::PostTask(BrowserThread::FILE, | 40 BrowserThread::PostTask(BrowserThread::FILE, |
| 40 FROM_HERE, | 41 FROM_HERE, |
| 41 base::Bind(&UsbDeviceHandle::Close, device_)); | 42 base::Bind(&UsbDeviceHandle::Close, device_)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 } // namespace extensions | 45 } // namespace extensions |
| OLD | NEW |