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.
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_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ppapi/c/pp_file_info.h"
12 #include "ppapi/host/host_message_context.h"
13 #include "ppapi/host/resource_host.h"
15 #include "webkit/browser/fileapi/file_system_context.h"
16 #include "webkit/common/fileapi/file_system_types.h"
20 class BrowserPpapiHost;
22 class PepperFileSystemBrowserHost :
23 public ppapi::host::ResourceHost,
24 public base::SupportsWeakPtr<PepperFileSystemBrowserHost> {
26 // Creates a new PepperFileSystemBrowserHost for a file system of a given
27 // |type|. The host must be opened before use.
28 PepperFileSystemBrowserHost(BrowserPpapiHost* host,
31 PP_FileSystemType type);
32 virtual ~PepperFileSystemBrowserHost();
34 // Opens the PepperFileSystemBrowserHost to use an existing file system at the
35 // given |root_url|. The file system at |root_url| must already be opened and
36 // have the type given by GetType().
37 // Calls |callback| when complete.
38 void OpenExisting(const GURL& root_url, const base::Closure& callback);
40 // ppapi::host::ResourceHost override.
41 virtual int32_t OnResourceMessageReceived(
42 const IPC::Message& msg,
43 ppapi::host::HostMessageContext* context) OVERRIDE;
44 virtual bool IsFileSystemHost() OVERRIDE;
46 // Supports FileRefs direct access on the host side.
47 PP_FileSystemType GetType() const { return type_; }
48 bool IsOpened() const { return opened_; }
49 GURL GetRootUrl() const { return root_url_; }
50 scoped_refptr<fileapi::FileSystemContext> GetFileSystemContext() const {
55 void OpenExistingWithContext(
56 const base::Closure& callback,
57 scoped_refptr<fileapi::FileSystemContext> fs_context);
58 void GotFileSystemContext(
59 ppapi::host::ReplyMessageContext reply_context,
60 fileapi::FileSystemType file_system_type,
61 scoped_refptr<fileapi::FileSystemContext> fs_context);
62 void GotIsolatedFileSystemContext(
63 ppapi::host::ReplyMessageContext reply_context,
64 scoped_refptr<fileapi::FileSystemContext> fs_context);
65 void OpenFileSystemComplete(
66 ppapi::host::ReplyMessageContext reply_context,
68 const std::string& name,
69 base::PlatformFileError error);
71 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
72 int64_t expected_size);
73 int32_t OnHostMsgInitIsolatedFileSystem(
74 ppapi::host::HostMessageContext* context,
75 const std::string& fsid);
77 BrowserPpapiHost* browser_ppapi_host_;
79 PP_FileSystemType type_;
80 bool opened_; // whether open is successful.
82 scoped_refptr<fileapi::FileSystemContext> fs_context_;
83 bool called_open_; // whether open has been called.
85 base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_;
87 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost);
90 } // namespace content
92 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_