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 // MediaFileSystemRegistry implementation. | 5 // MediaFileSystemRegistry implementation. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 7 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // a weak pointer to MediaFileSystemRegistry. | 132 // a weak pointer to MediaFileSystemRegistry. |
133 class ScopedMTPDeviceMapEntry | 133 class ScopedMTPDeviceMapEntry |
134 : public base::RefCounted<ScopedMTPDeviceMapEntry>, | 134 : public base::RefCounted<ScopedMTPDeviceMapEntry>, |
135 public base::SupportsWeakPtr<ScopedMTPDeviceMapEntry> { | 135 public base::SupportsWeakPtr<ScopedMTPDeviceMapEntry> { |
136 public: | 136 public: |
137 // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry | 137 // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry |
138 // reference goes away. | 138 // reference goes away. |
139 ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location, | 139 ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location, |
140 const base::Closure& no_references_callback) | 140 const base::Closure& no_references_callback) |
141 : device_location_(device_location), | 141 : device_location_(device_location), |
142 delegate_(new MTPDeviceDelegateImpl(device_location)), | |
143 no_references_callback_(no_references_callback) { | 142 no_references_callback_(no_references_callback) { |
144 DCHECK(delegate_); | |
145 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
146 BrowserThread::IO, FROM_HERE, | 144 BrowserThread::IO, FROM_HERE, |
147 Bind(&MTPDeviceMapService::AddDelegate, | 145 Bind(&MTPDeviceMapService::AddDelegate, |
148 base::Unretained(MTPDeviceMapService::GetInstance()), | 146 base::Unretained(MTPDeviceMapService::GetInstance()), |
149 device_location_, make_scoped_refptr(delegate_))); | 147 device_location_, |
| 148 make_scoped_refptr(new MTPDeviceDelegateImpl(device_location)))); |
150 } | 149 } |
151 | 150 |
152 private: | 151 private: |
153 // Friend declaration for ref counted implementation. | 152 // Friend declaration for ref counted implementation. |
154 friend class base::RefCounted<ScopedMTPDeviceMapEntry>; | 153 friend class base::RefCounted<ScopedMTPDeviceMapEntry>; |
155 | 154 |
156 // Private because this class is ref-counted. | 155 // Private because this class is ref-counted. |
157 ~ScopedMTPDeviceMapEntry() { | 156 ~ScopedMTPDeviceMapEntry() { |
158 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
159 BrowserThread::IO, FROM_HERE, | 158 BrowserThread::IO, FROM_HERE, |
160 Bind(&MTPDeviceMapService::RemoveDelegate, | 159 Bind(&MTPDeviceMapService::RemoveDelegate, |
161 base::Unretained(MTPDeviceMapService::GetInstance()), | 160 base::Unretained(MTPDeviceMapService::GetInstance()), |
162 device_location_)); | 161 device_location_)); |
163 no_references_callback_.Run(); | 162 no_references_callback_.Run(); |
164 } | 163 } |
165 | 164 |
166 // Store the MTP or PTP device location. | 165 // Store the MTP or PTP device location. |
167 const FilePath::StringType device_location_; | 166 const FilePath::StringType device_location_; |
168 | 167 |
169 // Store a raw pointer of MTPDeviceDelegateImpl object. | |
170 // MTPDeviceDelegateImpl is ref-counted and owned by MTPDeviceMapService. | |
171 // This class tells MTPDeviceMapService to dispose of it when the last | |
172 // reference to |this| goes away. | |
173 MTPDeviceDelegateImpl* delegate_; | |
174 | |
175 // A callback to call when the last reference of this object goes away. | 168 // A callback to call when the last reference of this object goes away. |
176 base::Closure no_references_callback_; | 169 base::Closure no_references_callback_; |
177 | 170 |
178 DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry); | 171 DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry); |
179 }; | 172 }; |
180 #endif | 173 #endif |
181 | 174 |
182 // The main owner of this class is | 175 // The main owner of this class is |
183 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may | 176 // |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may |
184 // temporarily hold a reference. | 177 // temporarily hold a reference. |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 751 |
759 PrefChangeRegistrarMap::iterator pref_it = | 752 PrefChangeRegistrarMap::iterator pref_it = |
760 pref_change_registrar_map_.find(profile); | 753 pref_change_registrar_map_.find(profile); |
761 DCHECK(pref_it != pref_change_registrar_map_.end()); | 754 DCHECK(pref_it != pref_change_registrar_map_.end()); |
762 delete pref_it->second; | 755 delete pref_it->second; |
763 pref_change_registrar_map_.erase(pref_it); | 756 pref_change_registrar_map_.erase(pref_it); |
764 } | 757 } |
765 } | 758 } |
766 | 759 |
767 } // namespace chrome | 760 } // namespace chrome |
OLD | NEW |