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_
10 #include "base/basictypes.h"
11 #include "base/files/file.h"
12 #include "base/memory/weak_ptr.h"
13 #include "ppapi/c/pp_file_info.h"
14 #include "ppapi/c/private/ppb_isolated_file_system_private.h"
15 #include "ppapi/host/host_message_context.h"
16 #include "ppapi/host/resource_host.h"
21 class RendererPpapiHost
;
23 class PepperFileSystemHost
24 : public ppapi::host::ResourceHost
,
25 public base::SupportsWeakPtr
<PepperFileSystemHost
> {
27 // Creates a new PepperFileSystemHost for a file system of a given |type|. The
28 // host will not be connected to any specific file system, and will need to
29 // subsequently be opened before use.
30 PepperFileSystemHost(RendererPpapiHost
* host
,
33 PP_FileSystemType type
);
34 // Creates a new PepperFileSystemHost with an existing file system at the
35 // given |root_url| and of the given |type|. The file system must already be
36 // opened. Once created, the PepperFileSystemHost is already opened for use.
37 PepperFileSystemHost(RendererPpapiHost
* host
,
41 PP_FileSystemType type
);
42 ~PepperFileSystemHost() override
;
44 // ppapi::host::ResourceHost override.
45 int32_t OnResourceMessageReceived(
46 const IPC::Message
& msg
,
47 ppapi::host::HostMessageContext
* context
) override
;
48 bool IsFileSystemHost() override
;
50 // Supports FileRefs direct access on the host side.
51 PP_FileSystemType
GetType() const { return type_
; }
52 bool IsOpened() const { return opened_
; }
53 GURL
GetRootUrl() const { return root_url_
; }
56 // Callback for OpenFileSystem.
57 void DidOpenFileSystem(const std::string
& name_unused
, const GURL
& root
);
58 void DidFailOpenFileSystem(base::File::Error error
);
60 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext
* context
,
61 int64_t expected_size
);
62 int32_t OnHostMsgInitIsolatedFileSystem(
63 ppapi::host::HostMessageContext
* context
,
64 const std::string
& fsid
,
65 PP_IsolatedFileSystemType_Private type
);
67 RendererPpapiHost
* renderer_ppapi_host_
;
68 ppapi::host::ReplyMessageContext reply_context_
;
70 PP_FileSystemType type_
;
71 bool opened_
; // whether open is successful.
73 bool called_open_
; // whether open has been called.
75 base::WeakPtrFactory
<PepperFileSystemHost
> weak_factory_
;
77 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemHost
);
80 } // namespace content
82 #endif // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_