Index: net/base/file_stream_context_android.cc |
diff --git a/net/base/file_stream_context_android.cc b/net/base/file_stream_context_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..69884aced40d5454461ca2e4dc1c74d67d00f318 |
--- /dev/null |
+++ b/net/base/file_stream_context_android.cc |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
mmenke
2013/10/31 15:07:06
file_stream_context.cc is small enough that I thin
qinmin
2013/11/05 01:41:31
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/base/file_stream_context.h" |
+ |
+#include "base/basictypes.h" |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/callback.h" |
+#include "base/location.h" |
+#include "base/platform_file.h" |
+#include "base/task_runner_util.h" |
+#include "net/android/content_uri_utils.h" |
+#include "net/base/net_errors.h" |
+ |
+namespace net { |
+ |
+void FileStream::Context::OpenContentUrlAsync( |
+ const base::FilePath& path, |
+ int open_flags, |
+ const CompletionCallback& callback) { |
+ DCHECK(!async_in_progress_); |
+ const bool posted = base::PostTaskAndReplyWithResult( |
+ task_runner_.get(), |
+ FROM_HERE, |
+ base::Bind(&Context::OpenContentUrlImpl, base::Unretained(this), |
joth
2013/10/31 06:42:39
the unretained is slightly scary but I see file_st
mmenke
2013/10/31 15:07:06
The FileStreamContext basically owns itself, and w
|
+ path, open_flags), |
+ base::Bind(&Context::OnOpenCompleted, base::Unretained(this), callback)); |
+ DCHECK(posted); |
+ |
+ async_in_progress_ = true; |
+} |
+ |
+int FileStream::Context::OpenContentUrlSync( |
+ const base::FilePath& path, int open_flags) { |
+ DCHECK(!async_in_progress_); |
+ |
+ OpenResult result = OpenContentUrlImpl(path, open_flags); |
+ file_ = result.file; |
+ if (file_ == base::kInvalidPlatformFileValue) { |
+ ProcessOpenError(result.error_code); |
+ } else { |
+ if (open_flags & base::PLATFORM_FILE_ASYNC) |
+ OnAsyncFileOpened(); |
+ } |
+ return result.error_code.result; |
+} |
+ |
+FileStream::Context::OpenResult FileStream::Context::OpenContentUrlImpl( |
+ const base::FilePath& path, int open_flags) { |
+ // Check that only Read flags are set. |
+ DCHECK_EQ(open_flags & ~base::PLATFORM_FILE_ASYNC, |
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
+ base::PlatformFile file = OpenContentUrlForRead(path); |
+ if (file == base::kInvalidPlatformFileValue) |
+ return OpenResult(file, IOResult::FromOSError(GetLastErrno())); |
+ |
+ return OpenResult(file, IOResult(OK, 0)); |
+} |
+ |
+} // namespace net |