OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fileapi/mtp_device_map_service.h" | 5 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 // static | 22 // static |
23 MTPDeviceMapService* MTPDeviceMapService::GetInstance() { | 23 MTPDeviceMapService* MTPDeviceMapService::GetInstance() { |
24 return g_mtp_device_map_service.Pointer(); | 24 return g_mtp_device_map_service.Pointer(); |
25 } | 25 } |
26 | 26 |
27 void MTPDeviceMapService::RegisterMTPFileSystem( | 27 void MTPDeviceMapService::RegisterMTPFileSystem( |
28 const base::FilePath::StringType& device_location, | 28 const base::FilePath::StringType& device_location, |
29 const std::string& filesystem_id, | 29 const std::string& filesystem_id, |
30 const bool read_only) { | 30 const bool read_only) { |
31 #if defined(OS_ANDROID) | |
32 // Skip registering the MTP device as there is no MTPDeviceAsyncDelegate | |
33 // implementation for Chrome on Android at the moment. (crbug.com/560390) | |
no sievers
2015/11/23 18:43:40
can we just create a stub that returns null?
Lei Zhang
2015/11/23 21:26:51
Right, is a no-op CreateMTPDeviceAsyncDelegate() s
mohsen
2015/11/23 21:33:50
Done, by creating media_galleries/android/ directo
| |
34 NOTIMPLEMENTED(); | |
35 #else | |
31 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
32 DCHECK(!device_location.empty()); | 37 DCHECK(!device_location.empty()); |
33 DCHECK(!filesystem_id.empty()); | 38 DCHECK(!filesystem_id.empty()); |
34 | 39 |
35 const AsyncDelegateKey key = GetAsyncDelegateKey(device_location, read_only); | 40 const AsyncDelegateKey key = GetAsyncDelegateKey(device_location, read_only); |
36 if (!ContainsKey(mtp_device_usage_map_, key)) { | 41 if (!ContainsKey(mtp_device_usage_map_, key)) { |
37 // Note that this initializes the delegate asynchronously, but since | 42 // Note that this initializes the delegate asynchronously, but since |
38 // the delegate will only be used from the IO thread, it is guaranteed | 43 // the delegate will only be used from the IO thread, it is guaranteed |
39 // to be created before use of it expects it to be there. | 44 // to be created before use of it expects it to be there. |
40 CreateMTPDeviceAsyncDelegate( | 45 CreateMTPDeviceAsyncDelegate( |
41 device_location, read_only, | 46 device_location, read_only, |
42 base::Bind(&MTPDeviceMapService::AddAsyncDelegate, | 47 base::Bind(&MTPDeviceMapService::AddAsyncDelegate, |
43 base::Unretained(this), device_location, read_only)); | 48 base::Unretained(this), device_location, read_only)); |
44 mtp_device_usage_map_[key] = 0; | 49 mtp_device_usage_map_[key] = 0; |
45 } | 50 } |
46 | 51 |
47 mtp_device_usage_map_[key]++; | 52 mtp_device_usage_map_[key]++; |
48 mtp_device_map_[filesystem_id] = make_pair(device_location, read_only); | 53 mtp_device_map_[filesystem_id] = make_pair(device_location, read_only); |
54 #endif | |
49 } | 55 } |
50 | 56 |
51 void MTPDeviceMapService::RevokeMTPFileSystem( | 57 void MTPDeviceMapService::RevokeMTPFileSystem( |
52 const std::string& filesystem_id) { | 58 const std::string& filesystem_id) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 59 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
54 DCHECK(!filesystem_id.empty()); | 60 DCHECK(!filesystem_id.empty()); |
55 | 61 |
56 MTPDeviceFileSystemMap::iterator it = mtp_device_map_.find(filesystem_id); | 62 MTPDeviceFileSystemMap::iterator it = mtp_device_map_.find(filesystem_id); |
57 if (it != mtp_device_map_.end()) { | 63 if (it != mtp_device_map_.end()) { |
58 const base::FilePath::StringType device_location = it->second.first; | 64 const base::FilePath::StringType device_location = it->second.first; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 ? async_delegate_map_it->second | 150 ? async_delegate_map_it->second |
145 : NULL; | 151 : NULL; |
146 } | 152 } |
147 | 153 |
148 MTPDeviceMapService::MTPDeviceMapService() { | 154 MTPDeviceMapService::MTPDeviceMapService() { |
149 } | 155 } |
150 | 156 |
151 MTPDeviceMapService::~MTPDeviceMapService() { | 157 MTPDeviceMapService::~MTPDeviceMapService() { |
152 DCHECK(mtp_device_usage_map_.empty()); | 158 DCHECK(mtp_device_usage_map_.empty()); |
153 } | 159 } |
OLD | NEW |