| 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 "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 5 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 348 } |
| 349 | 349 |
| 350 void OnStorageDetached(const std::string& storage_name) { | 350 void OnStorageDetached(const std::string& storage_name) { |
| 351 DCHECK(thread_checker_.CalledOnValidThread()); | 351 DCHECK(thread_checker_.CalledOnValidThread()); |
| 352 if (storage_info_map_.erase(storage_name) == 0) { | 352 if (storage_info_map_.erase(storage_name) == 0) { |
| 353 // This can happen for a storage where | 353 // This can happen for a storage where |
| 354 // MediaTransferProtocolDaemonClient::GetStorageInfo() failed. | 354 // MediaTransferProtocolDaemonClient::GetStorageInfo() failed. |
| 355 // Return to avoid giving observers phantom detach events. | 355 // Return to avoid giving observers phantom detach events. |
| 356 return; | 356 return; |
| 357 } | 357 } |
| 358 FOR_EACH_OBSERVER(Observer, | 358 for (auto& observer : observers_) |
| 359 observers_, | 359 observer.StorageChanged(false /* detach */, storage_name); |
| 360 StorageChanged(false /* detach */, storage_name)); | |
| 361 } | 360 } |
| 362 | 361 |
| 363 void OnStorageChanged(bool is_attach, const std::string& storage_name) { | 362 void OnStorageChanged(bool is_attach, const std::string& storage_name) { |
| 364 DCHECK(thread_checker_.CalledOnValidThread()); | 363 DCHECK(thread_checker_.CalledOnValidThread()); |
| 365 DCHECK(mtp_client_); | 364 DCHECK(mtp_client_); |
| 366 if (is_attach) | 365 if (is_attach) |
| 367 OnStorageAttached(storage_name); | 366 OnStorageAttached(storage_name); |
| 368 else | 367 else |
| 369 OnStorageDetached(storage_name); | 368 OnStorageDetached(storage_name); |
| 370 } | 369 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 391 // After that, all incoming signals are either for new storage | 390 // After that, all incoming signals are either for new storage |
| 392 // attachments, which should not be in |storage_info_map_|, or for | 391 // attachments, which should not be in |storage_info_map_|, or for |
| 393 // storage detachments, which do not add to |storage_info_map_|. | 392 // storage detachments, which do not add to |storage_info_map_|. |
| 394 // Return to avoid giving observers phantom detach events. | 393 // Return to avoid giving observers phantom detach events. |
| 395 NOTREACHED(); | 394 NOTREACHED(); |
| 396 return; | 395 return; |
| 397 } | 396 } |
| 398 | 397 |
| 399 // New storage. Add it and let the observers know. | 398 // New storage. Add it and let the observers know. |
| 400 storage_info_map_.insert(std::make_pair(storage_name, storage_info)); | 399 storage_info_map_.insert(std::make_pair(storage_name, storage_info)); |
| 401 FOR_EACH_OBSERVER(Observer, | 400 for (auto& observer : observers_) |
| 402 observers_, | 401 observer.StorageChanged(true /* is attach */, storage_name); |
| 403 StorageChanged(true /* is attach */, storage_name)); | |
| 404 } | 402 } |
| 405 | 403 |
| 406 void OnGetStorageInfoFromDevice(const MtpStorageInfo& storage_info) { | 404 void OnGetStorageInfoFromDevice(const MtpStorageInfo& storage_info) { |
| 407 get_storage_info_from_device_callbacks_.front().Run(storage_info, | 405 get_storage_info_from_device_callbacks_.front().Run(storage_info, |
| 408 false /* no error */); | 406 false /* no error */); |
| 409 get_storage_info_from_device_callbacks_.pop(); | 407 get_storage_info_from_device_callbacks_.pop(); |
| 410 } | 408 } |
| 411 | 409 |
| 412 void OnGetStorageInfoFromDeviceError() { | 410 void OnGetStorageInfoFromDeviceError() { |
| 413 MtpStorageInfo info; | 411 MtpStorageInfo info; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 DCHECK(!g_media_transfer_protocol_manager); | 710 DCHECK(!g_media_transfer_protocol_manager); |
| 713 | 711 |
| 714 g_media_transfer_protocol_manager = | 712 g_media_transfer_protocol_manager = |
| 715 new MediaTransferProtocolManagerImpl(task_runner); | 713 new MediaTransferProtocolManagerImpl(task_runner); |
| 716 VLOG(1) << "MediaTransferProtocolManager initialized"; | 714 VLOG(1) << "MediaTransferProtocolManager initialized"; |
| 717 | 715 |
| 718 return g_media_transfer_protocol_manager; | 716 return g_media_transfer_protocol_manager; |
| 719 } | 717 } |
| 720 | 718 |
| 721 } // namespace device | 719 } // namespace device |
| OLD | NEW |