Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / plugins / ppapi / file_callbacks.cc
blob9e3ff7cf9d93fd9a6cf1db041fcd0593a23f6159
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;
22 namespace webkit {
23 namespace ppapi {
25 FileCallbacks::FileCallbacks(
26 Resource* resource,
27 scoped_refptr<TrackedCallback> callback,
28 PP_FileInfo* info,
29 scoped_refptr<PPB_FileSystem_Impl> file_system)
30 : callback_(callback),
31 info_(info),
32 file_system_(file_system) {
35 FileCallbacks::~FileCallbacks() {}
37 void FileCallbacks::DidSucceed() {
38 if (callback_->completed())
39 return;
41 callback_->Run(PP_OK);
44 void FileCallbacks::DidReadMetadata(
45 const base::PlatformFileInfo& file_info,
46 const base::FilePath& unused) {
47 if (callback_->completed())
48 return;
50 DCHECK(info_);
51 DCHECK(file_system_);
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;
59 else
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) {
68 NOTREACHED();
71 void FileCallbacks::DidReadDirectory(
72 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) {
73 NOTREACHED();
76 void FileCallbacks::DidOpenFileSystem(const std::string&,
77 const GURL& root_url) {
78 if (callback_->completed())
79 return;
81 DCHECK(file_system_);
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) {
93 NOTREACHED();
96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) {
97 if (callback_->completed())
98 return;
100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code));
103 } // namespace ppapi
104 } // namespace webkit