Disable signin-to-Chrome when using Guest profile.
[chromium-blink-merge.git] / content / child / webfileutilities_impl.cc
blob9c055966fd691a43eb09f70246ff75dbcf0d02c0
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/webfileutilities_impl.h"
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "content/child/blink_glue.h"
11 #include "net/base/file_stream.h"
12 #include "net/base/net_util.h"
13 #include "third_party/WebKit/public/platform/WebFileInfo.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/platform/WebURL.h"
17 using blink::WebString;
19 namespace content {
21 WebFileUtilitiesImpl::WebFileUtilitiesImpl()
22 : sandbox_enabled_(true) {
25 WebFileUtilitiesImpl::~WebFileUtilitiesImpl() {
28 bool WebFileUtilitiesImpl::getFileInfo(const WebString& path,
29 blink::WebFileInfo& web_file_info) {
30 if (sandbox_enabled_) {
31 NOTREACHED();
32 return false;
34 // TODO(rvargas): convert this code to use base::File::Info.
35 base::File::Info file_info;
36 if (!base::GetFileInfo(base::FilePath::FromUTF16Unsafe(path),
37 reinterpret_cast<base::File::Info*>(&file_info)))
38 return false;
40 FileInfoToWebFileInfo(file_info, &web_file_info);
41 web_file_info.platformPath = path;
42 return true;
45 WebString WebFileUtilitiesImpl::directoryName(const WebString& path) {
46 return base::FilePath::FromUTF16Unsafe(path).DirName().AsUTF16Unsafe();
49 WebString WebFileUtilitiesImpl::baseName(const WebString& path) {
50 return base::FilePath::FromUTF16Unsafe(path).BaseName().AsUTF16Unsafe();
53 blink::WebURL WebFileUtilitiesImpl::filePathToURL(const WebString& path) {
54 return net::FilePathToFileURL(base::FilePath::FromUTF16Unsafe(path));
57 base::PlatformFile WebFileUtilitiesImpl::openFile(const WebString& path,
58 int mode) {
59 if (sandbox_enabled_) {
60 NOTREACHED();
61 return base::kInvalidPlatformFileValue;
63 // mode==0 (read-only) is the only supported mode.
64 // TODO(kinuko): Remove this parameter.
65 DCHECK_EQ(0, mode);
66 return base::CreatePlatformFile(
67 base::FilePath::FromUTF16Unsafe(path),
68 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
69 NULL, NULL);
72 void WebFileUtilitiesImpl::closeFile(base::PlatformFile& handle) {
73 if (handle == base::kInvalidPlatformFileValue)
74 return;
75 if (base::ClosePlatformFile(handle))
76 handle = base::kInvalidPlatformFileValue;
79 int WebFileUtilitiesImpl::readFromFile(base::PlatformFile handle,
80 char* data,
81 int length) {
82 if (handle == base::kInvalidPlatformFileValue || !data || length <= 0)
83 return -1;
84 return base::ReadPlatformFileCurPosNoBestEffort(handle, data, length);
87 } // namespace content