| 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 "chrome/browser/media_galleries/scoped_mtp_device_map_entry.h" | 5 #include "chrome/browser/media_galleries/scoped_mtp_device_map_entry.h" |
| 6 | 6 |
| 7 #include "webkit/fileapi/media/mtp_device_file_system_config.h" | 7 #include "chrome/browser/media_galleries/fileapi/mtp_device_file_system_config.h
" |
| 8 | 8 |
| 9 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 9 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" |
| 12 #include "chrome/browser/media_galleries/mtp_device_delegate_impl.h" | 13 #include "chrome/browser/media_galleries/mtp_device_delegate_impl.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "webkit/fileapi/file_system_task_runners.h" | 15 #include "webkit/fileapi/file_system_task_runners.h" |
| 15 #include "webkit/fileapi/media/mtp_device_map_service.h" | 16 |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 namespace chrome { | 19 namespace chrome { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 23 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 23 bool IsMediaTaskRunnerThread() { | 24 bool IsMediaTaskRunnerThread() { |
| 24 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 25 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 25 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 26 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 26 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); | 27 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); |
| 27 return pool->IsRunningSequenceOnCurrentThread(media_sequence_token); | 28 return pool->IsRunningSequenceOnCurrentThread(media_sequence_token); |
| 28 } | 29 } |
| 29 | 30 |
| 30 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() { | 31 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() { |
| 31 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 32 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 32 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 33 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 33 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); | 34 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); |
| 34 return pool->GetSequencedTaskRunner(media_sequence_token); | 35 return pool->GetSequencedTaskRunner(media_sequence_token); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void OnDeviceAsyncDelegateDestroyed( | 38 void OnDeviceAsyncDelegateDestroyed( |
| 38 const base::FilePath::StringType& device_location) { | 39 const base::FilePath::StringType& device_location) { |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 40 fileapi::MTPDeviceMapService::GetInstance()->RemoveAsyncDelegate( | 41 MTPDeviceMapService::GetInstance()->RemoveAsyncDelegate( |
| 41 device_location); | 42 device_location); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void RemoveDeviceDelegate(const base::FilePath::StringType& device_location) { | 45 void RemoveDeviceDelegate(const base::FilePath::StringType& device_location) { |
| 45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 46 content::BrowserThread::PostTask( | 47 content::BrowserThread::PostTask( |
| 47 content::BrowserThread::IO, | 48 content::BrowserThread::IO, |
| 48 FROM_HERE, | 49 FROM_HERE, |
| 49 base::Bind(&OnDeviceAsyncDelegateDestroyed, device_location)); | 50 base::Bind(&OnDeviceAsyncDelegateDestroyed, device_location)); |
| 50 } | 51 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 75 } | 76 } |
| 76 | 77 |
| 77 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() { | 78 ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() { |
| 78 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 79 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 79 RemoveDeviceDelegate(device_location_); | 80 RemoveDeviceDelegate(device_location_); |
| 80 on_destruction_callback_.Run(); | 81 on_destruction_callback_.Run(); |
| 81 #endif | 82 #endif |
| 82 } | 83 } |
| 83 | 84 |
| 84 void ScopedMTPDeviceMapEntry::OnMTPDeviceAsyncDelegateCreated( | 85 void ScopedMTPDeviceMapEntry::OnMTPDeviceAsyncDelegateCreated( |
| 85 fileapi::MTPDeviceAsyncDelegate* delegate) { | 86 MTPDeviceAsyncDelegate* delegate) { |
| 86 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 87 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
| 87 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 88 fileapi::MTPDeviceMapService::GetInstance()->AddAsyncDelegate( | 89 MTPDeviceMapService::GetInstance()->AddAsyncDelegate( |
| 89 device_location_, delegate); | 90 device_location_, delegate); |
| 90 #endif | 91 #endif |
| 91 } | 92 } |
| 92 | 93 |
| 93 } // namespace chrome | 94 } // namespace chrome |
| OLD | NEW |