| 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 "net/base/file_stream_context.h" | 5 #include "net/base/file_stream_context.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/profiler/scoped_profile.h" |
| 10 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
| 11 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 | 16 |
| 16 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
| 17 #include "base/android/content_uri_utils.h" | 18 #include "base/android/content_uri_utils.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 base::Bind(&Context::OnAsyncCompleted, | 143 base::Bind(&Context::OnAsyncCompleted, |
| 143 base::Unretained(this), | 144 base::Unretained(this), |
| 144 IntToInt64(callback))); | 145 IntToInt64(callback))); |
| 145 DCHECK(posted); | 146 DCHECK(posted); |
| 146 | 147 |
| 147 async_in_progress_ = true; | 148 async_in_progress_ = true; |
| 148 } | 149 } |
| 149 | 150 |
| 150 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( | 151 FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( |
| 151 const base::FilePath& path, int open_flags) { | 152 const base::FilePath& path, int open_flags) { |
| 153 // TODO(vadimt): Remove ScopedProfile below once crbug.com/423948 is fixed. |
| 154 tracked_objects::ScopedProfile tracking_profile( |
| 155 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 156 "423948 FileStream::Context::OpenFileImpl")); |
| 157 |
| 152 #if defined(OS_POSIX) | 158 #if defined(OS_POSIX) |
| 153 // Always use blocking IO. | 159 // Always use blocking IO. |
| 154 open_flags &= ~base::File::FLAG_ASYNC; | 160 open_flags &= ~base::File::FLAG_ASYNC; |
| 155 #endif | 161 #endif |
| 156 base::File file; | 162 base::File file; |
| 157 #if defined(OS_ANDROID) | 163 #if defined(OS_ANDROID) |
| 158 if (path.IsContentUri()) { | 164 if (path.IsContentUri()) { |
| 159 // Check that only Read flags are set. | 165 // Check that only Read flags are set. |
| 160 DCHECK_EQ(open_flags & ~base::File::FLAG_ASYNC, | 166 DCHECK_EQ(open_flags & ~base::File::FLAG_ASYNC, |
| 161 base::File::FLAG_OPEN | base::File::FLAG_READ); | 167 base::File::FLAG_OPEN | base::File::FLAG_READ); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 188 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { | 194 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { |
| 189 if (file_.Flush()) | 195 if (file_.Flush()) |
| 190 return IOResult(OK, 0); | 196 return IOResult(OK, 0); |
| 191 | 197 |
| 192 return IOResult::FromOSError(logging::GetLastSystemErrorCode()); | 198 return IOResult::FromOSError(logging::GetLastSystemErrorCode()); |
| 193 } | 199 } |
| 194 | 200 |
| 195 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, | 201 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, |
| 196 OpenResult open_result) { | 202 OpenResult open_result) { |
| 197 file_ = open_result.file.Pass(); | 203 file_ = open_result.file.Pass(); |
| 198 if (file_.IsValid() && !orphaned_) | 204 if (file_.IsValid() && !orphaned_) { |
| 205 // TODO(vadimt): Remove ScopedProfile below once crbug.com/423948 is fixed. |
| 206 tracked_objects::ScopedProfile tracking_profile( |
| 207 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 208 "423948 FileStream::Context::OnOpenCompleted")); |
| 209 |
| 199 OnFileOpened(); | 210 OnFileOpened(); |
| 211 } |
| 200 | 212 |
| 201 OnAsyncCompleted(IntToInt64(callback), open_result.error_code); | 213 OnAsyncCompleted(IntToInt64(callback), open_result.error_code); |
| 202 } | 214 } |
| 203 | 215 |
| 204 void FileStream::Context::CloseAndDelete() { | 216 void FileStream::Context::CloseAndDelete() { |
| 205 DCHECK(!async_in_progress_); | 217 DCHECK(!async_in_progress_); |
| 206 | 218 |
| 207 if (file_.IsValid()) { | 219 if (file_.IsValid()) { |
| 208 bool posted = task_runner_.get()->PostTask( | 220 bool posted = task_runner_.get()->PostTask( |
| 209 FROM_HERE, | 221 FROM_HERE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 227 // should be reset before Close() because it shouldn't run if any async | 239 // should be reset before Close() because it shouldn't run if any async |
| 228 // operation is in progress. | 240 // operation is in progress. |
| 229 async_in_progress_ = false; | 241 async_in_progress_ = false; |
| 230 if (orphaned_) | 242 if (orphaned_) |
| 231 CloseAndDelete(); | 243 CloseAndDelete(); |
| 232 else | 244 else |
| 233 callback.Run(result.result); | 245 callback.Run(result.result); |
| 234 } | 246 } |
| 235 | 247 |
| 236 } // namespace net | 248 } // namespace net |
| OLD | NEW |