ipc_data_source.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 3// found in the LICENSE file. 4 5#ifndef CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 6#define CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 7 8#include <map> 9#include <string> 10 11#include "chrome/utility/utility_message_handler.h" 12#include "media/base/data_source.h" 13 14namespace metadata { 15 16// Provides the metadata parser with bytes from the browser process via IPC. 17class IPCDataSource: public media::DataSource, 18 public chrome::UtilityMessageHandler { 19 public: 20 explicit IPCDataSource(int64 total_size); 21 virtual ~IPCDataSource(); 22 23 // Implementation of DataSource. 24 virtual void set_host(media::DataSourceHost* host) OVERRIDE; 25 virtual void Stop(const base::Closure& callback) OVERRIDE; 26 virtual void Read(int64 position, int size, uint8* data, 27 const ReadCB& read_cb) OVERRIDE; 28 virtual bool GetSize(int64* size_out) OVERRIDE; 29 virtual bool IsStreaming() OVERRIDE; 30 virtual void SetBitrate(int bitrate) OVERRIDE; 31 32 // Implementation of UtilityMessageHandler. 33 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 34 35 private: 36 struct Request { 37 Request(); 38 ~Request(); 39 uint8* destination; 40 ReadCB callback; 41 }; 42 43 void OnRequestBlobBytesFinished(int64 request_id, 44 const std::string& bytes); 45 46 const int64 total_size_; 47 std::map<int64, Request> pending_requests_; 48 int64 next_request_id_; 49}; 50 51} // namespace metadata 52 53#endif // CHROME_UTILITY_MEDIA_GALLERIES_IPC_DATA_SOURCE_H_ 54