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

Side by Side Diff: trunk/src/net/base/file_stream_context.cc

Issue 65043023: Revert 235752 "Fix chrome upload with content uri" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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 "net/base/file_stream_context.h" 5 #include "net/base/file_stream_context.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 #include "net/base/file_stream_net_log_parameters.h" 11 #include "net/base/file_stream_net_log_parameters.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 13
14 #if defined(OS_ANDROID)
15 #include "base/android/content_uri_utils.h"
16 #endif
17
18 namespace { 14 namespace {
19 15
20 void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) { 16 void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) {
21 callback.Run(static_cast<int>(result)); 17 callback.Run(static_cast<int>(result));
22 } 18 }
23 19
24 } 20 }
25 21
26 namespace net { 22 namespace net {
27 23
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 186 }
191 187
192 void FileStream::Context::BeginOpenEvent(const base::FilePath& path) { 188 void FileStream::Context::BeginOpenEvent(const base::FilePath& path) {
193 std::string file_name = path.AsUTF8Unsafe(); 189 std::string file_name = path.AsUTF8Unsafe();
194 bound_net_log_.BeginEvent(NetLog::TYPE_FILE_STREAM_OPEN, 190 bound_net_log_.BeginEvent(NetLog::TYPE_FILE_STREAM_OPEN,
195 NetLog::StringCallback("file_name", &file_name)); 191 NetLog::StringCallback("file_name", &file_name));
196 } 192 }
197 193
198 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( 194 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl(
199 const base::FilePath& path, int open_flags) { 195 const base::FilePath& path, int open_flags) {
200 base::PlatformFile file; 196 // FileStream::Context actually closes the file asynchronously, independently
201 #if defined(OS_ANDROID) 197 // from FileStream's destructor. It can cause problems for users wanting to
202 if (path.IsContentUri()) { 198 // delete the file right after FileStream deletion. Thus we are always
203 // Check that only Read flags are set. 199 // adding SHARE_DELETE flag to accommodate such use case.
204 DCHECK_EQ(open_flags & ~base::PLATFORM_FILE_ASYNC, 200 open_flags |= base::PLATFORM_FILE_SHARE_DELETE;
205 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); 201 base::PlatformFile file =
206 file = base::OpenContentUriForRead(path); 202 base::CreatePlatformFile(path, open_flags, NULL, NULL);
207 } else {
208 #endif // defined(OS_ANDROID)
209 // FileStream::Context actually closes the file asynchronously,
210 // independently from FileStream's destructor. It can cause problems for
211 // users wanting to delete the file right after FileStream deletion. Thus
212 // we are always adding SHARE_DELETE flag to accommodate such use case.
213 open_flags |= base::PLATFORM_FILE_SHARE_DELETE;
214 file = base::CreatePlatformFile(path, open_flags, NULL, NULL);
215 #if defined(OS_ANDROID)
216 }
217 #endif // defined(OS_ANDROID)
218 if (file == base::kInvalidPlatformFileValue) 203 if (file == base::kInvalidPlatformFileValue)
219 return OpenResult(file, IOResult::FromOSError(GetLastErrno())); 204 return OpenResult(file, IOResult::FromOSError(GetLastErrno()));
220 205
221 return OpenResult(file, IOResult(OK, 0)); 206 return OpenResult(file, IOResult(OK, 0));
222 } 207 }
223 208
224 void FileStream::Context::ProcessOpenError(const IOResult& error_code) { 209 void FileStream::Context::ProcessOpenError(const IOResult& error_code) {
225 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); 210 bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN);
226 RecordError(error_code, FILE_ERROR_SOURCE_OPEN); 211 RecordError(error_code, FILE_ERROR_SOURCE_OPEN);
227 } 212 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // operation is in progress. 261 // operation is in progress.
277 async_in_progress_ = false; 262 async_in_progress_ = false;
278 if (orphaned_) 263 if (orphaned_)
279 CloseAndDelete(); 264 CloseAndDelete();
280 else 265 else
281 callback.Run(result); 266 callback.Run(result);
282 } 267 }
283 268
284 } // namespace net 269 } // namespace net
285 270
OLDNEW
« no previous file with comments | « trunk/src/content/browser/child_process_security_policy_impl.cc ('k') | trunk/src/net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698