IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_external_file_ref_backend.cc
blob4cea3d897c493adcfd6f1a506d2561b5f429d4a8
1 // Copyright 2013 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/browser/renderer_host/pepper/pepper_external_file_ref_backend.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util_proxy.h"
9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/c/pp_time.h"
13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/shared_impl/file_type_conversion.h"
16 #include "ppapi/shared_impl/time_conversion.h"
18 namespace content {
20 PepperExternalFileRefBackend::PepperExternalFileRefBackend(
21 ppapi::host::PpapiHost* host,
22 int render_process_id,
23 const base::FilePath& path) : host_(host),
24 path_(path),
25 render_process_id_(render_process_id),
26 weak_factory_(this) {
27 task_runner_ =
28 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
31 PepperExternalFileRefBackend::~PepperExternalFileRefBackend() {
34 int32_t PepperExternalFileRefBackend::MakeDirectory(
35 ppapi::host::ReplyMessageContext reply_context,
36 int32_t make_directory_flags) {
37 // This operation isn't supported for external filesystems.
38 return PP_ERROR_NOACCESS;
41 int32_t PepperExternalFileRefBackend::Touch(
42 ppapi::host::ReplyMessageContext reply_context,
43 PP_Time last_access_time,
44 PP_Time last_modified_time) {
45 IPC::Message reply_msg = PpapiPluginMsg_FileRef_TouchReply();
46 base::FileUtilProxy::Touch(
47 task_runner_.get(),
48 path_,
49 ppapi::PPTimeToTime(last_access_time),
50 ppapi::PPTimeToTime(last_modified_time),
51 base::Bind(&PepperExternalFileRefBackend::DidFinish,
52 weak_factory_.GetWeakPtr(),
53 reply_context,
54 reply_msg));
55 return PP_OK_COMPLETIONPENDING;
58 int32_t PepperExternalFileRefBackend::Delete(
59 ppapi::host::ReplyMessageContext reply_context) {
60 // This operation isn't supported for external filesystems.
61 return PP_ERROR_NOACCESS;
64 int32_t PepperExternalFileRefBackend::Rename(
65 ppapi::host::ReplyMessageContext reply_context,
66 PepperFileRefHost* new_file_ref) {
67 // This operation isn't supported for external filesystems.
68 return PP_ERROR_NOACCESS;
71 int32_t PepperExternalFileRefBackend::Query(
72 ppapi::host::ReplyMessageContext reply_context) {
73 bool ok = base::FileUtilProxy::GetFileInfo(
74 task_runner_.get(),
75 path_,
76 base::Bind(&PepperExternalFileRefBackend::GetMetadataComplete,
77 weak_factory_.GetWeakPtr(),
78 reply_context));
79 DCHECK(ok);
80 return PP_OK_COMPLETIONPENDING;
83 int32_t PepperExternalFileRefBackend::ReadDirectoryEntries(
84 ppapi::host::ReplyMessageContext context) {
85 // This operation isn't supported for external filesystems.
86 return PP_ERROR_NOACCESS;
89 int32_t PepperExternalFileRefBackend::GetAbsolutePath(
90 ppapi::host::ReplyMessageContext reply_context) {
91 host_->SendReply(reply_context,
92 PpapiPluginMsg_FileRef_GetAbsolutePathReply(path_.AsUTF8Unsafe()));
94 // Use PP_OK_COMPLETIONPENDING instead of PP_OK since we've already sent our
95 // reply above.
96 return PP_OK_COMPLETIONPENDING;
99 fileapi::FileSystemURL PepperExternalFileRefBackend::GetFileSystemURL() const {
100 return fileapi::FileSystemURL();
103 base::FilePath PepperExternalFileRefBackend::GetExternalFilePath() const {
104 return path_;
107 int32_t PepperExternalFileRefBackend::CanRead() const {
108 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
109 CanReadFile(render_process_id_, path_)) {
110 return PP_ERROR_NOACCESS;
112 return PP_OK;
115 int32_t PepperExternalFileRefBackend::CanWrite() const {
116 // Platform files have coarse-grained grants in ChildProcessSecurityPolicy.
117 return CanReadWrite();
120 int32_t PepperExternalFileRefBackend::CanCreate() const {
121 // Platform files have coarse-grained grants in ChildProcessSecurityPolicy.
122 return CanReadWrite();
125 int32_t PepperExternalFileRefBackend::CanReadWrite() const {
126 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
127 CanCreateReadWriteFile(render_process_id_, path_)) {
128 return PP_ERROR_NOACCESS;
130 return PP_OK;
133 void PepperExternalFileRefBackend::DidFinish(
134 ppapi::host::ReplyMessageContext reply_context,
135 const IPC::Message& msg,
136 base::PlatformFileError error) {
137 reply_context.params.set_result(ppapi::PlatformFileErrorToPepperError(error));
138 host_->SendReply(reply_context, msg);
141 void PepperExternalFileRefBackend::GetMetadataComplete(
142 ppapi::host::ReplyMessageContext reply_context,
143 const base::PlatformFileError error,
144 const base::PlatformFileInfo& file_info) {
145 reply_context.params.set_result(ppapi::PlatformFileErrorToPepperError(error));
147 PP_FileInfo pp_file_info;
148 if (error == base::PLATFORM_FILE_OK) {
149 ppapi::PlatformFileInfoToPepperFileInfo(
150 file_info, PP_FILESYSTEMTYPE_EXTERNAL, &pp_file_info);
151 } else {
152 memset(&pp_file_info, 0, sizeof(pp_file_info));
155 host_->SendReply(reply_context,
156 PpapiPluginMsg_FileRef_QueryReply(pp_file_info));
159 } // namespace content