[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 2 | // 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 | |
| 13 | namespace pp { |
| 14 | |
| 15 | namespace { |
| 16 | |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 17 | template <> const char* interface_name<PPB_FileRef_1_0>() { |
| 18 | return PPB_FILEREF_INTERFACE_1_0; |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | } // namespace |
| 22 | |
| 23 | FileRef::FileRef(PP_Resource resource) : Resource(resource) { |
| 24 | } |
| 25 | |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 26 | FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | FileRef::FileRef(const FileSystem& file_system, |
| 30 | const char* path) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 31 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 32 | return; |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 33 | PassRefFromConstructor(get_interface<PPB_FileRef_1_0>()->Create( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 34 | file_system.pp_resource(), path)); |
| 35 | } |
| 36 | |
| 37 | FileRef::FileRef(const FileRef& other) |
| 38 | : Resource(other) { |
| 39 | } |
| 40 | |
| 41 | PP_FileSystemType FileRef::GetFileSystemType() const { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 42 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 43 | return PP_FILESYSTEMTYPE_EXTERNAL; |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 44 | return get_interface<PPB_FileRef_1_0>()->GetFileSystemType(pp_resource()); |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | Var FileRef::GetName() const { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 48 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 49 | return Var(); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 50 | return Var(PASS_REF, |
| 51 | get_interface<PPB_FileRef_1_0>()->GetName(pp_resource())); |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | Var FileRef::GetPath() const { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 55 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 56 | return Var(); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 57 | return Var(PASS_REF, |
| 58 | get_interface<PPB_FileRef_1_0>()->GetPath(pp_resource())); |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | FileRef FileRef::GetParent() const { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 62 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 63 | return FileRef(); |
[email protected] | 09af0f7 | 2012-02-27 20:23:19 | [diff] [blame] | 64 | return FileRef(PASS_REF, |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 65 | get_interface<PPB_FileRef_1_0>()->GetParent(pp_resource())); |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | int32_t FileRef::MakeDirectory(const CompletionCallback& cc) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 69 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 70 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 71 | return get_interface<PPB_FileRef_1_0>()->MakeDirectory( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 72 | pp_resource(), |
| 73 | PP_FALSE, // make_ancestors |
| 74 | cc.pp_completion_callback()); |
| 75 | } |
| 76 | |
| 77 | int32_t FileRef::MakeDirectoryIncludingAncestors( |
| 78 | const CompletionCallback& cc) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 79 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 80 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 81 | return get_interface<PPB_FileRef_1_0>()->MakeDirectory( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 82 | pp_resource(), |
| 83 | PP_TRUE, // make_ancestors |
| 84 | cc.pp_completion_callback()); |
| 85 | } |
| 86 | |
| 87 | int32_t FileRef::Touch(PP_Time last_access_time, |
| 88 | PP_Time last_modified_time, |
| 89 | const CompletionCallback& cc) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 90 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 91 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 92 | return get_interface<PPB_FileRef_1_0>()->Touch( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 93 | pp_resource(), last_access_time, last_modified_time, |
| 94 | cc.pp_completion_callback()); |
| 95 | } |
| 96 | |
| 97 | int32_t FileRef::Delete(const CompletionCallback& cc) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 98 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 99 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 100 | return get_interface<PPB_FileRef_1_0>()->Delete( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 101 | pp_resource(), cc.pp_completion_callback()); |
| 102 | } |
| 103 | |
| 104 | int32_t FileRef::Rename(const FileRef& new_file_ref, |
| 105 | const CompletionCallback& cc) { |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 106 | if (!has_interface<PPB_FileRef_1_0>()) |
[email protected] | 917e86a | 2011-06-30 21:42:37 | [diff] [blame] | 107 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
[email protected] | 6060b10c | 2012-03-31 04:24:21 | [diff] [blame] | 108 | return get_interface<PPB_FileRef_1_0>()->Rename( |
[email protected] | 126f4fb | 2011-06-27 20:18:59 | [diff] [blame] | 109 | pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); |
| 110 | } |
| 111 | |
| 112 | } // namespace pp |