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 PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_
6 #define PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_
12 #include "base/memory/ref_counted.h"
13 #include "ppapi/c/pp_file_info.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/private/ppb_isolated_file_system_private.h"
16 #include "ppapi/proxy/connection.h"
17 #include "ppapi/proxy/plugin_resource.h"
18 #include "ppapi/proxy/ppapi_proxy_export.h"
19 #include "ppapi/proxy/resource_message_params.h"
20 #include "ppapi/thunk/ppb_file_system_api.h"
24 class TrackedCallback
;
28 class PPAPI_PROXY_EXPORT FileSystemResource
29 : public PluginResource
,
30 public NON_EXPORTED_BASE(thunk::PPB_FileSystem_API
) {
32 // Creates a new FileSystemResource. The resource must be subsequently opened
33 // via Open() before use.
34 FileSystemResource(Connection connection
,
36 PP_FileSystemType type
);
37 // Creates a FileSystemResource, attached to an existing pending host
38 // resource. The |pending_renderer_id| and |pending_browser_id| must be
39 // already-opened file systems.
40 FileSystemResource(Connection connection
,
42 int pending_renderer_id
,
43 int pending_browser_id
,
44 PP_FileSystemType type
);
45 virtual ~FileSystemResource();
47 // Resource overrides.
48 virtual thunk::PPB_FileSystem_API
* AsPPB_FileSystem_API() OVERRIDE
;
50 // PPB_FileSystem_API implementation.
51 virtual int32_t Open(int64_t expected_size
,
52 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
53 virtual PP_FileSystemType
GetType() OVERRIDE
;
54 virtual void OpenQuotaFile(PP_Resource file_io
) OVERRIDE
;
55 virtual void CloseQuotaFile(PP_Resource file_io
) OVERRIDE
;
56 typedef base::Callback
<void(int64_t)> RequestQuotaCallback
;
57 virtual int64_t RequestQuota(int64_t amount
,
58 const RequestQuotaCallback
& callback
) OVERRIDE
;
60 int32_t InitIsolatedFileSystem(const std::string
& fsid
,
61 PP_IsolatedFileSystemType_Private type
,
62 const base::Callback
<void(int32_t)>& callback
);
65 QuotaRequest(int64_t amount
,
66 const RequestQuotaCallback
& callback
);
70 RequestQuotaCallback callback
;
73 // Called when the host has responded to our open request.
74 void OpenComplete(scoped_refptr
<TrackedCallback
> callback
,
75 const ResourceMessageReplyParams
& params
);
77 // Called when the host has responded to our InitIsolatedFileSystem request.
78 void InitIsolatedFileSystemComplete(
79 const base::Callback
<void(int32_t)>& callback
,
80 const ResourceMessageReplyParams
& params
);
82 void ReserveQuota(int64_t amount
);
83 typedef std::map
<int32_t, int64_t> OffsetMap
;
84 void ReserveQuotaComplete(const ResourceMessageReplyParams
& params
,
86 const OffsetMap
& max_written_offsets
);
88 PP_FileSystemType type_
;
90 uint32_t callback_count_
;
91 int32_t callback_result_
;
93 std::set
<PP_Resource
> files_
;
94 std::queue
<QuotaRequest
> pending_quota_requests_
;
95 int64_t reserved_quota_
;
96 bool reserving_quota_
;
98 DISALLOW_COPY_AND_ASSIGN(FileSystemResource
);
104 #endif // PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_