Instrumenting Predictor to locate the source of jankiness.
[chromium-blink-merge.git] / ppapi / cpp / file_ref.cc
blobf9294a7e02c9dd99453cc204630f9b6eb3a6ff24
1 // Copyright (c) 2012 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 "ppapi/cpp/file_ref.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/directory_entry.h"
11 #include "ppapi/cpp/file_system.h"
12 #include "ppapi/cpp/module_impl.h"
14 namespace pp {
16 namespace {
18 template <> const char* interface_name<PPB_FileRef_1_0>() {
19 return PPB_FILEREF_INTERFACE_1_0;
22 template <> const char* interface_name<PPB_FileRef_1_1>() {
23 return PPB_FILEREF_INTERFACE_1_1;
26 template <> const char* interface_name<PPB_FileRef_1_2>() {
27 return PPB_FILEREF_INTERFACE_1_2;
30 } // namespace
32 FileRef::FileRef(PP_Resource resource) : Resource(resource) {
35 FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) {
38 FileRef::FileRef(const FileSystem& file_system,
39 const char* path) {
40 if (has_interface<PPB_FileRef_1_2>()) {
41 PassRefFromConstructor(get_interface<PPB_FileRef_1_2>()->Create(
42 file_system.pp_resource(), path));
43 } else if (has_interface<PPB_FileRef_1_1>()) {
44 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create(
45 file_system.pp_resource(), path));
46 } else if (has_interface<PPB_FileRef_1_0>()) {
47 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create(
48 file_system.pp_resource(), path));
52 FileRef::FileRef(const FileRef& other)
53 : Resource(other) {
56 PP_FileSystemType FileRef::GetFileSystemType() const {
57 if (has_interface<PPB_FileRef_1_2>())
58 return get_interface<PPB_FileRef_1_2>()->GetFileSystemType(pp_resource());
59 if (has_interface<PPB_FileRef_1_1>())
60 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource());
61 if (has_interface<PPB_FileRef_1_0>())
62 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource());
63 return PP_FILESYSTEMTYPE_EXTERNAL;
66 Var FileRef::GetName() const {
67 if (has_interface<PPB_FileRef_1_2>()) {
68 return Var(PASS_REF,
69 get_interface<PPB_FileRef_1_2>()->GetName(pp_resource()));
71 if (has_interface<PPB_FileRef_1_1>()) {
72 return Var(PASS_REF,
73 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource()));
75 if (has_interface<PPB_FileRef_1_0>()) {
76 return Var(PASS_REF,
77 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource()));
79 return Var();
82 Var FileRef::GetPath() const {
83 if (has_interface<PPB_FileRef_1_2>()) {
84 return Var(PASS_REF,
85 get_interface<PPB_FileRef_1_2>()->GetPath(pp_resource()));
87 if (has_interface<PPB_FileRef_1_1>()) {
88 return Var(PASS_REF,
89 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource()));
91 if (has_interface<PPB_FileRef_1_0>()) {
92 return Var(PASS_REF,
93 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource()));
95 return Var();
98 FileRef FileRef::GetParent() const {
99 if (has_interface<PPB_FileRef_1_2>()) {
100 return FileRef(PASS_REF,
101 get_interface<PPB_FileRef_1_2>()->GetParent(pp_resource()));
103 if (has_interface<PPB_FileRef_1_1>()) {
104 return FileRef(PASS_REF,
105 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource()));
107 if (has_interface<PPB_FileRef_1_0>()) {
108 return FileRef(PASS_REF,
109 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource()));
111 return FileRef();
114 int32_t FileRef::MakeDirectory(int32_t make_directory_flags,
115 const CompletionCallback& cc) {
116 if (has_interface<PPB_FileRef_1_2>()) {
117 return get_interface<PPB_FileRef_1_2>()->MakeDirectory(
118 pp_resource(),
119 make_directory_flags,
120 cc.pp_completion_callback());
122 if (has_interface<PPB_FileRef_1_1>()) {
123 if (make_directory_flags & ~PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS)
124 return cc.MayForce(PP_ERROR_NOTSUPPORTED);
125 return get_interface<PPB_FileRef_1_1>()->MakeDirectory(
126 pp_resource(),
127 PP_FromBool(make_directory_flags & PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS),
128 cc.pp_completion_callback());
130 if (has_interface<PPB_FileRef_1_0>()) {
131 if (make_directory_flags & ~PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS)
132 return cc.MayForce(PP_ERROR_NOTSUPPORTED);
133 return get_interface<PPB_FileRef_1_0>()->MakeDirectory(
134 pp_resource(),
135 PP_FromBool(make_directory_flags & PP_MAKEDIRECTORYFLAG_WITH_ANCESTORS),
136 cc.pp_completion_callback());
138 return cc.MayForce(PP_ERROR_NOINTERFACE);
141 int32_t FileRef::Touch(PP_Time last_access_time,
142 PP_Time last_modified_time,
143 const CompletionCallback& cc) {
144 if (has_interface<PPB_FileRef_1_2>()) {
145 return get_interface<PPB_FileRef_1_2>()->Touch(
146 pp_resource(), last_access_time, last_modified_time,
147 cc.pp_completion_callback());
149 if (has_interface<PPB_FileRef_1_1>()) {
150 return get_interface<PPB_FileRef_1_1>()->Touch(
151 pp_resource(), last_access_time, last_modified_time,
152 cc.pp_completion_callback());
154 if (has_interface<PPB_FileRef_1_0>()) {
155 return get_interface<PPB_FileRef_1_0>()->Touch(
156 pp_resource(), last_access_time, last_modified_time,
157 cc.pp_completion_callback());
159 return cc.MayForce(PP_ERROR_NOINTERFACE);
162 int32_t FileRef::Delete(const CompletionCallback& cc) {
163 if (has_interface<PPB_FileRef_1_2>()) {
164 return get_interface<PPB_FileRef_1_2>()->Delete(
165 pp_resource(), cc.pp_completion_callback());
167 if (has_interface<PPB_FileRef_1_1>()) {
168 return get_interface<PPB_FileRef_1_1>()->Delete(
169 pp_resource(), cc.pp_completion_callback());
171 if (has_interface<PPB_FileRef_1_0>()) {
172 return get_interface<PPB_FileRef_1_0>()->Delete(
173 pp_resource(), cc.pp_completion_callback());
175 return cc.MayForce(PP_ERROR_NOINTERFACE);
178 int32_t FileRef::Rename(const FileRef& new_file_ref,
179 const CompletionCallback& cc) {
180 if (has_interface<PPB_FileRef_1_2>()) {
181 return get_interface<PPB_FileRef_1_2>()->Rename(
182 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
184 if (has_interface<PPB_FileRef_1_1>()) {
185 return get_interface<PPB_FileRef_1_1>()->Rename(
186 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
188 if (has_interface<PPB_FileRef_1_0>()) {
189 return get_interface<PPB_FileRef_1_0>()->Rename(
190 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
192 return cc.MayForce(PP_ERROR_NOINTERFACE);
195 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) {
196 if (has_interface<PPB_FileRef_1_2>()) {
197 return get_interface<PPB_FileRef_1_2>()->Query(
198 pp_resource(), cc.output(), cc.pp_completion_callback());
200 if (has_interface<PPB_FileRef_1_1>()) {
201 return get_interface<PPB_FileRef_1_1>()->Query(
202 pp_resource(), cc.output(), cc.pp_completion_callback());
204 return cc.MayForce(PP_ERROR_NOINTERFACE);
207 int32_t FileRef::ReadDirectoryEntries(
208 const CompletionCallbackWithOutput<std::vector<DirectoryEntry> >&
209 callback) {
210 if (has_interface<PPB_FileRef_1_2>()) {
211 return get_interface<PPB_FileRef_1_2>()->ReadDirectoryEntries(
212 pp_resource(), callback.output(), callback.pp_completion_callback());
214 if (has_interface<PPB_FileRef_1_1>()) {
215 return get_interface<PPB_FileRef_1_1>()->ReadDirectoryEntries(
216 pp_resource(), callback.output(), callback.pp_completion_callback());
218 return callback.MayForce(PP_ERROR_NOINTERFACE);
221 } // namespace pp