15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/file_system.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_errors.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/ppb_file_system.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/completion_callback.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/file_ref.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance_handle.h" 120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ppapi/cpp/logging.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module_impl.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <> const char* interface_name<PPB_FileSystem_1_0>() { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return PPB_FILESYSTEM_INTERFACE_1_0; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileSystem::FileSystem() { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)FileSystem::FileSystem(const FileSystem& other) : Resource(other) { 30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)FileSystem::FileSystem(const Resource& resource) : Resource(resource) { 330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (!IsFileSystem(resource)) { 340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) PP_NOTREACHED(); 350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // On release builds, set this to null. 370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Clear(); 380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) } 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)FileSystem::FileSystem(PassRef, PP_Resource resource) 42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) : Resource(PASS_REF, resource) { 43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileSystem::FileSystem(const InstanceHandle& instance, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_FileSystemType type) { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!has_interface<PPB_FileSystem_1_0>()) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PassRefFromConstructor(get_interface<PPB_FileSystem_1_0>()->Create( 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) instance.pp_instance(), type)); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int32_t FileSystem::Open(int64_t expected_size, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const CompletionCallback& cc) { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!has_interface<PPB_FileSystem_1_0>()) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cc.MayForce(PP_ERROR_NOINTERFACE); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return get_interface<PPB_FileSystem_1_0>()->Open( 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp_resource(), expected_size, cc.pp_completion_callback()); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static 620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)bool FileSystem::IsFileSystem(const Resource& resource) { 630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (!has_interface<PPB_FileSystem_1_0>()) 640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return false; 650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return get_interface<PPB_FileSystem_1_0>()->IsFileSystem( 660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) resource.pp_resource()) == PP_TRUE; 670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace pp 70