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 "webkit/chromeos/fileapi/remote_file_stream_writer.h" | 5 #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" |
6 | 6 |
7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "webkit/blob/local_file_stream_reader.h" | 9 #include "webkit/blob/local_file_stream_reader.h" |
10 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" | 10 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" |
11 #include "webkit/fileapi/local_file_stream_writer.h" | 11 #include "webkit/fileapi/local_file_stream_writer.h" |
12 | 12 |
13 namespace { | |
14 | |
15 int PlatformFileErrorToNetError(base::PlatformFileError error) { | |
16 // TODO(kinuko): Move this static method to more convenient place. | |
17 return webkit_blob::LocalFileStreamReader::PlatformFileErrorToNetError(error); | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 namespace fileapi { | 13 namespace fileapi { |
23 | 14 |
24 RemoteFileStreamWriter::RemoteFileStreamWriter( | 15 RemoteFileStreamWriter::RemoteFileStreamWriter( |
25 const scoped_refptr<RemoteFileSystemProxyInterface>& remote_filesystem, | 16 const scoped_refptr<RemoteFileSystemProxyInterface>& remote_filesystem, |
26 const FileSystemURL& url, | 17 const FileSystemURL& url, |
27 int64 offset) | 18 int64 offset) |
28 : remote_filesystem_(remote_filesystem), | 19 : remote_filesystem_(remote_filesystem), |
29 url_(url), | 20 url_(url), |
30 initial_offset_(offset), | 21 initial_offset_(offset), |
31 has_pending_create_snapshot_(false), | 22 has_pending_create_snapshot_(false), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 base::PlatformFileError open_result, | 57 base::PlatformFileError open_result, |
67 const FilePath& local_path, | 58 const FilePath& local_path, |
68 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 59 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
69 has_pending_create_snapshot_ = false; | 60 has_pending_create_snapshot_ = false; |
70 if (!pending_cancel_callback_.is_null()) { | 61 if (!pending_cancel_callback_.is_null()) { |
71 InvokePendingCancelCallback(net::OK); | 62 InvokePendingCancelCallback(net::OK); |
72 return; | 63 return; |
73 } | 64 } |
74 | 65 |
75 if (open_result != base::PLATFORM_FILE_OK) { | 66 if (open_result != base::PLATFORM_FILE_OK) { |
76 callback.Run(PlatformFileErrorToNetError(open_result)); | 67 callback.Run(net::PlatformFileErrorToNetError(open_result)); |
77 return; | 68 return; |
78 } | 69 } |
79 | 70 |
80 // Hold the reference to the file. Releasing the reference notifies the file | 71 // Hold the reference to the file. Releasing the reference notifies the file |
81 // system about to close file. | 72 // system about to close file. |
82 file_ref_ = file_ref; | 73 file_ref_ = file_ref; |
83 | 74 |
84 DCHECK(!local_file_writer_.get()); | 75 DCHECK(!local_file_writer_.get()); |
85 local_file_writer_.reset(new fileapi::LocalFileStreamWriter(local_path, | 76 local_file_writer_.reset(new fileapi::LocalFileStreamWriter(local_path, |
86 initial_offset_)); | 77 initial_offset_)); |
(...skipping 25 matching lines...) Expand all Loading... |
112 return net::ERR_UNEXPECTED; | 103 return net::ERR_UNEXPECTED; |
113 } | 104 } |
114 | 105 |
115 void RemoteFileStreamWriter::InvokePendingCancelCallback(int result) { | 106 void RemoteFileStreamWriter::InvokePendingCancelCallback(int result) { |
116 net::CompletionCallback callback = pending_cancel_callback_; | 107 net::CompletionCallback callback = pending_cancel_callback_; |
117 pending_cancel_callback_.Reset(); | 108 pending_cancel_callback_.Reset(); |
118 callback.Run(result); | 109 callback.Run(result); |
119 } | 110 } |
120 | 111 |
121 } // namespace gdata | 112 } // namespace gdata |
OLD | NEW |