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

Side by Side Diff: webkit/fileapi/media/mtp_device_map_service.cc

Issue 11358243: Redesigned and refactored ScopedMTPDeviceMapEntry, MTPDeviceMapService & MTPDeviceDelegate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/media/mtp_device_map_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/fileapi/media/mtp_device_map_service.h" 5 #include "webkit/fileapi/media/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"
11 #include "webkit/fileapi/isolated_context.h" 11 #include "webkit/fileapi/isolated_context.h"
12 #include "webkit/fileapi/media/mtp_device_delegate.h" 12 #include "webkit/fileapi/media/mtp_device_delegate.h"
13 13
14 namespace fileapi { 14 namespace fileapi {
15 15
16 // static 16 // static
17 MTPDeviceMapService* MTPDeviceMapService::GetInstance() { 17 MTPDeviceMapService* MTPDeviceMapService::GetInstance() {
18 return Singleton<MTPDeviceMapService>::get(); 18 return Singleton<MTPDeviceMapService>::get();
19 } 19 }
20 20
21 void MTPDeviceMapService::AddDelegate( 21 void MTPDeviceMapService::AddDelegate(
22 const FilePath::StringType& device_location, 22 const FilePath::StringType& device_location,
23 scoped_refptr<MTPDeviceDelegate> delegate) { 23 MTPDeviceDelegate* delegate) {
24 DCHECK(thread_checker_.CalledOnValidThread()); 24 DCHECK(thread_checker_.CalledOnValidThread());
25 DCHECK(delegate.get()); 25 DCHECK(delegate);
26 DCHECK(!device_location.empty()); 26 DCHECK(!device_location.empty());
27
28 if (ContainsKey(delegate_map_, device_location)) 27 if (ContainsKey(delegate_map_, device_location))
29 return; 28 return;
30 29
31 delegate_map_[device_location] = delegate; 30 delegate_map_[device_location] = delegate;
32 } 31 }
33 32
34 void MTPDeviceMapService::RemoveDelegate( 33 void MTPDeviceMapService::RemoveDelegate(
35 const FilePath::StringType& device_location) { 34 const FilePath::StringType& device_location) {
36 DCHECK(thread_checker_.CalledOnValidThread()); 35 DCHECK(thread_checker_.CalledOnValidThread());
37 DelegateMap::iterator it = delegate_map_.find(device_location); 36 DelegateMap::iterator it = delegate_map_.find(device_location);
38 DCHECK(it != delegate_map_.end()); 37 DCHECK(it != delegate_map_.end());
38 it->second->CancelPendingTasksAndDeleteDelegate();
39 delegate_map_.erase(it); 39 delegate_map_.erase(it);
40 } 40 }
41 41
42 MTPDeviceDelegate* MTPDeviceMapService::GetMTPDeviceDelegate( 42 MTPDeviceDelegate* MTPDeviceMapService::GetMTPDeviceDelegate(
43 const std::string& filesystem_id) { 43 const std::string& filesystem_id) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
45 FilePath device_path; 45 FilePath device_path;
46 if (!IsolatedContext::GetInstance()->GetRegisteredPath(filesystem_id, 46 if (!IsolatedContext::GetInstance()->GetRegisteredPath(filesystem_id,
47 &device_path)) { 47 &device_path)) {
48 return NULL; 48 return NULL;
49 } 49 }
50 50
51 FilePath::StringType device_location = device_path.value(); 51 FilePath::StringType device_location = device_path.value();
52 DCHECK(!device_location.empty()); 52 DCHECK(!device_location.empty());
53 53
54 DelegateMap::const_iterator it = delegate_map_.find(device_location); 54 DelegateMap::const_iterator it = delegate_map_.find(device_location);
55 DCHECK(it != delegate_map_.end()); 55 DCHECK(it != delegate_map_.end());
56 return it->second.get(); 56 return it->second;
57 } 57 }
58 58
59 MTPDeviceMapService::MTPDeviceMapService() { 59 MTPDeviceMapService::MTPDeviceMapService() {
60 // This object is constructed on UI Thread but the member functions are 60 // This object is constructed on UI Thread but the member functions are
61 // accessed on IO thread. Therefore, detach from current thread. 61 // accessed on IO thread. Therefore, detach from current thread.
62 thread_checker_.DetachFromThread(); 62 thread_checker_.DetachFromThread();
Lei Zhang 2012/11/21 06:46:39 Speaking of DetachFromThread(), I don't think this
kmadhusu 2012/11/22 00:49:08 When we instantiate thread_checker_, we bind the c
63 } 63 }
64 64
65 MTPDeviceMapService::~MTPDeviceMapService() {} 65 MTPDeviceMapService::~MTPDeviceMapService() {}
66 66
67 } // namespace fileapi 67 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/media/mtp_device_map_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698