• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
7 
8 #include <string>
9 
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"
17 #include "url/gurl.h"
18 
19 namespace content {
20 
21 class RendererPpapiHost;
22 
23 class PepperFileSystemHost
24     : public ppapi::host::ResourceHost,
25       public base::SupportsWeakPtr<PepperFileSystemHost> {
26  public:
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,
31                        PP_Instance instance,
32                        PP_Resource resource,
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,
38                        PP_Instance instance,
39                        PP_Resource resource,
40                        const GURL& root_url,
41                        PP_FileSystemType type);
42   virtual ~PepperFileSystemHost();
43 
44   // ppapi::host::ResourceHost override.
45   virtual int32_t OnResourceMessageReceived(
46       const IPC::Message& msg,
47       ppapi::host::HostMessageContext* context) OVERRIDE;
48   virtual bool IsFileSystemHost() OVERRIDE;
49 
50   // Supports FileRefs direct access on the host side.
GetType()51   PP_FileSystemType GetType() const { return type_; }
IsOpened()52   bool IsOpened() const { return opened_; }
GetRootUrl()53   GURL GetRootUrl() const { return root_url_; }
54 
55  private:
56   // Callback for OpenFileSystem.
57   void DidOpenFileSystem(const std::string& name_unused, const GURL& root);
58   void DidFailOpenFileSystem(base::File::Error error);
59 
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);
66 
67   RendererPpapiHost* renderer_ppapi_host_;
68   ppapi::host::ReplyMessageContext reply_context_;
69 
70   PP_FileSystemType type_;
71   bool opened_;  // whether open is successful.
72   GURL root_url_;
73   bool called_open_;  // whether open has been called.
74 
75   base::WeakPtrFactory<PepperFileSystemHost> weak_factory_;
76 
77   DISALLOW_COPY_AND_ASSIGN(PepperFileSystemHost);
78 };
79 
80 }  // namespace content
81 
82 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_
83