Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / media_galleries / linux / mtp_device_task_helper_map_service.cc
blobdfa85e347e99ea30891e0cbc571c03da8e82b9f9
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"
12 namespace {
14 base::LazyInstance<MTPDeviceTaskHelperMapService>
15 g_mtp_device_task_helper_map_service = LAZY_INSTANCE_INITIALIZER;
17 } // namespace
19 // static
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 const bool read_only) {
27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
28 DCHECK(!storage_name.empty());
29 const MTPDeviceTaskHelperKey key =
30 GetMTPDeviceTaskHelperKey(storage_name, read_only);
31 DCHECK(!ContainsKey(task_helper_map_, key));
32 MTPDeviceTaskHelper* task_helper = new MTPDeviceTaskHelper();
33 task_helper_map_[key] = task_helper;
34 return task_helper;
37 void MTPDeviceTaskHelperMapService::DestroyDeviceTaskHelper(
38 const std::string& storage_name,
39 const bool read_only) {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41 const MTPDeviceTaskHelperKey key =
42 GetMTPDeviceTaskHelperKey(storage_name, read_only);
43 TaskHelperMap::iterator it = task_helper_map_.find(key);
44 if (it == task_helper_map_.end())
45 return;
46 delete it->second;
47 task_helper_map_.erase(it);
50 MTPDeviceTaskHelper* MTPDeviceTaskHelperMapService::GetDeviceTaskHelper(
51 const std::string& storage_name,
52 const bool read_only) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 DCHECK(!storage_name.empty());
55 const MTPDeviceTaskHelperKey key =
56 GetMTPDeviceTaskHelperKey(storage_name, read_only);
57 TaskHelperMap::const_iterator it = task_helper_map_.find(key);
58 return (it != task_helper_map_.end()) ? it->second : NULL;
61 // static
62 MTPDeviceTaskHelperMapService::MTPDeviceTaskHelperKey
63 MTPDeviceTaskHelperMapService::GetMTPDeviceTaskHelperKey(
64 const std::string& storage_name,
65 const bool read_only) {
66 return (read_only ? "ReadOnly" : "ReadWrite") + std::string("|") +
67 storage_name;
70 MTPDeviceTaskHelperMapService::MTPDeviceTaskHelperMapService() {
73 MTPDeviceTaskHelperMapService::~MTPDeviceTaskHelperMapService() {