Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ppapi/cpp/file_system.h" |
| 6 | |
| 7 | #include "ppapi/c/pp_errors.h" |
| 8 | #include "ppapi/c/ppb_file_system.h" |
| 9 | #include "ppapi/cpp/completion_callback.h" |
| 10 | #include "ppapi/cpp/file_ref.h" |
| 11 | #include "ppapi/cpp/instance_handle.h" |
Torne (Richard Coles) | 0f1bc08 | 2013-11-06 12:27:47 +0000 | [diff] [blame] | 12 | #include "ppapi/cpp/logging.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include "ppapi/cpp/module.h" |
| 14 | #include "ppapi/cpp/module_impl.h" |
| 15 | |
| 16 | namespace pp { |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | template <> const char* interface_name<PPB_FileSystem_1_0>() { |
| 21 | return PPB_FILESYSTEM_INTERFACE_1_0; |
| 22 | } |
| 23 | |
| 24 | } // namespace |
| 25 | |
| 26 | FileSystem::FileSystem() { |
| 27 | } |
| 28 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 29 | FileSystem::FileSystem(const FileSystem& other) : Resource(other) { |
| 30 | } |
| 31 | |
Torne (Richard Coles) | 0f1bc08 | 2013-11-06 12:27:47 +0000 | [diff] [blame] | 32 | FileSystem::FileSystem(const Resource& resource) : Resource(resource) { |
| 33 | if (!IsFileSystem(resource)) { |
| 34 | PP_NOTREACHED(); |
| 35 | |
| 36 | // On release builds, set this to null. |
| 37 | Clear(); |
| 38 | } |
| 39 | } |
| 40 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 41 | FileSystem::FileSystem(PassRef, PP_Resource resource) |
| 42 | : Resource(PASS_REF, resource) { |
| 43 | } |
| 44 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | FileSystem::FileSystem(const InstanceHandle& instance, |
| 46 | PP_FileSystemType type) { |
| 47 | if (!has_interface<PPB_FileSystem_1_0>()) |
| 48 | return; |
| 49 | PassRefFromConstructor(get_interface<PPB_FileSystem_1_0>()->Create( |
| 50 | instance.pp_instance(), type)); |
| 51 | } |
| 52 | |
| 53 | int32_t FileSystem::Open(int64_t expected_size, |
| 54 | const CompletionCallback& cc) { |
| 55 | if (!has_interface<PPB_FileSystem_1_0>()) |
| 56 | return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 57 | return get_interface<PPB_FileSystem_1_0>()->Open( |
| 58 | pp_resource(), expected_size, cc.pp_completion_callback()); |
| 59 | } |
| 60 | |
Torne (Richard Coles) | 0f1bc08 | 2013-11-06 12:27:47 +0000 | [diff] [blame] | 61 | // static |
| 62 | bool FileSystem::IsFileSystem(const Resource& resource) { |
| 63 | if (!has_interface<PPB_FileSystem_1_0>()) |
| 64 | return false; |
| 65 | return get_interface<PPB_FileSystem_1_0>()->IsFileSystem( |
| 66 | resource.pp_resource()) == PP_TRUE; |
| 67 | } |
| 68 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 69 | } // namespace pp |