Changed get_caretOffset to return -1 when the object on which it's called is not...
[chromium-blink-merge.git] / ppapi / proxy / file_system_resource.h
blobfef6b0b2a59d883001fc7b9881db73db688e36b0
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_
8 #include <map>
9 #include <queue>
10 #include <string>
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"
22 namespace ppapi {
24 class TrackedCallback;
26 namespace proxy {
28 class PPAPI_PROXY_EXPORT FileSystemResource
29 : public PluginResource,
30 public NON_EXPORTED_BASE(thunk::PPB_FileSystem_API) {
31 public:
32 // Creates a new FileSystemResource. The resource must be subsequently opened
33 // via Open() before use.
34 FileSystemResource(Connection connection,
35 PP_Instance instance,
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,
41 PP_Instance instance,
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);
63 private:
64 struct QuotaRequest {
65 QuotaRequest(int64_t amount,
66 const RequestQuotaCallback& callback);
67 ~QuotaRequest();
69 int64_t amount;
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,
85 int64_t amount,
86 const OffsetMap& max_written_offsets);
88 PP_FileSystemType type_;
89 bool called_open_;
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);
101 } // namespace proxy
102 } // namespace ppapi
104 #endif // PPAPI_PROXY_FILE_SYSTEM_RESOURCE_H_