Update V8 to version 4.7.24.
[chromium-blink-merge.git] / ppapi / proxy / isolated_file_system_private_resource.cc
blob756bdb7bd6c1a5eacb890853dcfc094255a2e510
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 #include "ppapi/proxy/isolated_file_system_private_resource.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_file_info.h"
11 #include "ppapi/proxy/file_system_resource.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/resource_message_params.h"
14 #include "ppapi/shared_impl/host_resource.h"
15 #include "ppapi/shared_impl/tracked_callback.h"
16 #include "ppapi/thunk/enter.h"
18 namespace ppapi {
19 namespace proxy {
21 namespace {
22 void RunTrackedCallback(scoped_refptr<TrackedCallback> callback,
23 int32_t rc) {
24 callback->Run(rc);
26 } // namespace
28 IsolatedFileSystemPrivateResource::IsolatedFileSystemPrivateResource(
29 Connection connection, PP_Instance instance)
30 : PluginResource(connection, instance) {
31 SendCreate(BROWSER, PpapiHostMsg_IsolatedFileSystem_Create());
34 IsolatedFileSystemPrivateResource::~IsolatedFileSystemPrivateResource() {
37 thunk::PPB_IsolatedFileSystem_Private_API*
38 IsolatedFileSystemPrivateResource::AsPPB_IsolatedFileSystem_Private_API() {
39 return this;
42 int32_t IsolatedFileSystemPrivateResource::Open(
43 PP_Instance /* unused */,
44 PP_IsolatedFileSystemType_Private type,
45 PP_Resource* file_system_resource,
46 scoped_refptr<TrackedCallback> callback) {
47 if (!file_system_resource)
48 return PP_ERROR_BADARGUMENT;
50 Call<PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply>(BROWSER,
51 PpapiHostMsg_IsolatedFileSystem_BrowserOpen(type),
52 base::Bind(&IsolatedFileSystemPrivateResource::OnBrowserOpenComplete,
53 this, type, file_system_resource, callback));
54 return PP_OK_COMPLETIONPENDING;
57 void IsolatedFileSystemPrivateResource::OnBrowserOpenComplete(
58 PP_IsolatedFileSystemType_Private type,
59 PP_Resource* file_system_resource,
60 scoped_refptr<TrackedCallback> callback,
61 const ResourceMessageReplyParams& params,
62 const std::string& fsid) {
63 if (!TrackedCallback::IsPending(callback))
64 return;
66 if (params.result() != PP_OK) {
67 callback->Run(params.result());
68 return;
71 FileSystemResource* fs = new FileSystemResource(
72 connection(), pp_instance(), PP_FILESYSTEMTYPE_ISOLATED);
73 *file_system_resource = fs->GetReference();
74 if (*file_system_resource == 0)
75 callback->Run(PP_ERROR_FAILED);
76 fs->InitIsolatedFileSystem(
77 fsid, type, base::Bind(&RunTrackedCallback, callback));
80 } // namespace proxy
81 } // namespace ppapi