OLD | NEW |
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 "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 void HoldFileRef( | 49 void HoldFileRef( |
50 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 50 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
51 } | 51 } |
52 | 52 |
53 void DidOpenSnapshot( | 53 void DidOpenSnapshot( |
54 const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback, | 54 const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback, |
55 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | 55 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, |
56 base::File file) { | 56 base::File file) { |
57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
58 if (file.error_details() != base::File::FILE_OK) { | 58 if (!file.IsValid()) { |
59 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); | 59 callback.Run(file.Pass(), base::Closure()); |
60 callback.Run(file.error_details(), | |
61 base::PassPlatformFile(&invalid_file), | |
62 base::Closure()); | |
63 return; | 60 return; |
64 } | 61 } |
65 base::PlatformFile platform_file = file.TakePlatformFile(); | 62 callback.Run(file.Pass(), base::Bind(&HoldFileRef, file_ref)); |
66 callback.Run(base::File::FILE_OK, | |
67 base::PassPlatformFile(&platform_file), | |
68 base::Bind(&HoldFileRef, file_ref)); | |
69 } | 63 } |
70 | 64 |
71 } // namespace | 65 } // namespace |
72 | 66 |
73 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter) | 67 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter) |
74 : media_path_filter_(media_path_filter), | 68 : media_path_filter_(media_path_filter), |
75 weak_factory_(this) { | 69 weak_factory_(this) { |
76 } | 70 } |
77 | 71 |
78 NativeMediaFileUtil::~NativeMediaFileUtil() { | 72 NativeMediaFileUtil::~NativeMediaFileUtil() { |
(...skipping 26 matching lines...) Expand all Loading... |
105 void NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen( | 99 void NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen( |
106 base::SequencedTaskRunner* media_task_runner, | 100 base::SequencedTaskRunner* media_task_runner, |
107 int file_flags, | 101 int file_flags, |
108 const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback, | 102 const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback, |
109 base::File::Error result, | 103 base::File::Error result, |
110 const base::File::Info& file_info, | 104 const base::File::Info& file_info, |
111 const base::FilePath& platform_path, | 105 const base::FilePath& platform_path, |
112 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 106 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
114 if (result != base::File::FILE_OK) { | 108 if (result != base::File::FILE_OK) { |
115 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); | 109 callback.Run(base::File(), base::Closure()); |
116 callback.Run(result, | |
117 base::PassPlatformFile(&invalid_file), | |
118 base::Closure()); | |
119 return; | 110 return; |
120 } | 111 } |
121 base::PostTaskAndReplyWithResult( | 112 base::PostTaskAndReplyWithResult( |
122 media_task_runner, | 113 media_task_runner, |
123 FROM_HERE, | 114 FROM_HERE, |
124 base::Bind(&fileapi::NativeFileUtil::CreateOrOpen, | 115 base::Bind(&fileapi::NativeFileUtil::CreateOrOpen, |
125 platform_path, | 116 platform_path, |
126 file_flags), | 117 file_flags), |
127 base::Bind(&DidOpenSnapshot, | 118 base::Bind(&DidOpenSnapshot, callback, file_ref)); |
128 callback, | |
129 file_ref)); | |
130 } | 119 } |
131 | 120 |
132 void NativeMediaFileUtil::CreateOrOpen( | 121 void NativeMediaFileUtil::CreateOrOpen( |
133 scoped_ptr<fileapi::FileSystemOperationContext> context, | 122 scoped_ptr<fileapi::FileSystemOperationContext> context, |
134 const fileapi::FileSystemURL& url, | 123 const fileapi::FileSystemURL& url, |
135 int file_flags, | 124 int file_flags, |
136 const CreateOrOpenCallback& callback) { | 125 const CreateOrOpenCallback& callback) { |
137 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 126 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
138 // Returns an error if any unsupported flag is found. | 127 // Returns an error if any unsupported flag is found. |
139 if (file_flags & ~(base::File::FLAG_OPEN | | 128 if (file_flags & ~(base::File::FLAG_OPEN | |
140 base::File::FLAG_READ | | 129 base::File::FLAG_READ | |
141 base::File::FLAG_WRITE_ATTRIBUTES)) { | 130 base::File::FLAG_WRITE_ATTRIBUTES)) { |
142 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); | 131 callback.Run(base::File(base::File::FILE_ERROR_SECURITY), base::Closure()); |
143 callback.Run(base::File::FILE_ERROR_SECURITY, | |
144 base::PassPlatformFile(&invalid_file), | |
145 base::Closure()); | |
146 return; | 132 return; |
147 } | 133 } |
148 scoped_refptr<base::SequencedTaskRunner> task_runner = context->task_runner(); | 134 scoped_refptr<base::SequencedTaskRunner> task_runner = context->task_runner(); |
149 CreateSnapshotFile( | 135 CreateSnapshotFile( |
150 context.Pass(), | 136 context.Pass(), |
151 url, | 137 url, |
152 base::Bind(&NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen, | 138 base::Bind(&NativeMediaFileUtil::CreatedSnapshotFileForCreateOrOpen, |
153 task_runner, | 139 task_runner, |
154 file_flags, | 140 file_flags, |
155 callback)); | 141 callback)); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return base::File::FILE_ERROR_FAILED; | 670 return base::File::FILE_ERROR_FAILED; |
685 | 671 |
686 if (!file_info.is_directory && | 672 if (!file_info.is_directory && |
687 !media_path_filter_->Match(file_path)) { | 673 !media_path_filter_->Match(file_path)) { |
688 return failure_error; | 674 return failure_error; |
689 } | 675 } |
690 | 676 |
691 *local_file_path = file_path; | 677 *local_file_path = file_path; |
692 return base::File::FILE_OK; | 678 return base::File::FILE_OK; |
693 } | 679 } |
OLD | NEW |