OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/base/file_stream_context.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/bind.h" | |
9 #include "base/bind_helpers.h" | |
10 #include "base/callback.h" | |
11 #include "base/location.h" | |
12 #include "base/platform_file.h" | |
13 #include "base/task_runner_util.h" | |
14 #include "net/android/content_uri_utils.h" | |
15 #include "net/base/net_errors.h" | |
16 | |
17 namespace net { | |
18 | |
19 void FileStream::Context::OpenContentUrlAsync( | |
20 const base::FilePath& path, | |
21 int open_flags, | |
22 const CompletionCallback& callback) { | |
23 DCHECK(!async_in_progress_); | |
24 const bool posted = base::PostTaskAndReplyWithResult( | |
25 task_runner_.get(), | |
26 FROM_HERE, | |
27 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
| |
28 path, open_flags), | |
29 base::Bind(&Context::OnOpenCompleted, base::Unretained(this), callback)); | |
30 DCHECK(posted); | |
31 | |
32 async_in_progress_ = true; | |
33 } | |
34 | |
35 int FileStream::Context::OpenContentUrlSync( | |
36 const base::FilePath& path, int open_flags) { | |
37 DCHECK(!async_in_progress_); | |
38 | |
39 OpenResult result = OpenContentUrlImpl(path, open_flags); | |
40 file_ = result.file; | |
41 if (file_ == base::kInvalidPlatformFileValue) { | |
42 ProcessOpenError(result.error_code); | |
43 } else { | |
44 if (open_flags & base::PLATFORM_FILE_ASYNC) | |
45 OnAsyncFileOpened(); | |
46 } | |
47 return result.error_code.result; | |
48 } | |
49 | |
50 FileStream::Context::OpenResult FileStream::Context::OpenContentUrlImpl( | |
51 const base::FilePath& path, int open_flags) { | |
52 // Check that only Read flags are set. | |
53 DCHECK_EQ(open_flags & ~base::PLATFORM_FILE_ASYNC, | |
54 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); | |
55 base::PlatformFile file = OpenContentUrlForRead(path); | |
56 if (file == base::kInvalidPlatformFileValue) | |
57 return OpenResult(file, IOResult::FromOSError(GetLastErrno())); | |
58 | |
59 return OpenResult(file, IOResult(OK, 0)); | |
60 } | |
61 | |
62 } // namespace net | |
OLD | NEW |