1 // Copyright 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/weak_ptr.h" 10 #include "ppapi/c/pp_file_info.h" 11 #include "ppapi/host/host_message_context.h" 12 #include "ppapi/host/resource_host.h" 13 #include "url/gurl.h" 14 #include "webkit/browser/fileapi/file_system_context.h" 15 #include "webkit/common/fileapi/file_system_types.h" 16 17 namespace content { 18 19 class BrowserPpapiHost; 20 21 class PepperFileSystemBrowserHost : 22 public ppapi::host::ResourceHost, 23 public base::SupportsWeakPtr<PepperFileSystemBrowserHost> { 24 public: 25 PepperFileSystemBrowserHost(BrowserPpapiHost* host, 26 PP_Instance instance, 27 PP_Resource resource, 28 PP_FileSystemType type); 29 virtual ~PepperFileSystemBrowserHost(); 30 31 // ppapi::host::ResourceHost override. 32 virtual int32_t OnResourceMessageReceived( 33 const IPC::Message& msg, 34 ppapi::host::HostMessageContext* context) OVERRIDE; 35 virtual bool IsFileSystemHost() OVERRIDE; 36 37 // Supports FileRefs direct access on the host side. 38 PP_FileSystemType GetType() const { return type_; } 39 bool IsOpened() const { return opened_; } 40 GURL GetRootUrl() const { return root_url_; } 41 scoped_refptr<fileapi::FileSystemContext> GetFileSystemContext() const { 42 return fs_context_; 43 } 44 45 private: 46 void GotFileSystemContext( 47 ppapi::host::ReplyMessageContext reply_context, 48 fileapi::FileSystemType file_system_type, 49 scoped_refptr<fileapi::FileSystemContext> fs_context); 50 void OpenFileSystemComplete( 51 ppapi::host::ReplyMessageContext reply_context, 52 base::PlatformFileError error, 53 const std::string& name, 54 const GURL& root); 55 56 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, 57 int64_t expected_size); 58 int32_t OnHostMsgInitIsolatedFileSystem( 59 ppapi::host::HostMessageContext* context, 60 const std::string& fsid); 61 62 BrowserPpapiHost* browser_ppapi_host_; 63 base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_; 64 65 PP_FileSystemType type_; 66 bool opened_; // whether open is successful. 67 GURL root_url_; 68 scoped_refptr<fileapi::FileSystemContext> fs_context_; 69 bool called_open_; // whether open has been called. 70 71 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost); 72 }; 73 74 } // namespace content 75 76 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_ 77