Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_file_system_browser_host.h
blobd31a16d565190aa331c2d5f1de237c17810b13b0
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.
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_
8 #include <queue>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/memory/weak_ptr.h"
15 #include "content/browser/renderer_host/pepper/quota_reservation.h"
16 #include "content/common/content_export.h"
17 #include "ppapi/c/pp_file_info.h"
18 #include "ppapi/c/private/ppb_isolated_file_system_private.h"
19 #include "ppapi/host/host_message_context.h"
20 #include "ppapi/host/resource_host.h"
21 #include "ppapi/shared_impl/file_growth.h"
22 #include "url/gurl.h"
23 #include "webkit/browser/fileapi/file_system_context.h"
25 namespace content {
27 class BrowserPpapiHost;
28 class PepperFileIOHost;
30 class CONTENT_EXPORT PepperFileSystemBrowserHost
31 : public ppapi::host::ResourceHost,
32 public base::SupportsWeakPtr<PepperFileSystemBrowserHost> {
33 public:
34 // Creates a new PepperFileSystemBrowserHost for a file system of a given
35 // |type|. The host must be opened before use.
36 PepperFileSystemBrowserHost(BrowserPpapiHost* host,
37 PP_Instance instance,
38 PP_Resource resource,
39 PP_FileSystemType type);
40 virtual ~PepperFileSystemBrowserHost();
42 // Opens the PepperFileSystemBrowserHost to use an existing file system at the
43 // given |root_url|. The file system at |root_url| must already be opened and
44 // have the type given by GetType().
45 // Calls |callback| when complete.
46 void OpenExisting(const GURL& root_url, const base::Closure& callback);
48 // ppapi::host::ResourceHost overrides.
49 virtual int32_t OnResourceMessageReceived(
50 const IPC::Message& msg,
51 ppapi::host::HostMessageContext* context) OVERRIDE;
52 virtual bool IsFileSystemHost() OVERRIDE;
54 // Supports FileRefs direct access on the host side.
55 PP_FileSystemType GetType() const { return type_; }
56 bool IsOpened() const { return opened_; }
57 GURL GetRootUrl() const { return root_url_; }
58 scoped_refptr<fileapi::FileSystemContext> GetFileSystemContext() const {
59 return file_system_context_;
62 // Supports FileIOs direct access on the host side.
63 // Non-NULL only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
64 fileapi::FileSystemOperationRunner* GetFileSystemOperationRunner() const {
65 return file_system_operation_runner_.get();
67 bool ChecksQuota() const { return quota_reservation_ != NULL; }
68 // Opens a file for writing with quota checks. Returns the file size in the
69 // callback.
70 typedef base::Callback<void(int64_t)> OpenQuotaFileCallback;
71 void OpenQuotaFile(PepperFileIOHost* file_io_host,
72 const fileapi::FileSystemURL& url,
73 const OpenQuotaFileCallback& callback);
74 // Closes the file. This must be called after OpenQuotaFile and before the
75 // PepperFileIOHost is destroyed.
76 void CloseQuotaFile(PepperFileIOHost* file_io_host,
77 const ppapi::FileGrowth& file_growth);
79 private:
80 friend class PepperFileSystemBrowserHostTest;
82 void OpenExistingFileSystem(
83 const base::Closure& callback,
84 scoped_refptr<fileapi::FileSystemContext> file_system_context);
85 void OpenFileSystem(
86 ppapi::host::ReplyMessageContext reply_context,
87 fileapi::FileSystemType file_system_type,
88 scoped_refptr<fileapi::FileSystemContext> file_system_context);
89 void OpenFileSystemComplete(
90 ppapi::host::ReplyMessageContext reply_context,
91 const GURL& root,
92 const std::string& name,
93 base::File::Error error);
94 void OpenIsolatedFileSystem(
95 ppapi::host::ReplyMessageContext reply_context,
96 const std::string& fsid,
97 PP_IsolatedFileSystemType_Private type,
98 scoped_refptr<fileapi::FileSystemContext> file_system_context);
99 void OpenPluginPrivateFileSystem(
100 ppapi::host::ReplyMessageContext reply_context,
101 const std::string& fsid,
102 scoped_refptr<fileapi::FileSystemContext> file_system_context);
103 void OpenPluginPrivateFileSystemComplete(
104 ppapi::host::ReplyMessageContext reply_context,
105 const std::string& fsid,
106 base::File::Error error);
108 int32_t OnHostMsgOpen(
109 ppapi::host::HostMessageContext* context,
110 int64_t expected_size);
111 int32_t OnHostMsgInitIsolatedFileSystem(
112 ppapi::host::HostMessageContext* context,
113 const std::string& fsid,
114 PP_IsolatedFileSystemType_Private type);
115 int32_t OnHostMsgReserveQuota(
116 ppapi::host::HostMessageContext* context,
117 int64_t amount,
118 const ppapi::FileGrowthMap& file_growths);
120 void SendReplyForFileSystem(
121 ppapi::host::ReplyMessageContext reply_context,
122 int32_t pp_error);
123 void SendReplyForIsolatedFileSystem(
124 ppapi::host::ReplyMessageContext reply_context,
125 const std::string& fsid,
126 int32_t error);
128 void SetFileSystemContext(
129 scoped_refptr<fileapi::FileSystemContext> file_system_context);
131 bool ShouldCreateQuotaReservation() const;
132 void CreateQuotaReservation(const base::Closure& callback);
133 void GotQuotaReservation(
134 const base::Closure& callback,
135 scoped_refptr<QuotaReservation> quota_reservation);
137 void GotReservedQuota(
138 ppapi::host::ReplyMessageContext reply_context,
139 int64_t amount,
140 const ppapi::FileSizeMap& file_sizes);
141 void DidOpenQuotaFile(
142 PP_Resource file_io_resource,
143 const OpenQuotaFileCallback& callback,
144 int64_t max_written_offset);
146 std::string GetPluginMimeType() const;
148 // Returns plugin ID generated from plugin's MIME type.
149 std::string GeneratePluginId(const std::string& mime_type) const;
151 BrowserPpapiHost* browser_ppapi_host_;
153 PP_FileSystemType type_;
154 bool called_open_; // whether open has been called.
155 bool opened_; // whether open succeeded.
156 GURL root_url_;
157 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
159 scoped_ptr<fileapi::FileSystemOperationRunner> file_system_operation_runner_;
161 // Used only for file systems with quota.
162 // When a PepperFileIOHost calls OpenQuotaFile, we add the id and a non-owning
163 // pointer to this map. CloseQuotaFile must be called when before the host is
164 // destroyed.
165 typedef std::map<int32_t, PepperFileIOHost*> FileMap;
166 FileMap files_;
167 int64_t reserved_quota_;
168 bool reserving_quota_;
169 // Access only on the FileSystemContext's default_file_task_runner().
170 scoped_refptr<QuotaReservation> quota_reservation_;
172 std::string fsid_; // used only for isolated filesystems.
174 base::WeakPtrFactory<PepperFileSystemBrowserHost> weak_factory_;
176 DISALLOW_COPY_AND_ASSIGN(PepperFileSystemBrowserHost);
179 } // namespace content
181 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_FILE_SYSTEM_BROWSER_HOST_H_