Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: ppapi/cpp/file_ref.cc

Issue 12817009: Add Query() support to FileRef (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't leak file handles, fix nits Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/file_ref.h" 5 #include "ppapi/cpp/file_ref.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/completion_callback.h" 8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/cpp/file_system.h" 9 #include "ppapi/cpp/file_system.h"
10 #include "ppapi/cpp/module_impl.h" 10 #include "ppapi/cpp/module_impl.h"
11 11
12 12
13 namespace pp { 13 namespace pp {
14 14
15 namespace { 15 namespace {
16 16
17 template <> const char* interface_name<PPB_FileRef_1_0>() { 17 template <> const char* interface_name<PPB_FileRef_1_0>() {
18 return PPB_FILEREF_INTERFACE_1_0; 18 return PPB_FILEREF_INTERFACE_1_0;
19 } 19 }
20 20
21 template <> const char* interface_name<PPB_FileRef_1_1>() {
22 return PPB_FILEREF_INTERFACE_1_1;
23 }
24
21 } // namespace 25 } // namespace
22 26
23 FileRef::FileRef(PP_Resource resource) : Resource(resource) { 27 FileRef::FileRef(PP_Resource resource) : Resource(resource) {
24 } 28 }
25 29
26 FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { 30 FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) {
27 } 31 }
28 32
29 FileRef::FileRef(const FileSystem& file_system, 33 FileRef::FileRef(const FileSystem& file_system,
30 const char* path) { 34 const char* path) {
31 if (!has_interface<PPB_FileRef_1_0>()) 35 if (has_interface<PPB_FileRef_1_1>()) {
32 return; 36 PassRefFromConstructor(get_interface<PPB_FileRef_1_1>()->Create(
33 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( 37 file_system.pp_resource(), path));
34 file_system.pp_resource(), path)); 38 } else if (has_interface<PPB_FileRef_1_0>()) {
dmichael (off chromium) 2013/03/27 20:20:06 Wow, this is ugly. yzshen: I think we've talked ab
yzshen1 2013/03/27 21:28:41 It was in the thread "Provide a way to disable Nag
39 PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create(
40 file_system.pp_resource(), path));
41 }
35 } 42 }
36 43
37 FileRef::FileRef(const FileRef& other) 44 FileRef::FileRef(const FileRef& other)
38 : Resource(other) { 45 : Resource(other) {
39 } 46 }
40 47
41 PP_FileSystemType FileRef::GetFileSystemType() const { 48 PP_FileSystemType FileRef::GetFileSystemType() const {
42 if (!has_interface<PPB_FileRef_1_0>()) 49 if (has_interface<PPB_FileRef_1_1>())
43 return PP_FILESYSTEMTYPE_EXTERNAL; 50 return get_interface<PPB_FileRef_1_1>()->GetFileSystemType(pp_resource());
44 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); 51 if (has_interface<PPB_FileRef_1_0>())
52 return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource());
53 return PP_FILESYSTEMTYPE_EXTERNAL;
45 } 54 }
46 55
47 Var FileRef::GetName() const { 56 Var FileRef::GetName() const {
48 if (!has_interface<PPB_FileRef_1_0>()) 57 if (has_interface<PPB_FileRef_1_1>()) {
49 return Var(); 58 return Var(PASS_REF,
50 return Var(PASS_REF, 59 get_interface<PPB_FileRef_1_1>()->GetName(pp_resource()));
51 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); 60 }
61 if (has_interface<PPB_FileRef_1_0>()) {
62 return Var(PASS_REF,
63 get_interface<PPB_FileRef_1_0>()->GetName(pp_resource()));
64 }
65 return Var();
52 } 66 }
53 67
54 Var FileRef::GetPath() const { 68 Var FileRef::GetPath() const {
55 if (!has_interface<PPB_FileRef_1_0>()) 69 if (has_interface<PPB_FileRef_1_1>()) {
56 return Var(); 70 return Var(PASS_REF,
57 return Var(PASS_REF, 71 get_interface<PPB_FileRef_1_1>()->GetPath(pp_resource()));
58 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); 72 }
73 if (has_interface<PPB_FileRef_1_0>()) {
74 return Var(PASS_REF,
75 get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource()));
76 }
77 return Var();
59 } 78 }
60 79
61 FileRef FileRef::GetParent() const { 80 FileRef FileRef::GetParent() const {
62 if (!has_interface<PPB_FileRef_1_0>()) 81 if (has_interface<PPB_FileRef_1_1>()) {
63 return FileRef(); 82 return FileRef(PASS_REF,
64 return FileRef(PASS_REF, 83 get_interface<PPB_FileRef_1_1>()->GetParent(pp_resource()));
65 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); 84 }
85 if (has_interface<PPB_FileRef_1_0>()) {
86 return FileRef(PASS_REF,
87 get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource()));
88 }
89 return FileRef();
66 } 90 }
67 91
68 int32_t FileRef::MakeDirectory(const CompletionCallback& cc) { 92 int32_t FileRef::MakeDirectory(const CompletionCallback& cc) {
69 if (!has_interface<PPB_FileRef_1_0>()) 93 if (has_interface<PPB_FileRef_1_1>()) {
70 return cc.MayForce(PP_ERROR_NOINTERFACE); 94 return get_interface<PPB_FileRef_1_1>()->MakeDirectory(
71 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( 95 pp_resource(),
72 pp_resource(), 96 PP_FALSE, // make_ancestors
73 PP_FALSE, // make_ancestors 97 cc.pp_completion_callback());
74 cc.pp_completion_callback()); 98 }
99 if (has_interface<PPB_FileRef_1_0>()) {
100 return get_interface<PPB_FileRef_1_0>()->MakeDirectory(
101 pp_resource(),
102 PP_FALSE, // make_ancestors
103 cc.pp_completion_callback());
104 }
105 return cc.MayForce(PP_ERROR_NOINTERFACE);
75 } 106 }
76 107
77 int32_t FileRef::MakeDirectoryIncludingAncestors( 108 int32_t FileRef::MakeDirectoryIncludingAncestors(
78 const CompletionCallback& cc) { 109 const CompletionCallback& cc) {
79 if (!has_interface<PPB_FileRef_1_0>()) 110 if (has_interface<PPB_FileRef_1_1>()) {
80 return cc.MayForce(PP_ERROR_NOINTERFACE); 111 return get_interface<PPB_FileRef_1_1>()->MakeDirectory(
81 return get_interface<PPB_FileRef_1_0>()->MakeDirectory( 112 pp_resource(),
82 pp_resource(), 113 PP_TRUE, // make_ancestors
83 PP_TRUE, // make_ancestors 114 cc.pp_completion_callback());
84 cc.pp_completion_callback()); 115 }
116 if (has_interface<PPB_FileRef_1_0>()) {
117 return get_interface<PPB_FileRef_1_0>()->MakeDirectory(
118 pp_resource(),
119 PP_TRUE, // make_ancestors
120 cc.pp_completion_callback());
121 }
122 return cc.MayForce(PP_ERROR_NOINTERFACE);
85 } 123 }
86 124
87 int32_t FileRef::Touch(PP_Time last_access_time, 125 int32_t FileRef::Touch(PP_Time last_access_time,
88 PP_Time last_modified_time, 126 PP_Time last_modified_time,
89 const CompletionCallback& cc) { 127 const CompletionCallback& cc) {
90 if (!has_interface<PPB_FileRef_1_0>()) 128 if (has_interface<PPB_FileRef_1_1>()) {
91 return cc.MayForce(PP_ERROR_NOINTERFACE); 129 return get_interface<PPB_FileRef_1_1>()->Touch(
92 return get_interface<PPB_FileRef_1_0>()->Touch( 130 pp_resource(), last_access_time, last_modified_time,
93 pp_resource(), last_access_time, last_modified_time, 131 cc.pp_completion_callback());
94 cc.pp_completion_callback()); 132 }
133 if (has_interface<PPB_FileRef_1_0>()) {
134 return get_interface<PPB_FileRef_1_0>()->Touch(
135 pp_resource(), last_access_time, last_modified_time,
136 cc.pp_completion_callback());
137 }
138 return cc.MayForce(PP_ERROR_NOINTERFACE);
95 } 139 }
96 140
97 int32_t FileRef::Delete(const CompletionCallback& cc) { 141 int32_t FileRef::Delete(const CompletionCallback& cc) {
98 if (!has_interface<PPB_FileRef_1_0>()) 142 if (has_interface<PPB_FileRef_1_1>()) {
99 return cc.MayForce(PP_ERROR_NOINTERFACE); 143 return get_interface<PPB_FileRef_1_1>()->Delete(
100 return get_interface<PPB_FileRef_1_0>()->Delete( 144 pp_resource(), cc.pp_completion_callback());
101 pp_resource(), cc.pp_completion_callback()); 145 }
146 if (has_interface<PPB_FileRef_1_0>()) {
147 return get_interface<PPB_FileRef_1_0>()->Delete(
148 pp_resource(), cc.pp_completion_callback());
149 }
150 return cc.MayForce(PP_ERROR_NOINTERFACE);
102 } 151 }
103 152
104 int32_t FileRef::Rename(const FileRef& new_file_ref, 153 int32_t FileRef::Rename(const FileRef& new_file_ref,
105 const CompletionCallback& cc) { 154 const CompletionCallback& cc) {
106 if (!has_interface<PPB_FileRef_1_0>()) 155 if (has_interface<PPB_FileRef_1_1>()) {
107 return cc.MayForce(PP_ERROR_NOINTERFACE); 156 return get_interface<PPB_FileRef_1_1>()->Rename(
108 return get_interface<PPB_FileRef_1_0>()->Rename( 157 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
109 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); 158 }
159 if (has_interface<PPB_FileRef_1_0>()) {
160 return get_interface<PPB_FileRef_1_0>()->Rename(
161 pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback());
162 }
163 return cc.MayForce(PP_ERROR_NOINTERFACE);
110 } 164 }
111 165
166 int32_t FileRef::Query(const CompletionCallbackWithOutput<PP_FileInfo>& cc) {
167 if (!has_interface<PPB_FileRef_1_1>())
168 return cc.MayForce(PP_ERROR_NOINTERFACE);
169 return get_interface<PPB_FileRef_1_1>()->Query(
170 pp_resource(), cc.output(), cc.pp_completion_callback());
171 }
172
173
112 } // namespace pp 174 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698