1 // Copyright (c) 2012 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 "webkit/plugins/ppapi/file_callbacks.h"
7 #include "base/logging.h"
8 #include "ppapi/c/pp_file_info.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_file_system.h"
11 #include "ppapi/shared_impl/file_type_conversion.h"
12 #include "ppapi/shared_impl/time_conversion.h"
13 #include "ppapi/shared_impl/tracked_callback.h"
14 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/plugins/ppapi/plugin_module.h"
16 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
18 using ppapi::Resource
;
19 using ppapi::TimeToPPTime
;
20 using ppapi::TrackedCallback
;
25 FileCallbacks::FileCallbacks(
27 scoped_refptr
<TrackedCallback
> callback
,
29 scoped_refptr
<PPB_FileSystem_Impl
> file_system
)
30 : callback_(callback
),
32 file_system_(file_system
) {
35 FileCallbacks::~FileCallbacks() {}
37 void FileCallbacks::DidSucceed() {
38 if (callback_
->completed())
41 callback_
->Run(PP_OK
);
44 void FileCallbacks::DidReadMetadata(
45 const base::PlatformFileInfo
& file_info
,
46 const base::FilePath
& unused
) {
47 if (callback_
->completed())
52 info_
->size
= file_info
.size
;
53 info_
->creation_time
= TimeToPPTime(file_info
.creation_time
);
54 info_
->last_access_time
= TimeToPPTime(file_info
.last_accessed
);
55 info_
->last_modified_time
= TimeToPPTime(file_info
.last_modified
);
56 info_
->system_type
= file_system_
->type();
57 if (file_info
.is_directory
)
58 info_
->type
= PP_FILETYPE_DIRECTORY
;
60 info_
->type
= PP_FILETYPE_REGULAR
;
62 callback_
->Run(PP_OK
);
65 void FileCallbacks::DidCreateSnapshotFile(
66 const base::PlatformFileInfo
& file_info
,
67 const base::FilePath
& path
) {
71 void FileCallbacks::DidReadDirectory(
72 const std::vector
<base::FileUtilProxy::Entry
>& entries
, bool has_more
) {
76 void FileCallbacks::DidOpenFileSystem(const std::string
&,
77 const GURL
& root_url
) {
78 if (callback_
->completed())
82 file_system_
->set_root_url(root_url
);
83 file_system_
->set_opened(true);
85 callback_
->Run(PP_OK
);
88 void FileCallbacks::DidFail(base::PlatformFileError error_code
) {
89 RunCallback(error_code
);
92 void FileCallbacks::DidWrite(int64 bytes
, bool complete
) {
96 void FileCallbacks::RunCallback(base::PlatformFileError error_code
) {
97 if (callback_
->completed())
100 callback_
->Run(::ppapi::PlatformFileErrorToPepperError(error_code
));
104 } // namespace webkit