- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / pepper / pepper_file_system_browser_host.h
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.
4
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_
7
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"
14 #include "url/gurl.h"
15 #include "webkit/browser/fileapi/file_system_context.h"
16 #include "webkit/common/fileapi/file_system_types.h"
17
18 namespace content {
19
20 class BrowserPpapiHost;
21
22 class PepperFileSystemBrowserHost :
23     public ppapi::host::ResourceHost,
24     public base::SupportsWeakPtr<PepperFileSystemBrowserHost> {
25  public:
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,
29                               PP_Instance instance,
30                               PP_Resource resource,
31                               PP_FileSystemType type);
32   virtual ~PepperFileSystemBrowserHost();
33
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);
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   scoped_refptr<fileapi::FileSystemContext> GetFileSystemContext() const {
51     return fs_context_;
52   }
53
54  private:
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,
67       const GURL& root,
68       const std::string& name,
69       base::PlatformFileError error);
70
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);
76
77   BrowserPpapiHost* browser_ppapi_host_;
78
79   PP_FileSystemType type_;
80   bool opened_;  // whether open is successful.
81   GURL root_url_;
82   scoped_refptr<fileapi::FileSystemContext> fs_context_;
83   bool called_open_;  // whether open has been called.
84
85   base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_;
86
87   DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost);
88 };
89
90 }  // namespace content
91
92 #endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_