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

Side by Side Diff: device/media_transfer_protocol/media_transfer_protocol_manager.cc

Issue 15741025: Linux/CrOS: Retry connecting to mtpd. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address nits Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « dbus/bus_unittest.cc ('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 "device/media_transfer_protocol/media_transfer_protocol_manager.h" 5 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 DCHECK(!task_runner.get()); 43 DCHECK(!task_runner.get());
44 #else 44 #else
45 DCHECK(task_runner.get()); 45 DCHECK(task_runner.get());
46 dbus::Bus::Options options; 46 dbus::Bus::Options options;
47 options.bus_type = dbus::Bus::SYSTEM; 47 options.bus_type = dbus::Bus::SYSTEM;
48 options.connection_type = dbus::Bus::PRIVATE; 48 options.connection_type = dbus::Bus::PRIVATE;
49 options.dbus_task_runner = task_runner; 49 options.dbus_task_runner = task_runner;
50 session_bus_ = new dbus::Bus(options); 50 session_bus_ = new dbus::Bus(options);
51 #endif 51 #endif
52 52
53 dbus::Bus::GetServiceOwnerCallback reply_task = 53 // Listen for future mtpd service owner changes, in case it is not
54 // available right now. There is no guarantee on Linux or ChromeOS that
55 // mtpd is running already.
56 mtpd_owner_changed_callback_ =
54 base::Bind(&MediaTransferProtocolManagerImpl::FinishSetupOnOriginThread, 57 base::Bind(&MediaTransferProtocolManagerImpl::FinishSetupOnOriginThread,
55 weak_ptr_factory_.GetWeakPtr()); 58 weak_ptr_factory_.GetWeakPtr());
56 GetBus()->GetServiceOwner(mtpd::kMtpdServiceName, reply_task); 59 GetBus()->ListenForServiceOwnerChange(mtpd::kMtpdServiceName,
60 mtpd_owner_changed_callback_);
61 GetBus()->GetServiceOwner(mtpd::kMtpdServiceName,
62 mtpd_owner_changed_callback_);
57 } 63 }
58 64
59 virtual ~MediaTransferProtocolManagerImpl() { 65 virtual ~MediaTransferProtocolManagerImpl() {
60 DCHECK(g_media_transfer_protocol_manager); 66 DCHECK(g_media_transfer_protocol_manager);
61 g_media_transfer_protocol_manager = NULL; 67 g_media_transfer_protocol_manager = NULL;
68 GetBus()->UnlistenForServiceOwnerChange(mtpd::kMtpdServiceName,
69 mtpd_owner_changed_callback_);
70
71 #if !defined(OS_CHROMEOS)
72 session_bus_->PostTaskToDBusThread(
73 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_));
74 #endif
75
62 VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; 76 VLOG(1) << "MediaTransferProtocolManager Shutdown completed";
63 } 77 }
64 78
65 // MediaTransferProtocolManager override. 79 // MediaTransferProtocolManager override.
66 virtual void AddObserver(Observer* observer) OVERRIDE { 80 virtual void AddObserver(Observer* observer) OVERRIDE {
67 observers_.AddObserver(observer); 81 observers_.AddObserver(observer);
68 } 82 }
69 83
70 // MediaTransferProtocolManager override. 84 // MediaTransferProtocolManager override.
71 virtual void RemoveObserver(Observer* observer) OVERRIDE { 85 virtual void RemoveObserver(Observer* observer) OVERRIDE {
(...skipping 18 matching lines...) Expand all
90 DCHECK(thread_checker_.CalledOnValidThread()); 104 DCHECK(thread_checker_.CalledOnValidThread());
91 StorageInfoMap::const_iterator it = storage_info_map_.find(storage_name); 105 StorageInfoMap::const_iterator it = storage_info_map_.find(storage_name);
92 return it != storage_info_map_.end() ? &it->second : NULL; 106 return it != storage_info_map_.end() ? &it->second : NULL;
93 } 107 }
94 108
95 // MediaTransferProtocolManager override. 109 // MediaTransferProtocolManager override.
96 virtual void OpenStorage(const std::string& storage_name, 110 virtual void OpenStorage(const std::string& storage_name,
97 const std::string& mode, 111 const std::string& mode,
98 const OpenStorageCallback& callback) OVERRIDE { 112 const OpenStorageCallback& callback) OVERRIDE {
99 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
100 if (!ContainsKey(storage_info_map_, storage_name)) { 114 if (!ContainsKey(storage_info_map_, storage_name) || !mtp_client_) {
101 callback.Run(std::string(), true); 115 callback.Run(std::string(), true);
102 return; 116 return;
103 } 117 }
104 open_storage_callbacks_.push(callback); 118 open_storage_callbacks_.push(callback);
105 mtp_client_->OpenStorage( 119 mtp_client_->OpenStorage(
106 storage_name, 120 storage_name,
107 mode, 121 mode,
108 base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorage, 122 base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorage,
109 weak_ptr_factory_.GetWeakPtr()), 123 weak_ptr_factory_.GetWeakPtr()),
110 base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorageError, 124 base::Bind(&MediaTransferProtocolManagerImpl::OnOpenStorageError,
111 weak_ptr_factory_.GetWeakPtr())); 125 weak_ptr_factory_.GetWeakPtr()));
112 } 126 }
113 127
114 // MediaTransferProtocolManager override. 128 // MediaTransferProtocolManager override.
115 virtual void CloseStorage(const std::string& storage_handle, 129 virtual void CloseStorage(const std::string& storage_handle,
116 const CloseStorageCallback& callback) OVERRIDE { 130 const CloseStorageCallback& callback) OVERRIDE {
117 DCHECK(thread_checker_.CalledOnValidThread()); 131 DCHECK(thread_checker_.CalledOnValidThread());
118 if (!ContainsKey(handles_, storage_handle)) { 132 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
119 callback.Run(true); 133 callback.Run(true);
120 return; 134 return;
121 } 135 }
122 close_storage_callbacks_.push(std::make_pair(callback, storage_handle)); 136 close_storage_callbacks_.push(std::make_pair(callback, storage_handle));
123 mtp_client_->CloseStorage( 137 mtp_client_->CloseStorage(
124 storage_handle, 138 storage_handle,
125 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorage, 139 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorage,
126 weak_ptr_factory_.GetWeakPtr()), 140 weak_ptr_factory_.GetWeakPtr()),
127 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorageError, 141 base::Bind(&MediaTransferProtocolManagerImpl::OnCloseStorageError,
128 weak_ptr_factory_.GetWeakPtr())); 142 weak_ptr_factory_.GetWeakPtr()));
129 } 143 }
130 144
131 // MediaTransferProtocolManager override. 145 // MediaTransferProtocolManager override.
132 virtual void ReadDirectoryByPath( 146 virtual void ReadDirectoryByPath(
133 const std::string& storage_handle, 147 const std::string& storage_handle,
134 const std::string& path, 148 const std::string& path,
135 const ReadDirectoryCallback& callback) OVERRIDE { 149 const ReadDirectoryCallback& callback) OVERRIDE {
136 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
137 if (!ContainsKey(handles_, storage_handle)) { 151 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
138 callback.Run(std::vector<MtpFileEntry>(), true); 152 callback.Run(std::vector<MtpFileEntry>(), true);
139 return; 153 return;
140 } 154 }
141 read_directory_callbacks_.push(callback); 155 read_directory_callbacks_.push(callback);
142 mtp_client_->ReadDirectoryByPath( 156 mtp_client_->ReadDirectoryByPath(
143 storage_handle, 157 storage_handle,
144 path, 158 path,
145 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory, 159 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory,
146 weak_ptr_factory_.GetWeakPtr()), 160 weak_ptr_factory_.GetWeakPtr()),
147 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, 161 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
148 weak_ptr_factory_.GetWeakPtr())); 162 weak_ptr_factory_.GetWeakPtr()));
149 } 163 }
150 164
151 // MediaTransferProtocolManager override. 165 // MediaTransferProtocolManager override.
152 virtual void ReadDirectoryById( 166 virtual void ReadDirectoryById(
153 const std::string& storage_handle, 167 const std::string& storage_handle,
154 uint32 file_id, 168 uint32 file_id,
155 const ReadDirectoryCallback& callback) OVERRIDE { 169 const ReadDirectoryCallback& callback) OVERRIDE {
156 DCHECK(thread_checker_.CalledOnValidThread()); 170 DCHECK(thread_checker_.CalledOnValidThread());
157 if (!ContainsKey(handles_, storage_handle)) { 171 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
158 callback.Run(std::vector<MtpFileEntry>(), true); 172 callback.Run(std::vector<MtpFileEntry>(), true);
159 return; 173 return;
160 } 174 }
161 read_directory_callbacks_.push(callback); 175 read_directory_callbacks_.push(callback);
162 mtp_client_->ReadDirectoryById( 176 mtp_client_->ReadDirectoryById(
163 storage_handle, 177 storage_handle,
164 file_id, 178 file_id,
165 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory, 179 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectory,
166 weak_ptr_factory_.GetWeakPtr()), 180 weak_ptr_factory_.GetWeakPtr()),
167 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError, 181 base::Bind(&MediaTransferProtocolManagerImpl::OnReadDirectoryError,
168 weak_ptr_factory_.GetWeakPtr())); 182 weak_ptr_factory_.GetWeakPtr()));
169 } 183 }
170 184
171 // MediaTransferProtocolManager override. 185 // MediaTransferProtocolManager override.
172 virtual void ReadFileChunkByPath(const std::string& storage_handle, 186 virtual void ReadFileChunkByPath(const std::string& storage_handle,
173 const std::string& path, 187 const std::string& path,
174 uint32 offset, 188 uint32 offset,
175 uint32 count, 189 uint32 count,
176 const ReadFileCallback& callback) OVERRIDE { 190 const ReadFileCallback& callback) OVERRIDE {
177 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
178 if (!ContainsKey(handles_, storage_handle)) { 192 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
179 callback.Run(std::string(), true); 193 callback.Run(std::string(), true);
180 return; 194 return;
181 } 195 }
182 read_file_callbacks_.push(callback); 196 read_file_callbacks_.push(callback);
183 mtp_client_->ReadFileChunkByPath( 197 mtp_client_->ReadFileChunkByPath(
184 storage_handle, path, offset, count, 198 storage_handle, path, offset, count,
185 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, 199 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile,
186 weak_ptr_factory_.GetWeakPtr()), 200 weak_ptr_factory_.GetWeakPtr()),
187 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, 201 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError,
188 weak_ptr_factory_.GetWeakPtr())); 202 weak_ptr_factory_.GetWeakPtr()));
189 } 203 }
190 204
191 // MediaTransferProtocolManager override. 205 // MediaTransferProtocolManager override.
192 virtual void ReadFileChunkById(const std::string& storage_handle, 206 virtual void ReadFileChunkById(const std::string& storage_handle,
193 uint32 file_id, 207 uint32 file_id,
194 uint32 offset, 208 uint32 offset,
195 uint32 count, 209 uint32 count,
196 const ReadFileCallback& callback) OVERRIDE { 210 const ReadFileCallback& callback) OVERRIDE {
197 DCHECK(thread_checker_.CalledOnValidThread()); 211 DCHECK(thread_checker_.CalledOnValidThread());
198 if (!ContainsKey(handles_, storage_handle)) { 212 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
199 callback.Run(std::string(), true); 213 callback.Run(std::string(), true);
200 return; 214 return;
201 } 215 }
202 read_file_callbacks_.push(callback); 216 read_file_callbacks_.push(callback);
203 mtp_client_->ReadFileChunkById( 217 mtp_client_->ReadFileChunkById(
204 storage_handle, file_id, offset, count, 218 storage_handle, file_id, offset, count,
205 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile, 219 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFile,
206 weak_ptr_factory_.GetWeakPtr()), 220 weak_ptr_factory_.GetWeakPtr()),
207 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError, 221 base::Bind(&MediaTransferProtocolManagerImpl::OnReadFileError,
208 weak_ptr_factory_.GetWeakPtr())); 222 weak_ptr_factory_.GetWeakPtr()));
209 } 223 }
210 224
211 virtual void GetFileInfoByPath(const std::string& storage_handle, 225 virtual void GetFileInfoByPath(const std::string& storage_handle,
212 const std::string& path, 226 const std::string& path,
213 const GetFileInfoCallback& callback) OVERRIDE { 227 const GetFileInfoCallback& callback) OVERRIDE {
214 DCHECK(thread_checker_.CalledOnValidThread()); 228 DCHECK(thread_checker_.CalledOnValidThread());
215 if (!ContainsKey(handles_, storage_handle)) { 229 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
216 callback.Run(MtpFileEntry(), true); 230 callback.Run(MtpFileEntry(), true);
217 return; 231 return;
218 } 232 }
219 get_file_info_callbacks_.push(callback); 233 get_file_info_callbacks_.push(callback);
220 mtp_client_->GetFileInfoByPath( 234 mtp_client_->GetFileInfoByPath(
221 storage_handle, 235 storage_handle,
222 path, 236 path,
223 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, 237 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo,
224 weak_ptr_factory_.GetWeakPtr()), 238 weak_ptr_factory_.GetWeakPtr()),
225 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, 239 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError,
226 weak_ptr_factory_.GetWeakPtr())); 240 weak_ptr_factory_.GetWeakPtr()));
227 } 241 }
228 242
229 virtual void GetFileInfoById(const std::string& storage_handle, 243 virtual void GetFileInfoById(const std::string& storage_handle,
230 uint32 file_id, 244 uint32 file_id,
231 const GetFileInfoCallback& callback) OVERRIDE { 245 const GetFileInfoCallback& callback) OVERRIDE {
232 DCHECK(thread_checker_.CalledOnValidThread()); 246 DCHECK(thread_checker_.CalledOnValidThread());
233 if (!ContainsKey(handles_, storage_handle)) { 247 if (!ContainsKey(handles_, storage_handle) || !mtp_client_) {
234 callback.Run(MtpFileEntry(), true); 248 callback.Run(MtpFileEntry(), true);
235 return; 249 return;
236 } 250 }
237 get_file_info_callbacks_.push(callback); 251 get_file_info_callbacks_.push(callback);
238 mtp_client_->GetFileInfoById( 252 mtp_client_->GetFileInfoById(
239 storage_handle, 253 storage_handle,
240 file_id, 254 file_id,
241 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo, 255 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfo,
242 weak_ptr_factory_.GetWeakPtr()), 256 weak_ptr_factory_.GetWeakPtr()),
243 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError, 257 base::Bind(&MediaTransferProtocolManagerImpl::OnGetFileInfoError,
244 weak_ptr_factory_.GetWeakPtr())); 258 weak_ptr_factory_.GetWeakPtr()));
245 } 259 }
246 260
247 private: 261 private:
248 // Map of storage names to storage info. 262 // Map of storage names to storage info.
249 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap; 263 typedef std::map<std::string, MtpStorageInfo> StorageInfoMap;
250 // Callback queues - DBus communication is in-order, thus callbacks are 264 // Callback queues - DBus communication is in-order, thus callbacks are
251 // received in the same order as the requests. 265 // received in the same order as the requests.
252 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue; 266 typedef std::queue<OpenStorageCallback> OpenStorageCallbackQueue;
253 // (callback, handle) 267 // (callback, handle)
254 typedef std::queue<std::pair<CloseStorageCallback, std::string> 268 typedef std::queue<std::pair<CloseStorageCallback, std::string>
255 > CloseStorageCallbackQueue; 269 > CloseStorageCallbackQueue;
256 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue; 270 typedef std::queue<ReadDirectoryCallback> ReadDirectoryCallbackQueue;
257 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue; 271 typedef std::queue<ReadFileCallback> ReadFileCallbackQueue;
258 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue; 272 typedef std::queue<GetFileInfoCallback> GetFileInfoCallbackQueue;
259 273
260 void OnStorageChanged(bool is_attach, const std::string& storage_name) { 274 void OnStorageChanged(bool is_attach, const std::string& storage_name) {
261 DCHECK(thread_checker_.CalledOnValidThread()); 275 DCHECK(thread_checker_.CalledOnValidThread());
276 DCHECK(mtp_client_);
262 if (is_attach) { 277 if (is_attach) {
263 mtp_client_->GetStorageInfo( 278 mtp_client_->GetStorageInfo(
264 storage_name, 279 storage_name,
265 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, 280 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo,
266 weak_ptr_factory_.GetWeakPtr()), 281 weak_ptr_factory_.GetWeakPtr()),
267 base::Bind(&base::DoNothing)); 282 base::Bind(&base::DoNothing));
268 return; 283 return;
269 } 284 }
270 285
271 // Detach case. 286 // Detach case.
272 StorageInfoMap::iterator it = storage_info_map_.find(storage_name); 287 StorageInfoMap::iterator it = storage_info_map_.find(storage_name);
273 if (it == storage_info_map_.end()) { 288 if (it == storage_info_map_.end()) {
274 // This might happen during initialization when |storage_info_map_| has 289 // This might happen during initialization when |storage_info_map_| has
275 // not been fully populated yet? 290 // not been fully populated yet?
276 return; 291 return;
277 } 292 }
278 storage_info_map_.erase(it); 293 storage_info_map_.erase(it);
279 FOR_EACH_OBSERVER(Observer, 294 FOR_EACH_OBSERVER(Observer,
280 observers_, 295 observers_,
281 StorageChanged(false /* detach */, storage_name)); 296 StorageChanged(false /* detach */, storage_name));
282 } 297 }
283 298
284 void OnEnumerateStorages(const std::vector<std::string>& storage_names) { 299 void OnEnumerateStorages(const std::vector<std::string>& storage_names) {
285 DCHECK(thread_checker_.CalledOnValidThread()); 300 DCHECK(thread_checker_.CalledOnValidThread());
301 DCHECK(mtp_client_);
286 for (size_t i = 0; i < storage_names.size(); ++i) { 302 for (size_t i = 0; i < storage_names.size(); ++i) {
287 mtp_client_->GetStorageInfo( 303 mtp_client_->GetStorageInfo(
288 storage_names[i], 304 storage_names[i],
289 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo, 305 base::Bind(&MediaTransferProtocolManagerImpl::OnGetStorageInfo,
290 weak_ptr_factory_.GetWeakPtr()), 306 weak_ptr_factory_.GetWeakPtr()),
291 base::Bind(&base::DoNothing)); 307 base::Bind(&base::DoNothing));
292 } 308 }
293 } 309 }
294 310
295 void OnGetStorageInfo(const MtpStorageInfo& storage_info) { 311 void OnGetStorageInfo(const MtpStorageInfo& storage_info) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 dbus::Bus* GetBus() { 405 dbus::Bus* GetBus() {
390 DCHECK(thread_checker_.CalledOnValidThread()); 406 DCHECK(thread_checker_.CalledOnValidThread());
391 #if defined(OS_CHROMEOS) 407 #if defined(OS_CHROMEOS)
392 return chromeos::DBusThreadManager::Get()->GetSystemBus(); 408 return chromeos::DBusThreadManager::Get()->GetSystemBus();
393 #else 409 #else
394 return session_bus_.get(); 410 return session_bus_.get();
395 #endif 411 #endif
396 } 412 }
397 413
398 // Callback to finish initialization after figuring out if the mtp service 414 // Callback to finish initialization after figuring out if the mtp service
399 // has an owner. 415 // has an owner, or if the service owner has changed.
400 // |service_owner| contains the name of the current owner, if any. 416 // |mtpd_service_owner| contains the name of the current owner, if any.
401 void FinishSetupOnOriginThread(const std::string& service_owner) { 417 void FinishSetupOnOriginThread(const std::string& mtpd_service_owner) {
402 DCHECK(thread_checker_.CalledOnValidThread()); 418 DCHECK(thread_checker_.CalledOnValidThread());
403 419
404 if (service_owner.empty()) { 420 if (mtpd_service_owner == current_mtpd_owner_)
405 #if !defined(OS_CHROMEOS) 421 return;
406 // |session_bus_| will not get used. Manually shut it down. 422
407 session_bus_->PostTaskToDBusThread( 423 if (mtpd_service_owner.empty()) {
408 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_)); 424 current_mtpd_owner_.clear();
409 #endif 425 mtp_client_.reset();
410 return; 426 return;
411 } 427 }
412 428
429 current_mtpd_owner_ = mtpd_service_owner;
430
413 mtp_client_.reset( 431 mtp_client_.reset(
414 MediaTransferProtocolDaemonClient::Create(GetBus(), 432 MediaTransferProtocolDaemonClient::Create(GetBus(),
415 false /* not stub */)); 433 false /* not stub */));
416 434
417 // Set up signals and start initializing |storage_info_map_|. 435 // Set up signals and start initializing |storage_info_map_|.
418 mtp_client_->SetUpConnections( 436 mtp_client_->SetUpConnections(
419 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, 437 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged,
420 weak_ptr_factory_.GetWeakPtr())); 438 weak_ptr_factory_.GetWeakPtr()));
421 mtp_client_->EnumerateStorages( 439 mtp_client_->EnumerateStorages(
422 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, 440 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages,
(...skipping 15 matching lines...) Expand all
438 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_; 456 base::WeakPtrFactory<MediaTransferProtocolManagerImpl> weak_ptr_factory_;
439 457
440 // Everything below is only accessed on the UI thread. 458 // Everything below is only accessed on the UI thread.
441 459
442 // Map to keep track of attached storages by name. 460 // Map to keep track of attached storages by name.
443 StorageInfoMap storage_info_map_; 461 StorageInfoMap storage_info_map_;
444 462
445 // Set of open storage handles. 463 // Set of open storage handles.
446 std::set<std::string> handles_; 464 std::set<std::string> handles_;
447 465
466 dbus::Bus::GetServiceOwnerCallback mtpd_owner_changed_callback_;
467
468 std::string current_mtpd_owner_;
469
448 // Queued callbacks. 470 // Queued callbacks.
449 OpenStorageCallbackQueue open_storage_callbacks_; 471 OpenStorageCallbackQueue open_storage_callbacks_;
450 CloseStorageCallbackQueue close_storage_callbacks_; 472 CloseStorageCallbackQueue close_storage_callbacks_;
451 ReadDirectoryCallbackQueue read_directory_callbacks_; 473 ReadDirectoryCallbackQueue read_directory_callbacks_;
452 ReadFileCallbackQueue read_file_callbacks_; 474 ReadFileCallbackQueue read_file_callbacks_;
453 GetFileInfoCallbackQueue get_file_info_callbacks_; 475 GetFileInfoCallbackQueue get_file_info_callbacks_;
454 476
455 base::ThreadChecker thread_checker_; 477 base::ThreadChecker thread_checker_;
456 478
457 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl); 479 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolManagerImpl);
458 }; 480 };
459 481
460 } // namespace 482 } // namespace
461 483
462 // static 484 // static
463 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize( 485 MediaTransferProtocolManager* MediaTransferProtocolManager::Initialize(
464 scoped_refptr<base::SequencedTaskRunner> task_runner) { 486 scoped_refptr<base::SequencedTaskRunner> task_runner) {
465 DCHECK(!g_media_transfer_protocol_manager); 487 DCHECK(!g_media_transfer_protocol_manager);
466 488
467 g_media_transfer_protocol_manager = 489 g_media_transfer_protocol_manager =
468 new MediaTransferProtocolManagerImpl(task_runner); 490 new MediaTransferProtocolManagerImpl(task_runner);
469 VLOG(1) << "MediaTransferProtocolManager initialized"; 491 VLOG(1) << "MediaTransferProtocolManager initialized";
470 492
471 return g_media_transfer_protocol_manager; 493 return g_media_transfer_protocol_manager;
472 } 494 }
473 495
474 } // namespace device 496 } // namespace device
OLDNEW
« no previous file with comments | « dbus/bus_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698