Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/utility/media_galleries/ipc_data_source.cc

Issue 103283003: Media Galleries API Metadata: SafeMediaMetadataParser and IPCTunnelDataReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "chrome/utility/media_galleries/ipc_data_source.h"
6
7 #include "chrome/common/chrome_utility_messages.h"
8 #include "content/public/utility/utility_thread.h"
9
10 namespace metadata {
11
12 IPCDataSource::IPCDataSource(int64 total_size)
13 : total_size_(total_size),
14 next_request_id_(0) {
15 }
16
17 IPCDataSource::~IPCDataSource() {}
18
19 void IPCDataSource::set_host(media::DataSourceHost* host) {
20 DataSource::set_host(host);
21 if (media::DataSource::host()) {
22 media::DataSource::host()->SetTotalBytes(total_size_);
23 }
24 }
25
26 void IPCDataSource::Stop(const base::Closure& callback) {
27 callback.Run();
28 }
29
30 void IPCDataSource::Read(int64 position, int size, uint8* data,
31 const DataSource::ReadCB& read_cb) {
32 CHECK_GE(total_size_, 0);
33 CHECK_GE(position, 0);
34 CHECK_GE(size, 0);
35
36 // Cap position and size within bounds.
37 position = std::min(position, total_size_);
38 int64 clamped_size =
39 std::min(static_cast<int64>(size), total_size_ - position);
40
41 int64 request_id = ++next_request_id_;
42
43 Request request;
44 request.destination = data;
45 request.callback = read_cb;
46
47 pending_requests_[request_id] = request;
48 content::UtilityThread::Get()->Send(new ChromeUtilityHostMsg_RequestBlobBytes(
49 request_id, position, clamped_size));
50 }
51
52 bool IPCDataSource::GetSize(int64* size_out) {
53 *size_out = total_size_;
54 return true;
55 }
56
57 bool IPCDataSource::IsStreaming() {
58 return false;
59 }
60
61 void IPCDataSource::SetBitrate(int bitrate) {
62 }
63
64 bool IPCDataSource::OnMessageReceived(const IPC::Message& message) {
65 bool handled = true;
66 IPC_BEGIN_MESSAGE_MAP(IPCDataSource, message)
67 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RequestBlobBytes_Finished,
68 OnRequestBlobBytesFinished)
69 IPC_MESSAGE_UNHANDLED(handled = false)
70 IPC_END_MESSAGE_MAP()
71 return handled;
72 }
73
74 IPCDataSource::Request::Request()
75 : destination(NULL) {
76 }
77
78 IPCDataSource::Request::~Request() {
79 }
80
81 void IPCDataSource::OnRequestBlobBytesFinished(int64 request_id,
82 const std::string& bytes) {
83 std::map<int64, Request>::iterator it = pending_requests_.find(request_id);
84
85 if (it == pending_requests_.end())
86 return;
87
88 std::copy(bytes.begin(), bytes.end(), it->second.destination);
89 it->second.callback.Run(bytes.size());
90
91 pending_requests_.erase(it);
92 }
93
94 } // namespace metadata
OLDNEW
« no previous file with comments | « chrome/utility/media_galleries/ipc_data_source.h ('k') | chrome/utility/media_galleries/media_metadata_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698