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

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

Powered by Google App Engine
This is Rietveld 408576698