Chromium Code Reviews| 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 GetBus()->UnlistenForServiceOwnerChange(mtpd::kMtpdServiceName, |
|
satorux1
2013/11/05 03:41:18
check GetBus() here too?
pneubeck (no reviews)
2013/11/05 09:54:29
Ops. Missed that. Good catch!
| |
| 69 mtpd_owner_changed_callback_); | 71 mtpd_owner_changed_callback_); |
| 70 | 72 |
| 71 #if !defined(OS_CHROMEOS) | 73 #if !defined(OS_CHROMEOS) |
| 72 session_bus_->GetDBusTaskRunner()->PostTask( | 74 session_bus_->GetDBusTaskRunner()->PostTask( |
| 73 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_)); | 75 FROM_HERE, base::Bind(&dbus::Bus::ShutdownAndBlock, session_bus_)); |
| 74 #endif | 76 #endif |
| 75 | 77 |
| 76 VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; | 78 VLOG(1) << "MediaTransferProtocolManager Shutdown completed"; |
| 77 } | 79 } |
| 78 | 80 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 return; | 423 return; |
| 422 | 424 |
| 423 if (mtpd_service_owner.empty()) { | 425 if (mtpd_service_owner.empty()) { |
| 424 current_mtpd_owner_.clear(); | 426 current_mtpd_owner_.clear(); |
| 425 mtp_client_.reset(); | 427 mtp_client_.reset(); |
| 426 return; | 428 return; |
| 427 } | 429 } |
| 428 | 430 |
| 429 current_mtpd_owner_ = mtpd_service_owner; | 431 current_mtpd_owner_ = mtpd_service_owner; |
| 430 | 432 |
| 431 mtp_client_.reset( | 433 mtp_client_.reset(MediaTransferProtocolDaemonClient::Create(GetBus())); |
| 432 MediaTransferProtocolDaemonClient::Create(GetBus(), | |
| 433 false /* not stub */)); | |
| 434 | 434 |
| 435 // Set up signals and start initializing |storage_info_map_|. | 435 // Set up signals and start initializing |storage_info_map_|. |
| 436 mtp_client_->SetUpConnections( | 436 mtp_client_->SetUpConnections( |
| 437 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, | 437 base::Bind(&MediaTransferProtocolManagerImpl::OnStorageChanged, |
| 438 weak_ptr_factory_.GetWeakPtr())); | 438 weak_ptr_factory_.GetWeakPtr())); |
| 439 mtp_client_->EnumerateStorages( | 439 mtp_client_->EnumerateStorages( |
| 440 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, | 440 base::Bind(&MediaTransferProtocolManagerImpl::OnEnumerateStorages, |
| 441 weak_ptr_factory_.GetWeakPtr()), | 441 weak_ptr_factory_.GetWeakPtr()), |
| 442 base::Bind(&base::DoNothing)); | 442 base::Bind(&base::DoNothing)); |
| 443 } | 443 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 DCHECK(!g_media_transfer_protocol_manager); | 487 DCHECK(!g_media_transfer_protocol_manager); |
| 488 | 488 |
| 489 g_media_transfer_protocol_manager = | 489 g_media_transfer_protocol_manager = |
| 490 new MediaTransferProtocolManagerImpl(task_runner); | 490 new MediaTransferProtocolManagerImpl(task_runner); |
| 491 VLOG(1) << "MediaTransferProtocolManager initialized"; | 491 VLOG(1) << "MediaTransferProtocolManager initialized"; |
| 492 | 492 |
| 493 return g_media_transfer_protocol_manager; | 493 return g_media_transfer_protocol_manager; |
| 494 } | 494 } |
| 495 | 495 |
| 496 } // namespace device | 496 } // namespace device |
| OLD | NEW |