OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_
H_ | 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_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_
H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 | 12 |
13 class MTPDeviceTaskHelper; | 13 class MTPDeviceTaskHelper; |
14 | 14 |
15 // MTPDeviceTaskHelperMapService manages MTPDeviceTaskHelper objects. | 15 // MTPDeviceTaskHelperMapService manages MTPDeviceTaskHelper objects. |
16 // MTPDeviceTaskHelperMapService lives on the UI thread. | 16 // MTPDeviceTaskHelperMapService lives on the UI thread. |
17 class MTPDeviceTaskHelperMapService { | 17 class MTPDeviceTaskHelperMapService { |
18 public: | 18 public: |
19 static MTPDeviceTaskHelperMapService* GetInstance(); | 19 static MTPDeviceTaskHelperMapService* GetInstance(); |
20 | 20 |
21 // Creates and returns the MTPDeviceTaskHelper object for the storage device | 21 // Creates and returns the MTPDeviceTaskHelper object for the storage device |
22 // specified by the |storage_name|. | 22 // specified by the |storage_name|. |
23 MTPDeviceTaskHelper* CreateDeviceTaskHelper(const std::string& storage_name); | 23 MTPDeviceTaskHelper* CreateDeviceTaskHelper(const std::string& storage_name, |
| 24 const bool read_only); |
24 | 25 |
25 // Destroys the MTPDeviceTaskHelper object created by | 26 // Destroys the MTPDeviceTaskHelper object created by |
26 // CreateDeviceTaskHelper(). | 27 // CreateDeviceTaskHelper(). |
27 // |storage_name| specifies the name of the storage device. | 28 // |storage_name| specifies the name of the storage device. |
28 void DestroyDeviceTaskHelper(const std::string& storage_name); | 29 void DestroyDeviceTaskHelper(const std::string& storage_name, |
| 30 const bool read_only); |
29 | 31 |
30 // Gets the MTPDeviceTaskHelper object associated with the device storage. | 32 // Gets the MTPDeviceTaskHelper object associated with the device storage. |
31 // |storage_name| specifies the name of the storage device. | 33 // |storage_name| specifies the name of the storage device. |
32 // Return NULL if the |storage_name| is no longer valid (e.g. because the | 34 // Return NULL if the |storage_name| is no longer valid (e.g. because the |
33 // corresponding storage device is detached, etc). | 35 // corresponding storage device is detached, etc). |
34 MTPDeviceTaskHelper* GetDeviceTaskHelper(const std::string& storage_name); | 36 MTPDeviceTaskHelper* GetDeviceTaskHelper(const std::string& storage_name, |
| 37 const bool read_only); |
35 | 38 |
36 private: | 39 private: |
37 friend struct base::DefaultLazyInstanceTraits<MTPDeviceTaskHelperMapService>; | 40 friend struct base::DefaultLazyInstanceTraits<MTPDeviceTaskHelperMapService>; |
38 | 41 |
39 // Key: Storage name. | 42 // A key to be used in TaskHelperMap. |
| 43 typedef std::string MTPDeviceTaskHelperKey; |
| 44 |
| 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); |
| 49 |
| 50 // Key: A combined value with storage_name and read_only. |
40 // Value: MTPDeviceTaskHelper object. | 51 // Value: MTPDeviceTaskHelper object. |
41 typedef std::map<std::string, MTPDeviceTaskHelper*> TaskHelperMap; | 52 typedef std::map<MTPDeviceTaskHelperKey, MTPDeviceTaskHelper*> TaskHelperMap; |
42 | 53 |
43 // Get access to this class using GetInstance() method. | 54 // Get access to this class using GetInstance() method. |
44 MTPDeviceTaskHelperMapService(); | 55 MTPDeviceTaskHelperMapService(); |
45 ~MTPDeviceTaskHelperMapService(); | 56 ~MTPDeviceTaskHelperMapService(); |
46 | 57 |
47 // Mapping of |storage_name| and MTPDeviceTaskHelper*. | 58 // Mapping of |storage_name| and MTPDeviceTaskHelper*. |
48 // TaskHelperMap owns MTPDeviceTaskHelper objects. | 59 // TaskHelperMap owns MTPDeviceTaskHelper objects. |
49 TaskHelperMap task_helper_map_; | 60 TaskHelperMap task_helper_map_; |
50 | 61 |
51 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelperMapService); | 62 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelperMapService); |
52 }; | 63 }; |
53 | 64 |
54 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVI
CE_H_ | 65 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVI
CE_H_ |
OLD | NEW |