- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / pepper_file_system_host.h
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 "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
15 namespace content {
16
17 class RendererPpapiHost;
18
19 class PepperFileSystemHost :
20     public ppapi::host::ResourceHost,
21     public base::SupportsWeakPtr<PepperFileSystemHost> {
22  public:
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,
27                        PP_Instance instance,
28                        PP_Resource resource,
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,
34                        PP_Instance instance,
35                        PP_Resource resource,
36                        const GURL& root_url,
37                        PP_FileSystemType type);
38   virtual ~PepperFileSystemHost();
39
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;
45
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
51  private:
52   // Callback for OpenFileSystem.
53   void DidOpenFileSystem(const std::string& name_unused, const GURL& root);
54   void DidFailOpenFileSystem(base::PlatformFileError error);
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   RendererPpapiHost* renderer_ppapi_host_;
63   ppapi::host::ReplyMessageContext reply_context_;
64
65   PP_FileSystemType type_;
66   bool opened_;  // whether open is successful.
67   GURL root_url_;
68   bool called_open_;  // whether open has been called.
69
70   base::WeakPtrFactory<PepperFileSystemHost> weak_factory_;
71
72   DISALLOW_COPY_AND_ASSIGN(PepperFileSystemHost);
73 };
74
75 }  // namespace content
76
77 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_FILE_SYSTEM_HOST_H_