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

Side by Side Diff: webkit/blob/local_file_stream_reader.cc

Issue 10808043: Factor out common error-code conversion code for PlatformFileErrorToNetError. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added NET_EXPORT symbol. Created 8 years, 4 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 "webkit/blob/local_file_stream_reader.h" 5 #include "webkit/blob/local_file_stream_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/file_util_proxy.h" 8 #include "base/file_util_proxy.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 14 matching lines...) Expand all
25 // Verify if the underlying file has not been modified. 25 // Verify if the underlying file has not been modified.
26 bool VerifySnapshotTime(const base::Time& expected_modification_time, 26 bool VerifySnapshotTime(const base::Time& expected_modification_time,
27 const base::PlatformFileInfo& file_info) { 27 const base::PlatformFileInfo& file_info) {
28 return expected_modification_time.is_null() || 28 return expected_modification_time.is_null() ||
29 expected_modification_time.ToTimeT() == 29 expected_modification_time.ToTimeT() ==
30 file_info.last_modified.ToTimeT(); 30 file_info.last_modified.ToTimeT();
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 // static
36 int LocalFileStreamReader::PlatformFileErrorToNetError(
37 base::PlatformFileError file_error) {
38 switch (file_error) {
39 case base::PLATFORM_FILE_OK:
40 return net::OK;
41 case base::PLATFORM_FILE_ERROR_NOT_FOUND:
42 return net::ERR_FILE_NOT_FOUND;
43 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
44 return net::ERR_ACCESS_DENIED;
45 default:
46 return net::ERR_FAILED;
47 }
48 }
49
50 LocalFileStreamReader::LocalFileStreamReader( 35 LocalFileStreamReader::LocalFileStreamReader(
51 base::TaskRunner* task_runner, 36 base::TaskRunner* task_runner,
52 const FilePath& file_path, 37 const FilePath& file_path,
53 int64 initial_offset, 38 int64 initial_offset,
54 const base::Time& expected_modification_time) 39 const base::Time& expected_modification_time)
55 : task_runner_(task_runner), 40 : task_runner_(task_runner),
56 file_path_(file_path), 41 file_path_(file_path),
57 initial_offset_(initial_offset), 42 initial_offset_(initial_offset),
58 expected_modification_time_(expected_modification_time), 43 expected_modification_time_(expected_modification_time),
59 has_pending_open_(false), 44 has_pending_open_(false),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 147
163 void LocalFileStreamReader::DidGetFileInfoForGetLength( 148 void LocalFileStreamReader::DidGetFileInfoForGetLength(
164 const net::Int64CompletionCallback& callback, 149 const net::Int64CompletionCallback& callback,
165 base::PlatformFileError error, 150 base::PlatformFileError error,
166 const base::PlatformFileInfo& file_info) { 151 const base::PlatformFileInfo& file_info) {
167 if (file_info.is_directory) { 152 if (file_info.is_directory) {
168 callback.Run(net::ERR_FILE_NOT_FOUND); 153 callback.Run(net::ERR_FILE_NOT_FOUND);
169 return; 154 return;
170 } 155 }
171 if (error != base::PLATFORM_FILE_OK) { 156 if (error != base::PLATFORM_FILE_OK) {
172 callback.Run(LocalFileStreamReader::PlatformFileErrorToNetError(error)); 157 callback.Run(net::PlatformFileErrorToNetError(error));
173 return; 158 return;
174 } 159 }
175 if (!VerifySnapshotTime(expected_modification_time_, file_info)) { 160 if (!VerifySnapshotTime(expected_modification_time_, file_info)) {
176 callback.Run(net::ERR_UPLOAD_FILE_CHANGED); 161 callback.Run(net::ERR_UPLOAD_FILE_CHANGED);
177 return; 162 return;
178 } 163 }
179 callback.Run(file_info.size); 164 callback.Run(file_info.size);
180 } 165 }
181 166
182 } // namespace webkit_blob 167 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/local_file_stream_reader.h ('k') | webkit/chromeos/fileapi/remote_file_stream_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698