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

Side by Side Diff: chrome/browser/media_galleries/fileapi/mtp_device_map_service.cc

Issue 1391893003: NOT FOR REVIEW: Aura on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 (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
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 // No CreateMTPDeviceAsyncDelegate implementation
33 NOTIMPLEMENTED();
34 #else
31 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
32 DCHECK(!device_location.empty()); 36 DCHECK(!device_location.empty());
33 DCHECK(!filesystem_id.empty()); 37 DCHECK(!filesystem_id.empty());
34 38
35 const AsyncDelegateKey key = GetAsyncDelegateKey(device_location, read_only); 39 const AsyncDelegateKey key = GetAsyncDelegateKey(device_location, read_only);
36 if (!ContainsKey(mtp_device_usage_map_, key)) { 40 if (!ContainsKey(mtp_device_usage_map_, key)) {
37 // Note that this initializes the delegate asynchronously, but since 41 // Note that this initializes the delegate asynchronously, but since
38 // the delegate will only be used from the IO thread, it is guaranteed 42 // 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. 43 // to be created before use of it expects it to be there.
40 CreateMTPDeviceAsyncDelegate( 44 CreateMTPDeviceAsyncDelegate(
41 device_location, read_only, 45 device_location, read_only,
42 base::Bind(&MTPDeviceMapService::AddAsyncDelegate, 46 base::Bind(&MTPDeviceMapService::AddAsyncDelegate,
43 base::Unretained(this), device_location, read_only)); 47 base::Unretained(this), device_location, read_only));
44 mtp_device_usage_map_[key] = 0; 48 mtp_device_usage_map_[key] = 0;
45 } 49 }
46 50
47 mtp_device_usage_map_[key]++; 51 mtp_device_usage_map_[key]++;
48 mtp_device_map_[filesystem_id] = make_pair(device_location, read_only); 52 mtp_device_map_[filesystem_id] = make_pair(device_location, read_only);
53 #endif
49 } 54 }
50 55
51 void MTPDeviceMapService::RevokeMTPFileSystem( 56 void MTPDeviceMapService::RevokeMTPFileSystem(
52 const std::string& filesystem_id) { 57 const std::string& filesystem_id) {
58 #if defined(OS_ANDROID)
59 // No RemoveAsyncDelegate implementation
60 NOTIMPLEMENTED();
61 #else
53 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 62 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
54 DCHECK(!filesystem_id.empty()); 63 DCHECK(!filesystem_id.empty());
55 64
56 MTPDeviceFileSystemMap::iterator it = mtp_device_map_.find(filesystem_id); 65 MTPDeviceFileSystemMap::iterator it = mtp_device_map_.find(filesystem_id);
57 if (it != mtp_device_map_.end()) { 66 if (it != mtp_device_map_.end()) {
58 const base::FilePath::StringType device_location = it->second.first; 67 const base::FilePath::StringType device_location = it->second.first;
59 const bool read_only = it->second.second; 68 const bool read_only = it->second.second;
60 69
61 mtp_device_map_.erase(it); 70 mtp_device_map_.erase(it);
62 71
63 const AsyncDelegateKey key = 72 const AsyncDelegateKey key =
64 GetAsyncDelegateKey(device_location, read_only); 73 GetAsyncDelegateKey(device_location, read_only);
65 MTPDeviceUsageMap::iterator delegate_it = mtp_device_usage_map_.find(key); 74 MTPDeviceUsageMap::iterator delegate_it = mtp_device_usage_map_.find(key);
66 DCHECK(delegate_it != mtp_device_usage_map_.end()); 75 DCHECK(delegate_it != mtp_device_usage_map_.end());
67 76
68 mtp_device_usage_map_[key]--; 77 mtp_device_usage_map_[key]--;
69 if (mtp_device_usage_map_[key] == 0) { 78 if (mtp_device_usage_map_[key] == 0) {
70 mtp_device_usage_map_.erase(delegate_it); 79 mtp_device_usage_map_.erase(delegate_it);
71 RemoveAsyncDelegate(device_location, read_only); 80 RemoveAsyncDelegate(device_location, read_only);
72 } 81 }
73 } 82 }
83 #endif
74 } 84 }
75 85
76 void MTPDeviceMapService::AddAsyncDelegate( 86 void MTPDeviceMapService::AddAsyncDelegate(
77 const base::FilePath::StringType& device_location, 87 const base::FilePath::StringType& device_location,
78 const bool read_only, 88 const bool read_only,
79 MTPDeviceAsyncDelegate* delegate) { 89 MTPDeviceAsyncDelegate* delegate) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
81 DCHECK(delegate); 91 DCHECK(delegate);
82 DCHECK(!device_location.empty()); 92 DCHECK(!device_location.empty());
83 93
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 ? async_delegate_map_it->second 154 ? async_delegate_map_it->second
145 : NULL; 155 : NULL;
146 } 156 }
147 157
148 MTPDeviceMapService::MTPDeviceMapService() { 158 MTPDeviceMapService::MTPDeviceMapService() {
149 } 159 }
150 160
151 MTPDeviceMapService::~MTPDeviceMapService() { 161 MTPDeviceMapService::~MTPDeviceMapService() {
152 DCHECK(mtp_device_usage_map_.empty()); 162 DCHECK(mtp_device_usage_map_.empty());
153 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698