| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/utility/media_galleries/ipc_data_source.h" | 5 #include "chrome/utility/media_galleries/ipc_data_source.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "chrome/common/chrome_utility_messages.h" | 8 #include "chrome/common/chrome_utility_messages.h" |
| 9 #include "content/public/utility/utility_thread.h" | 9 #include "content/public/utility/utility_thread.h" |
| 10 | 10 |
| 11 namespace metadata { | 11 namespace metadata { |
| 12 | 12 |
| 13 IPCDataSource::IPCDataSource(int64 total_size) | 13 IPCDataSource::IPCDataSource(int64 total_size) |
| 14 : total_size_(total_size), | 14 : total_size_(total_size), |
| 15 utility_task_runner_(base::MessageLoopProxy::current()), | 15 utility_task_runner_(base::MessageLoopProxy::current()), |
| 16 next_request_id_(0) { | 16 next_request_id_(0) { |
| 17 data_source_thread_checker_.DetachFromThread(); | 17 data_source_thread_checker_.DetachFromThread(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 IPCDataSource::~IPCDataSource() { | 20 IPCDataSource::~IPCDataSource() { |
| 21 DCHECK(utility_thread_checker_.CalledOnValidThread()); | 21 DCHECK(utility_thread_checker_.CalledOnValidThread()); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void IPCDataSource::set_host(media::DataSourceHost* host) { | |
| 25 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | |
| 26 DataSource::set_host(host); | |
| 27 if (media::DataSource::host()) { | |
| 28 media::DataSource::host()->SetTotalBytes(total_size_); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void IPCDataSource::Stop(const base::Closure& callback) { | 24 void IPCDataSource::Stop(const base::Closure& callback) { |
| 33 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 25 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
| 34 callback.Run(); | 26 callback.Run(); |
| 35 } | 27 } |
| 36 | 28 |
| 37 void IPCDataSource::Read(int64 position, int size, uint8* data, | 29 void IPCDataSource::Read(int64 position, int size, uint8* data, |
| 38 const DataSource::ReadCB& read_cb) { | 30 const DataSource::ReadCB& read_cb) { |
| 39 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 31 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
| 40 utility_task_runner_->PostTask( | 32 utility_task_runner_->PostTask( |
| 41 FROM_HERE, | 33 FROM_HERE, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (it == pending_requests_.end()) | 99 if (it == pending_requests_.end()) |
| 108 return; | 100 return; |
| 109 | 101 |
| 110 std::copy(bytes.begin(), bytes.end(), it->second.destination); | 102 std::copy(bytes.begin(), bytes.end(), it->second.destination); |
| 111 it->second.callback.Run(bytes.size()); | 103 it->second.callback.Run(bytes.size()); |
| 112 | 104 |
| 113 pending_requests_.erase(it); | 105 pending_requests_.erase(it); |
| 114 } | 106 } |
| 115 | 107 |
| 116 } // namespace metadata | 108 } // namespace metadata |
| OLD | NEW |