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. 4 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_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/lazy_instance.h" 12 13 class MTPDeviceTaskHelper; 14 15 // MTPDeviceTaskHelperMapService manages MTPDeviceTaskHelper objects. 16 // MTPDeviceTaskHelperMapService lives on the UI thread. 17 class MTPDeviceTaskHelperMapService { 18 public: 19 static MTPDeviceTaskHelperMapService* GetInstance(); 20 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 25 // Destroys the MTPDeviceTaskHelper object created by 26 // CreateDeviceTaskHelper(). 27 // |storage_name| specifies the name of the storage device. 28 void DestroyDeviceTaskHelper(const std::string& storage_name); 29 30 // Gets the MTPDeviceTaskHelper object associated with the device storage. 31 // |storage_name| specifies the name of the storage device. 32 // Return NULL if the |storage_name| is no longer valid (e.g. because the 33 // corresponding storage device is detached, etc). 34 MTPDeviceTaskHelper* GetDeviceTaskHelper(const std::string& storage_name); 35 36 private: 37 friend struct base::DefaultLazyInstanceTraits<MTPDeviceTaskHelperMapService>; 38 39 // Key: Storage name. 40 // Value: MTPDeviceTaskHelper object. 41 typedef std::map<std::string, MTPDeviceTaskHelper*> TaskHelperMap; 42 43 // Get access to this class using GetInstance() method. 44 MTPDeviceTaskHelperMapService(); 45 ~MTPDeviceTaskHelperMapService(); 46 47 // Mapping of |storage_name| and MTPDeviceTaskHelper*. 48 // TaskHelperMap owns MTPDeviceTaskHelper objects. 49 TaskHelperMap task_helper_map_; 50 51 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelperMapService); 52 }; 53 54 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_MAP_SERVICE_H_ 55