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

Side by Side Diff: media/filters/file_data_source.cc

Issue 109273002: Convert base::MemoryMappedFile to use File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Posix GetSize Created 6 years, 12 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/filters/file_data_source.h" 5 #include "media/filters/file_data_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 FileDataSource::FileDataSource() 13 FileDataSource::FileDataSource()
14 : force_read_errors_(false), 14 : force_read_errors_(false),
15 force_streaming_(false) { 15 force_streaming_(false) {
16 } 16 }
17 17
18 FileDataSource::FileDataSource(base::File file)
19 : force_read_errors_(false),
20 force_streaming_(false) {
21 if (!file_.Initialize(file.Pass()))
22 return;
23
24 UpdateHostBytes();
25 }
26
18 bool FileDataSource::Initialize(const base::FilePath& file_path) { 27 bool FileDataSource::Initialize(const base::FilePath& file_path) {
19 DCHECK(!file_.IsValid()); 28 DCHECK(!file_.IsValid());
20 29
21 if (!file_.Initialize(file_path)) 30 if (!file_.Initialize(file_path))
22 return false; 31 return false;
23 32
24 UpdateHostBytes(); 33 UpdateHostBytes();
25 return true;
26 }
27
28 bool FileDataSource::InitializeFromPlatformFile(
29 const base::PlatformFile& file) {
30 DCHECK(!file_.IsValid());
31
32 if (!file_.Initialize(file))
33 return false;
34
35 UpdateHostBytes();
36 return true; 34 return true;
37 } 35 }
38 36
39 void FileDataSource::set_host(DataSourceHost* host) { 37 void FileDataSource::set_host(DataSourceHost* host) {
40 DataSource::set_host(host); 38 DataSource::set_host(host);
41 UpdateHostBytes(); 39 UpdateHostBytes();
42 } 40 }
43 41
44 void FileDataSource::Stop(const base::Closure& callback) { 42 void FileDataSource::Stop(const base::Closure& callback) {
45 callback.Run(); 43 callback.Run();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 FileDataSource::~FileDataSource() {} 78 FileDataSource::~FileDataSource() {}
81 79
82 void FileDataSource::UpdateHostBytes() { 80 void FileDataSource::UpdateHostBytes() {
83 if (host() && file_.IsValid()) { 81 if (host() && file_.IsValid()) {
84 host()->SetTotalBytes(file_.length()); 82 host()->SetTotalBytes(file_.length());
85 host()->AddBufferedByteRange(0, file_.length()); 83 host()->AddBufferedByteRange(0, file_.length());
86 } 84 }
87 } 85 }
88 86
89 } // namespace media 87 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698