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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_WIN_PORTABLE_DEVICE_MAP_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_WIN_PORTABLE_DEVICE_MAP_SERVICE_H_
8 #include <portabledeviceapi.h>
11 #include "base/lazy_instance.h"
12 #include "base/strings/string16.h"
13 #include "base/synchronization/lock.h"
14 #include "base/win/scoped_comptr.h"
16 // PortableDeviceMapService keeps track of initialized portable device
17 // interfaces. PortableDeviceMapService owns the portable device interfaces.
18 class PortableDeviceMapService
{
20 static PortableDeviceMapService
* GetInstance();
22 // Adds the portable |device| interface to the map service for the device
23 // specified by the |device_location|. Called on a blocking pool thread.
24 void AddPortableDevice(const base::string16
& device_location
,
25 IPortableDevice
* device
);
27 // Marks the IPortableDevice interface of the device specified by the
28 // |device_location| for deletion. This helps to cancel all the pending
29 // tasks before deleting the IPortableDevice interface.
31 // Callers of this function should post a task on a blocking pool thread to
32 // remove the IPortableDevice interface from the map service.
34 // Called on the IO thread.
35 void MarkPortableDeviceForDeletion(const base::string16
& device_location
);
37 // Removes the IPortableDevice interface from the map service for the device
38 // specified by the |device_location|. Callers of this function should have
39 // already called MarkPortableDeviceForDeletion() on the IO thread.
40 // Called on a blocking pool thread.
41 void RemovePortableDevice(const base::string16
& device_location
);
43 // Gets the IPortableDevice interface associated with the device specified
44 // by the |device_location|. Returns NULL if the |device_location| is no
45 // longer valid (e.g. the corresponding device is detached etc).
46 // Called on a blocking pool thread.
47 IPortableDevice
* GetPortableDevice(const base::string16
& device_location
);
50 friend struct base::DefaultLazyInstanceTraits
<PortableDeviceMapService
>;
52 struct PortableDeviceInfo
{
53 PortableDeviceInfo(); // Necessary for STL.
54 explicit PortableDeviceInfo(IPortableDevice
* device
);
55 ~PortableDeviceInfo();
57 // The portable device interface.
58 base::win::ScopedComPtr
<IPortableDevice
> portable_device
;
60 // Set to true if the |portable_device| is marked for deletion.
61 bool scheduled_to_delete
;
64 typedef std::map
<const base::string16
, PortableDeviceInfo
> PortableDeviceMap
;
66 // Get access to this class using GetInstance() method.
67 PortableDeviceMapService();
68 ~PortableDeviceMapService();
70 // Mapping of |device_location| and IPortableDevice* object.
71 PortableDeviceMap device_map_
;
74 DISALLOW_COPY_AND_ASSIGN(PortableDeviceMapService
);
77 #endif // CHROME_BROWSER_MEDIA_GALLERIES_WIN_PORTABLE_DEVICE_MAP_SERVICE_H_