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 <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 Loading... |
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 // Listen for future mtpd service owner changes, in case it is not | 53 if (GetBus()) { |
54 // available right now. There is no guarantee on Linux or ChromeOS that | 54 // Listen for future mtpd service owner changes, in case it is not |
55 // mtpd is running already. | 55 // available right now. There is no guarantee on Linux or ChromeOS that |
56 mtpd_owner_changed_callback_ = | 56 // mtpd is running already. |
57 base::Bind(&MediaTransferProtocolManagerImpl::FinishSetupOnOriginThread, | 57 mtpd_owner_changed_callback_ = base::Bind( |
58 weak_ptr_factory_.GetWeakPtr()); | 58 &MediaTransferProtocolManagerImpl::FinishSetupOnOriginThread, |
59 GetBus()->ListenForServiceOwnerChange(mtpd::kMtpdServiceName, | 59 weak_ptr_factory_.GetWeakPtr()); |
60 mtpd_owner_changed_callback_); | 60 GetBus()->ListenForServiceOwnerChange(mtpd::kMtpdServiceName, |
61 GetBus()->GetServiceOwner(mtpd::kMtpdServiceName, | 61 mtpd_owner_changed_callback_); |
62 mtpd_owner_changed_callback_); | 62 GetBus()->GetServiceOwner(mtpd::kMtpdServiceName, |
| 63 mtpd_owner_changed_callback_); |
| 64 } |
63 } | 65 } |
64 | 66 |
65 virtual ~MediaTransferProtocolManagerImpl() { | 67 virtual ~MediaTransferProtocolManagerImpl() { |
66 DCHECK(g_media_transfer_protocol_manager); | 68 DCHECK(g_media_transfer_protocol_manager); |
67 g_media_transfer_protocol_manager = NULL; | 69 g_media_transfer_protocol_manager = NULL; |
68 GetBus()->UnlistenForServiceOwnerChange(mtpd::kMtpdServiceName, | 70 if (GetBus()) { |
69 mtpd_owner_changed_callback_); | 71 GetBus()->UnlistenForServiceOwnerChange(mtpd::kMtpdServiceName, |
| 72 mtpd_owner_changed_callback_); |
| 73 } |
70 | 74 |
71 #if !defined(OS_CHROMEOS) | 75 #if !defined(OS_CHROMEOS) |
72 session_bus_->GetDBusTaskRunner()->PostTask( | 76 session_bus_->GetDBusTaskRunner()->PostTask( |
73 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_)); | 77 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_)); |
74 #endif | 78 #endif |
75 | 79 |
76 VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; | 80 VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; |
77 } | 81 } |
78 | 82 |
79 // MediaTransferProtocolManager override. | 83 // MediaTransferProtocolManager override. |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return; | 425 return; |
422 | 426 |
423 if (mtpd_service_owner.empty()) { | 427 if (mtpd_service_owner.empty()) { |
424 current_mtpd_owner_.clear(); | 428 current_mtpd_owner_.clear(); |
425 mtp_client_.reset(); | 429 mtp_client_.reset(); |
426 return; | 430 return; |
427 } | 431 } |
428 | 432 |
429 current_mtpd_owner_ = mtpd_service_owner; | 433 current_mtpd_owner_ = mtpd_service_owner; |
430 | 434 |
431 mtp_client_.reset( | 435 mtp_client_.reset(MediaTransferProtocolDaemonClient::Create(GetBus())); |
432 MediaTransferProtocolDaemonClient::Create(GetBus(), | |
433 false /* not stub */)); | |
434 | 436 |
435 // Set up signals and start initializing |storage_info_map_|. | 437 // Set up signals and start initializing |storage_info_map_|. |
436 mtp_client_->SetUpConnections( | 438 mtp_client_->SetUpConnections( |
437 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, | 439 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, |
438 weak_ptr_factory_.GetWeakPtr())); | 440 weak_ptr_factory_.GetWeakPtr())); |
439 mtp_client_->EnumerateStorages( | 441 mtp_client_->EnumerateStorages( |
440 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, | 442 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, |
441 weak_ptr_factory_.GetWeakPtr()), | 443 weak_ptr_factory_.GetWeakPtr()), |
442 base::Bind(&base::DoNothing)); | 444 base::Bind(&base::DoNothing)); |
443 } | 445 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 DCHECK(!g_media_transfer_protocol_manager); | 489 DCHECK(!g_media_transfer_protocol_manager); |
488 | 490 |
489 g_media_transfer_protocol_manager = | 491 g_media_transfer_protocol_manager = |
490 new MediaTransferProtocolManagerImpl(task_runner); | 492 new MediaTransferProtocolManagerImpl(task_runner); |
491 VLOG(1) << "MediaTransferProtocolManager initialized"; | 493 VLOG(1) << "MediaTransferProtocolManager initialized"; |
492 | 494 |
493 return g_media_transfer_protocol_manager; | 495 return g_media_transfer_protocol_manager; |
494 } | 496 } |
495 | 497 |
496 } // namespace device | 498 } // namespace device |
OLD | NEW |