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/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" | 8 #include "chrome/common/extensions/chrome_utility_extensions_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_t total_size) |
14 : total_size_(total_size), | 14 : total_size_(total_size), |
15 utility_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 15 utility_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
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::Stop() { | 24 void IPCDataSource::Stop() { |
25 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 25 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
26 } | 26 } |
27 | 27 |
28 void IPCDataSource::Read(int64 position, int size, uint8* data, | 28 void IPCDataSource::Read(int64_t position, |
| 29 int size, |
| 30 uint8_t* data, |
29 const DataSource::ReadCB& read_cb) { | 31 const DataSource::ReadCB& read_cb) { |
30 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 32 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
31 utility_task_runner_->PostTask( | 33 utility_task_runner_->PostTask( |
32 FROM_HERE, | 34 FROM_HERE, |
33 base::Bind(&IPCDataSource::ReadOnUtilityThread, base::Unretained(this), | 35 base::Bind(&IPCDataSource::ReadOnUtilityThread, base::Unretained(this), |
34 position, size, data, read_cb)); | 36 position, size, data, read_cb)); |
35 } | 37 } |
36 | 38 |
37 bool IPCDataSource::GetSize(int64* size_out) { | 39 bool IPCDataSource::GetSize(int64_t* size_out) { |
38 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 40 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
39 *size_out = total_size_; | 41 *size_out = total_size_; |
40 return true; | 42 return true; |
41 } | 43 } |
42 | 44 |
43 bool IPCDataSource::IsStreaming() { | 45 bool IPCDataSource::IsStreaming() { |
44 DCHECK(data_source_thread_checker_.CalledOnValidThread()); | 46 DCHECK(data_source_thread_checker_.CalledOnValidThread()); |
45 return false; | 47 return false; |
46 } | 48 } |
47 | 49 |
(...skipping 12 matching lines...) Expand all Loading... |
60 return handled; | 62 return handled; |
61 } | 63 } |
62 | 64 |
63 IPCDataSource::Request::Request() | 65 IPCDataSource::Request::Request() |
64 : destination(NULL) { | 66 : destination(NULL) { |
65 } | 67 } |
66 | 68 |
67 IPCDataSource::Request::~Request() { | 69 IPCDataSource::Request::~Request() { |
68 } | 70 } |
69 | 71 |
70 void IPCDataSource::ReadOnUtilityThread(int64 position, int size, uint8* data, | 72 void IPCDataSource::ReadOnUtilityThread(int64_t position, |
| 73 int size, |
| 74 uint8_t* data, |
71 const DataSource::ReadCB& read_cb) { | 75 const DataSource::ReadCB& read_cb) { |
72 DCHECK(utility_thread_checker_.CalledOnValidThread()); | 76 DCHECK(utility_thread_checker_.CalledOnValidThread()); |
73 CHECK_GE(total_size_, 0); | 77 CHECK_GE(total_size_, 0); |
74 CHECK_GE(position, 0); | 78 CHECK_GE(position, 0); |
75 CHECK_GE(size, 0); | 79 CHECK_GE(size, 0); |
76 | 80 |
77 // Cap position and size within bounds. | 81 // Cap position and size within bounds. |
78 position = std::min(position, total_size_); | 82 position = std::min(position, total_size_); |
79 int64 clamped_size = | 83 int64_t clamped_size = |
80 std::min(static_cast<int64>(size), total_size_ - position); | 84 std::min(static_cast<int64_t>(size), total_size_ - position); |
81 | 85 |
82 int64 request_id = ++next_request_id_; | 86 int64_t request_id = ++next_request_id_; |
83 | 87 |
84 Request request; | 88 Request request; |
85 request.destination = data; | 89 request.destination = data; |
86 request.callback = read_cb; | 90 request.callback = read_cb; |
87 | 91 |
88 pending_requests_[request_id] = request; | 92 pending_requests_[request_id] = request; |
89 content::UtilityThread::Get()->Send(new ChromeUtilityHostMsg_RequestBlobBytes( | 93 content::UtilityThread::Get()->Send(new ChromeUtilityHostMsg_RequestBlobBytes( |
90 request_id, position, clamped_size)); | 94 request_id, position, clamped_size)); |
91 } | 95 } |
92 | 96 |
93 void IPCDataSource::OnRequestBlobBytesFinished(int64 request_id, | 97 void IPCDataSource::OnRequestBlobBytesFinished(int64_t request_id, |
94 const std::string& bytes) { | 98 const std::string& bytes) { |
95 DCHECK(utility_thread_checker_.CalledOnValidThread()); | 99 DCHECK(utility_thread_checker_.CalledOnValidThread()); |
96 std::map<int64, Request>::iterator it = pending_requests_.find(request_id); | 100 std::map<int64_t, Request>::iterator it = pending_requests_.find(request_id); |
97 | 101 |
98 if (it == pending_requests_.end()) | 102 if (it == pending_requests_.end()) |
99 return; | 103 return; |
100 | 104 |
101 std::copy(bytes.begin(), bytes.end(), it->second.destination); | 105 std::copy(bytes.begin(), bytes.end(), it->second.destination); |
102 it->second.callback.Run(bytes.size()); | 106 it->second.callback.Run(bytes.size()); |
103 | 107 |
104 pending_requests_.erase(it); | 108 pending_requests_.erase(it); |
105 } | 109 } |
106 | 110 |
107 } // namespace metadata | 111 } // namespace metadata |
OLD | NEW |