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_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_H_
11 #include "base/lazy_instance.h"
13 class MTPDeviceTaskHelper
;
15 // MTPDeviceTaskHelperMapService manages MTPDeviceTaskHelper objects.
16 // MTPDeviceTaskHelperMapService lives on the UI thread.
17 class MTPDeviceTaskHelperMapService
{
19 static MTPDeviceTaskHelperMapService
* GetInstance();
21 // Creates and returns the MTPDeviceTaskHelper object for the storage device
22 // specified by the |storage_name|.
23 MTPDeviceTaskHelper
* CreateDeviceTaskHelper(const std::string
& storage_name
,
24 const bool read_only
);
26 // Destroys the MTPDeviceTaskHelper object created by
27 // CreateDeviceTaskHelper().
28 // |storage_name| specifies the name of the storage device.
29 void DestroyDeviceTaskHelper(const std::string
& storage_name
,
30 const bool read_only
);
32 // Gets the MTPDeviceTaskHelper object associated with the device storage.
33 // |storage_name| specifies the name of the storage device.
34 // Return NULL if the |storage_name| is no longer valid (e.g. because the
35 // corresponding storage device is detached, etc).
36 MTPDeviceTaskHelper
* GetDeviceTaskHelper(const std::string
& storage_name
,
37 const bool read_only
);
40 friend struct base::DefaultLazyInstanceTraits
<MTPDeviceTaskHelperMapService
>;
42 // A key to be used in TaskHelperMap.
43 typedef std::string MTPDeviceTaskHelperKey
;
45 // Gets a key from |storage_name| and |read_only|.
46 static MTPDeviceTaskHelperKey
GetMTPDeviceTaskHelperKey(
47 const std::string
& storage_name
,
48 const bool read_only
);
50 // Key: A combined value with storage_name and read_only.
51 // Value: MTPDeviceTaskHelper object.
52 typedef std::map
<MTPDeviceTaskHelperKey
, MTPDeviceTaskHelper
*> TaskHelperMap
;
54 // Get access to this class using GetInstance() method.
55 MTPDeviceTaskHelperMapService();
56 ~MTPDeviceTaskHelperMapService();
58 // Mapping of |storage_name| and MTPDeviceTaskHelper*.
59 // TaskHelperMap owns MTPDeviceTaskHelper objects.
60 TaskHelperMap task_helper_map_
;
62 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelperMapService
);
65 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_H_