Index: chrome/utility/media_galleries/ipc_tunnel_data_source.cc |
diff --git a/chrome/utility/media_galleries/ipc_tunnel_data_source.cc b/chrome/utility/media_galleries/ipc_tunnel_data_source.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ad99798a43f7514b041a7279767ce50e20a1997a |
--- /dev/null |
+++ b/chrome/utility/media_galleries/ipc_tunnel_data_source.cc |
@@ -0,0 +1,85 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/utility/media_galleries/ipc_tunnel_data_source.h" |
+ |
+#include "chrome/common/chrome_utility_messages.h" |
+#include "content/public/utility/utility_thread.h" |
+ |
+namespace metadata { |
+ |
+IPCTunnelDataSource::IPCTunnelDataSource(int64 total_size) |
+ : total_size_(total_size), |
+ next_request_id_(0) { |
+} |
+ |
+IPCTunnelDataSource::~IPCTunnelDataSource() {} |
+ |
+void IPCTunnelDataSource::set_host(media::DataSourceHost* host) { |
+ DataSource::set_host(host); |
+ if (media::DataSource::host()) { |
+ media::DataSource::host()->SetTotalBytes(total_size_); |
+ } |
+} |
+ |
+void IPCTunnelDataSource::Stop(const base::Closure& callback) { |
+ callback.Run(); |
+} |
+ |
+void IPCTunnelDataSource::Read(int64 position, int size, uint8* data, |
+ const DataSource::ReadCB& read_cb) { |
+ CHECK_GE(total_size_, 0); |
+ CHECK_GE(position, 0); |
+ CHECK_GE(size, 0); |
+ |
+ // Cap position and size within bounds. |
+ position = std::min(position, total_size_); |
+ int64 clamped_size = |
+ std::min(static_cast<int64>(size), total_size_ - position); |
+ |
+ int64 request_id = ++next_request_id_; |
+ |
+ Request request; |
+ request.destination = data; |
+ request.callback = read_cb; |
+ |
+ pending_requests_[request_id] = request; |
+ content::UtilityThread::Get()->Send( |
+ new ChromeUtilityHostMsg_ParseMediaMetadata_RequestBlobBytes( |
+ request_id, position, clamped_size)); |
+} |
+ |
+bool IPCTunnelDataSource::GetSize(int64* size_out) { |
+ *size_out = total_size_; |
+ return true; |
+} |
+ |
+bool IPCTunnelDataSource::IsStreaming() { |
+ return false; |
+} |
+ |
+void IPCTunnelDataSource::SetBitrate(int bitrate) { |
+} |
+ |
+void IPCTunnelDataSource::ReceiveBytes(int64 request_id, |
+ const std::string& bytes) { |
+ std::map<int64, Request>::iterator it = pending_requests_.find(request_id); |
+ |
+ if (it == pending_requests_.end()) |
+ return; |
+ |
+ std::copy(bytes.begin(), bytes.end(), it->second.destination); |
+ it->second.callback.Run(bytes.size()); |
+ |
+ pending_requests_.erase(it); |
+} |
+ |
+IPCTunnelDataSource::Request::Request() |
+ : destination(NULL) { |
+} |
+ |
+IPCTunnelDataSource::Request::~Request() { |
+} |
+ |
+} // namespace metadata |