OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/utility/media_galleries/ipc_tunnel_data_reader.h" |
| 6 |
| 7 #include "chrome/common/chrome_utility_messages.h" |
| 8 #include "content/public/utility/utility_thread.h" |
| 9 |
| 10 namespace metadata { |
| 11 |
| 12 IPCTunnelDataReader::IPCTunnelDataReader() : next_request_id_(0) {} |
| 13 |
| 14 IPCTunnelDataReader::~IPCTunnelDataReader() {} |
| 15 |
| 16 void IPCTunnelDataReader::ReadBytes(int64 offset, int64 length, |
| 17 const ReadBytesCallback& callback) { |
| 18 int64 request_id = ++next_request_id_; |
| 19 pending_callbacks_[request_id] = callback; |
| 20 content::UtilityThread::Get()->Send( |
| 21 new ChromeUtilityHostMsg_ParseMediaMetadata_RequestBlobBytes( |
| 22 request_id, offset, length)); |
| 23 } |
| 24 |
| 25 void IPCTunnelDataReader::ReceiveBytes(int64 request_id, |
| 26 const std::string& bytes) { |
| 27 std::map<int64, ReadBytesCallback>::iterator it = |
| 28 pending_callbacks_.find(request_id); |
| 29 |
| 30 if (it == pending_callbacks_.end()) |
| 31 return; |
| 32 |
| 33 it->second.Run(bytes); |
| 34 |
| 35 pending_callbacks_.erase(it); |
| 36 } |
| 37 |
| 38 } // namespace metadata |
OLD | NEW |