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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
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"
17 class RendererPpapiHost;
19 class PepperFileSystemHost :
20 public ppapi::host::ResourceHost,
21 public base::SupportsWeakPtr<PepperFileSystemHost> {
23 // Creates a new PepperFileSystemHost for a file system of a given |type|. The
24 // host will not be connected to any specific file system, and will need to
25 // subsequently be opened before use.
26 PepperFileSystemHost(RendererPpapiHost* host,
29 PP_FileSystemType type);
30 // Creates a new PepperFileSystemHost with an existing file system at the
31 // given |root_url| and of the given |type|. The file system must already be
32 // opened. Once created, the PepperFileSystemHost is already opened for use.
33 PepperFileSystemHost(RendererPpapiHost* host,
37 PP_FileSystemType type);
38 virtual ~PepperFileSystemHost();
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_; }
52 // Callback for OpenFileSystem.
53 void DidOpenFileSystem(const std::string& name_unused, const GURL& root);
54 void DidFailOpenFileSystem(base::PlatformFileError error);
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);
62 RendererPpapiHost* renderer_ppapi_host_;
63 ppapi::host::ReplyMessageContext reply_context_;
65 PP_FileSystemType type_;
66 bool opened_; // whether open is successful.
68 bool called_open_; // whether open has been called.
70 base::WeakPtrFactory<PepperFileSystemHost> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemHost);
75 } // namespace content
77 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_