blob: fbfd49b489b3723a25e76eafca9a8331688cf1ab [file] [log] [blame]
[email protected]6060b10c2012-03-31 04:24:211// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]126f4fb2011-06-27 20:18:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/cpp/file_ref.h"
6
7#include "ppapi/c/pp_errors.h"
8#include "ppapi/cpp/completion_callback.h"
9#include "ppapi/cpp/file_system.h"
10#include "ppapi/cpp/module_impl.h"
11
12
13namespace pp {
14
15namespace {
16
[email protected]6060b10c2012-03-31 04:24:2117template <> const char* interface_name<PPB_FileRef_1_0>() {
18 return PPB_FILEREF_INTERFACE_1_0;
[email protected]126f4fb2011-06-27 20:18:5919}
20
21} // namespace
22
23FileRef::FileRef(PP_Resource resource) : Resource(resource) {
24}
25
[email protected]09af0f72012-02-27 20:23:1926FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) {
[email protected]126f4fb2011-06-27 20:18:5927}
28
29FileRef::FileRef(const FileSystem& file_system,
30 const char* path) {
[email protected]6060b10c2012-03-31 04:24:2131 if (!has_interface<PPB_FileRef_1_0>())
[email protected]126f4fb2011-06-27 20:18:5932 return;
[email protected]6060b10c2012-03-31 04:24:2133 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create(
[email protected]126f4fb2011-06-27 20:18:5934 file_system.pp_resource(), path));
35}
36
37FileRef::FileRef(const FileRef& other)
38 : Resource(other) {
39}
40
41PP_FileSystemType FileRef::GetFileSystemType() const {
[email protected]6060b10c2012-03-31 04:24:2142 if (!has_interface<PPB_FileRef_1_0>())
[email protected]126f4fb2011-06-27 20:18:5943 return PP_FILESYSTEMTYPE_EXTERNAL;
[email protected]6060b10c2012-03-31 04:24:2144 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource());
[email protected]126f4fb2011-06-27 20:18:5945}
46
47Var FileRef::GetName() const {
[email protected]6060b10c2012-03-31 04:24:2148 if (!has_interface<PPB_FileRef_1_0>())
[email protected]126f4fb2011-06-27 20:18:5949 return Var();
[email protected]6060b10c2012-03-31 04:24:2150 return Var(PASS_REF,
51 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource()));
[email protected]126f4fb2011-06-27 20:18:5952}
53
54Var FileRef::GetPath() const {
[email protected]6060b10c2012-03-31 04:24:2155 if (!has_interface<PPB_FileRef_1_0>())
[email protected]126f4fb2011-06-27 20:18:5956 return Var();
[email protected]6060b10c2012-03-31 04:24:2157 return Var(PASS_REF,
58 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource()));
[email protected]126f4fb2011-06-27 20:18:5959}
60
61FileRef FileRef::GetParent() const {
[email protected]6060b10c2012-03-31 04:24:2162 if (!has_interface<PPB_FileRef_1_0>())
[email protected]126f4fb2011-06-27 20:18:5963 return FileRef();
[email protected]09af0f72012-02-27 20:23:1964 return FileRef(PASS_REF,
[email protected]6060b10c2012-03-31 04:24:2165 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource()));
[email protected]126f4fb2011-06-27 20:18:5966}
67
68int32_t FileRef::MakeDirectory(const CompletionCallback& cc) {
[email protected]6060b10c2012-03-31 04:24:2169 if (!has_interface<PPB_FileRef_1_0>())
[email protected]917e86a2011-06-30 21:42:3770 return cc.MayForce(PP_ERROR_NOINTERFACE);
[email protected]6060b10c2012-03-31 04:24:2171 return get_interface<PPB_FileRef_1_0>()->MakeDirectory(
[email protected]126f4fb2011-06-27 20:18:5972 pp_resource(),
73 PP_FALSE, // make_ancestors
74 cc.pp_completion_callback());
75}
76
77int32_t FileRef::MakeDirectoryIncludingAncestors(
78 const CompletionCallback& cc) {
[email protected]6060b10c2012-03-31 04:24:2179 if (!has_interface<PPB_FileRef_1_0>())
[email protected]917e86a2011-06-30 21:42:3780 return cc.MayForce(PP_ERROR_NOINTERFACE);
[email protected]6060b10c2012-03-31 04:24:2181 return get_interface<PPB_FileRef_1_0>()->MakeDirectory(
[email protected]126f4fb2011-06-27 20:18:5982 pp_resource(),
83 PP_TRUE, // make_ancestors
84 cc.pp_completion_callback());
85}
86
87int32_t FileRef::Touch(PP_Time last_access_time,
88 PP_Time last_modified_time,
89 const CompletionCallback& cc) {
[email protected]6060b10c2012-03-31 04:24:2190 if (!has_interface<PPB_FileRef_1_0>())
[email protected]917e86a2011-06-30 21:42:3791 return cc.MayForce(PP_ERROR_NOINTERFACE);
[email protected]6060b10c2012-03-31 04:24:2192 return get_interface<PPB_FileRef_1_0>()->Touch(
[email protected]126f4fb2011-06-27 20:18:5993 pp_resource(), last_access_time, last_modified_time,
94 cc.pp_completion_callback());
95}
96
97int32_t FileRef::Delete(const CompletionCallback& cc) {
[email protected]6060b10c2012-03-31 04:24:2198 if (!has_interface<PPB_FileRef_1_0>())
[email protected]917e86a2011-06-30 21:42:3799 return cc.MayForce(PP_ERROR_NOINTERFACE);
[email protected]6060b10c2012-03-31 04:24:21100 return get_interface<PPB_FileRef_1_0>()->Delete(
[email protected]126f4fb2011-06-27 20:18:59101 pp_resource(), cc.pp_completion_callback());
102}
103
104int32_t FileRef::Rename(const FileRef& new_file_ref,
105 const CompletionCallback& cc) {
[email protected]6060b10c2012-03-31 04:24:21106 if (!has_interface<PPB_FileRef_1_0>())
[email protected]917e86a2011-06-30 21:42:37107 return cc.MayForce(PP_ERROR_NOINTERFACE);
[email protected]6060b10c2012-03-31 04:24:21108 return get_interface<PPB_FileRef_1_0>()->Rename(
[email protected]126f4fb2011-06-27 20:18:59109 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
110}
111
112} // namespace pp