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 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_service.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h"
10 #include "content/public/browser/browser_thread.h"
14 base::LazyInstance
<MTPDeviceTaskHelperMapService
>
15 g_mtp_device_task_helper_map_service
= LAZY_INSTANCE_INITIALIZER
;
20 MTPDeviceTaskHelperMapService
* MTPDeviceTaskHelperMapService::GetInstance() {
21 return g_mtp_device_task_helper_map_service
.Pointer();
24 MTPDeviceTaskHelper
* MTPDeviceTaskHelperMapService::CreateDeviceTaskHelper(
25 const std::string
& storage_name
) {
26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
27 DCHECK(!storage_name
.empty());
28 DCHECK(!ContainsKey(task_helper_map_
, storage_name
));
29 MTPDeviceTaskHelper
* task_helper
= new MTPDeviceTaskHelper();
30 task_helper_map_
[storage_name
] = task_helper
;
34 void MTPDeviceTaskHelperMapService::DestroyDeviceTaskHelper(
35 const std::string
& storage_name
) {
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
37 TaskHelperMap::iterator it
= task_helper_map_
.find(storage_name
);
38 if (it
== task_helper_map_
.end())
41 task_helper_map_
.erase(it
);
44 MTPDeviceTaskHelper
* MTPDeviceTaskHelperMapService::GetDeviceTaskHelper(
45 const std::string
& storage_name
) {
46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
47 DCHECK(!storage_name
.empty());
48 TaskHelperMap::const_iterator it
= task_helper_map_
.find(storage_name
);
49 return (it
!= task_helper_map_
.end()) ? it
->second
: NULL
;
52 MTPDeviceTaskHelperMapService::MTPDeviceTaskHelperMapService() {
55 MTPDeviceTaskHelperMapService::~MTPDeviceTaskHelperMapService() {