| 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..1dd7cc36301a205dd8bd3fd65a95aa0d1a538cb0
|
| --- /dev/null
|
| +++ b/net/base/file_stream_context_android.cc
|
| @@ -0,0 +1,62 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// 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 GURL& content_url,
|
| + 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),
|
| + content_url, open_flags),
|
| + base::Bind(&Context::OnOpenCompleted, base::Unretained(this), callback));
|
| + DCHECK(posted);
|
| +
|
| + async_in_progress_ = true;
|
| +}
|
| +
|
| +int FileStream::Context::OpenContentUrlSync(
|
| + const GURL& content_url, int open_flags) {
|
| + DCHECK(!async_in_progress_);
|
| +
|
| + OpenResult result = OpenContentUrlImpl(content_url, 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 GURL& content_url, 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(content_url);
|
| + if (file == base::kInvalidPlatformFileValue)
|
| + return OpenResult(file, IOResult::FromOSError(GetLastErrno()));
|
| +
|
| + return OpenResult(file, IOResult(OK, 0));
|
| +}
|
| +
|
| +} // namespace net
|
|
|