Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_task_helper_map_service.cc

Issue 947943002: Implement CopyFileFromLocal of MTPDeviceAsyncDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper_map_servic e.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h" 9 #include "chrome/browser/media_galleries/linux/mtp_device_task_helper.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 11
12 namespace { 12 namespace {
13 13
14 base::LazyInstance<MTPDeviceTaskHelperMapService> 14 base::LazyInstance<MTPDeviceTaskHelperMapService>
15 g_mtp_device_task_helper_map_service = LAZY_INSTANCE_INITIALIZER; 15 g_mtp_device_task_helper_map_service = LAZY_INSTANCE_INITIALIZER;
16 16
17 } // namespace 17 } // namespace
18 18
19 // static 19 // static
20 MTPDeviceTaskHelperMapService* MTPDeviceTaskHelperMapService::GetInstance() { 20 MTPDeviceTaskHelperMapService* MTPDeviceTaskHelperMapService::GetInstance() {
21 return g_mtp_device_task_helper_map_service.Pointer(); 21 return g_mtp_device_task_helper_map_service.Pointer();
22 } 22 }
23 23
24 MTPDeviceTaskHelper* MTPDeviceTaskHelperMapService::CreateDeviceTaskHelper( 24 MTPDeviceTaskHelper* MTPDeviceTaskHelperMapService::CreateDeviceTaskHelper(
25 const std::string& storage_name) { 25 const std::string& storage_name,
26 const bool read_only) {
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
27 DCHECK(!storage_name.empty()); 28 DCHECK(!storage_name.empty());
28 DCHECK(!ContainsKey(task_helper_map_, storage_name)); 29 const MTPDeviceTaskHelperKey key =
30 GetMTPDeviceTaskHelperKey(storage_name, read_only);
31 DCHECK(!ContainsKey(task_helper_map_, key));
29 MTPDeviceTaskHelper* task_helper = new MTPDeviceTaskHelper(); 32 MTPDeviceTaskHelper* task_helper = new MTPDeviceTaskHelper();
30 task_helper_map_[storage_name] = task_helper; 33 task_helper_map_[key] = task_helper;
31 return task_helper; 34 return task_helper;
32 } 35 }
33 36
34 void MTPDeviceTaskHelperMapService::DestroyDeviceTaskHelper( 37 void MTPDeviceTaskHelperMapService::DestroyDeviceTaskHelper(
35 const std::string& storage_name) { 38 const std::string& storage_name,
39 const bool read_only) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37 TaskHelperMap::iterator it = task_helper_map_.find(storage_name); 41 const MTPDeviceTaskHelperKey key =
42 GetMTPDeviceTaskHelperKey(storage_name, read_only);
43 TaskHelperMap::iterator it = task_helper_map_.find(key);
38 if (it == task_helper_map_.end()) 44 if (it == task_helper_map_.end())
39 return; 45 return;
40 delete it->second; 46 delete it->second;
41 task_helper_map_.erase(it); 47 task_helper_map_.erase(it);
42 } 48 }
43 49
44 MTPDeviceTaskHelper* MTPDeviceTaskHelperMapService::GetDeviceTaskHelper( 50 MTPDeviceTaskHelper* MTPDeviceTaskHelperMapService::GetDeviceTaskHelper(
45 const std::string& storage_name) { 51 const std::string& storage_name,
52 const bool read_only) {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
47 DCHECK(!storage_name.empty()); 54 DCHECK(!storage_name.empty());
48 TaskHelperMap::const_iterator it = task_helper_map_.find(storage_name); 55 const MTPDeviceTaskHelperKey key =
56 GetMTPDeviceTaskHelperKey(storage_name, read_only);
57 TaskHelperMap::const_iterator it = task_helper_map_.find(key);
49 return (it != task_helper_map_.end()) ? it->second : NULL; 58 return (it != task_helper_map_.end()) ? it->second : NULL;
50 } 59 }
51 60
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;
68 }
69
52 MTPDeviceTaskHelperMapService::MTPDeviceTaskHelperMapService() { 70 MTPDeviceTaskHelperMapService::MTPDeviceTaskHelperMapService() {
53 } 71 }
54 72
55 MTPDeviceTaskHelperMapService::~MTPDeviceTaskHelperMapService() { 73 MTPDeviceTaskHelperMapService::~MTPDeviceTaskHelperMapService() {
56 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698