Home | History | Annotate | Download | only in proxy
      1 // Copyright (c) 2013 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 #ifndef PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_
      6 #define PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "ppapi/c/pp_file_info.h"
     12 #include "ppapi/c/private/ppb_isolated_file_system_private.h"
     13 #include "ppapi/proxy/connection.h"
     14 #include "ppapi/proxy/plugin_resource.h"
     15 #include "ppapi/proxy/ppapi_proxy_export.h"
     16 #include "ppapi/proxy/resource_message_params.h"
     17 #include "ppapi/thunk/ppb_file_system_api.h"
     18 
     19 namespace ppapi {
     20 
     21 class TrackedCallback;
     22 
     23 namespace proxy {
     24 
     25 class PPAPI_PROXY_EXPORT FileSystemResource
     26     : public PluginResource,
     27       public NON_EXPORTED_BASE(thunk::PPB_FileSystem_API) {
     28  public:
     29   // Creates a new FileSystemResource. The resource must be subsequently opened
     30   // via Open() before use.
     31   FileSystemResource(Connection connection,
     32                      PP_Instance instance,
     33                      PP_FileSystemType type);
     34   // Creates a FileSystemResource, attached to an existing pending host
     35   // resource. The |pending_renderer_id| and |pending_browser_id| must be
     36   // already-opened file systems.
     37   FileSystemResource(Connection connection,
     38                      PP_Instance instance,
     39                      int pending_renderer_id,
     40                      int pending_browser_id,
     41                      PP_FileSystemType type);
     42   virtual ~FileSystemResource();
     43 
     44   // Resource overrides.
     45   virtual thunk::PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE;
     46 
     47   // PPB_FileSystem_API implementation.
     48   virtual int32_t Open(int64_t expected_size,
     49                        scoped_refptr<TrackedCallback> callback) OVERRIDE;
     50   virtual PP_FileSystemType GetType() OVERRIDE;
     51 
     52   int32_t InitIsolatedFileSystem(const std::string& fsid,
     53                                  PP_IsolatedFileSystemType_Private type,
     54                                  const base::Callback<void(int32_t)>& callback);
     55  private:
     56   // Called when the host has responded to our open request.
     57   void OpenComplete(scoped_refptr<TrackedCallback> callback,
     58                     const ResourceMessageReplyParams& params);
     59 
     60   // Called when the host has responded to our InitIsolatedFileSystem request.
     61   void InitIsolatedFileSystemComplete(
     62       const base::Callback<void(int32_t)>& callback,
     63       const ResourceMessageReplyParams& params);
     64 
     65   PP_FileSystemType type_;
     66   bool called_open_;
     67   uint32_t callback_count_;
     68   int32_t callback_result_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(FileSystemResource);
     71 };
     72 
     73 }  // namespace proxy
     74 }  // namespace ppapi
     75 
     76 #endif  // PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_
     77