| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/plugins/ppapi/file_callbacks.h" | 5 #include "webkit/plugins/ppapi/file_callbacks.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_file_info.h" | 8 #include "ppapi/c/pp_file_info.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/ppb_file_system.h" | 10 #include "ppapi/c/ppb_file_system.h" |
| 11 #include "ppapi/shared_impl/file_type_conversion.h" | 11 #include "ppapi/shared_impl/file_type_conversion.h" |
| 12 #include "ppapi/shared_impl/time_conversion.h" | 12 #include "ppapi/shared_impl/time_conversion.h" |
| 13 #include "ppapi/shared_impl/tracked_callback.h" | 13 #include "ppapi/shared_impl/tracked_callback.h" |
| 14 #include "webkit/fileapi/file_system_types.h" | 14 #include "webkit/fileapi/file_system_types.h" |
| 15 #include "webkit/plugins/ppapi/plugin_module.h" | 15 #include "webkit/plugins/ppapi/plugin_module.h" |
| 16 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | |
| 17 | 16 |
| 18 using ppapi::Resource; | 17 using ppapi::Resource; |
| 19 using ppapi::TimeToPPTime; | 18 using ppapi::TimeToPPTime; |
| 20 using ppapi::TrackedCallback; | 19 using ppapi::TrackedCallback; |
| 21 | 20 |
| 22 namespace webkit { | 21 namespace webkit { |
| 23 namespace ppapi { | 22 namespace ppapi { |
| 24 | 23 |
| 25 FileCallbacks::FileCallbacks( | 24 FileCallbacks::FileCallbacks( |
| 26 Resource* resource, | 25 Resource* resource, |
| 27 scoped_refptr<TrackedCallback> callback, | 26 scoped_refptr<TrackedCallback> callback, |
| 27 PP_FileInfo* info) |
| 28 : callback_(callback), |
| 29 info_(info), |
| 30 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
| 31 } |
| 32 |
| 33 FileCallbacks::FileCallbacks( |
| 34 Resource* resource, |
| 35 scoped_refptr<TrackedCallback> callback, |
| 28 PP_FileInfo* info, | 36 PP_FileInfo* info, |
| 29 scoped_refptr<PPB_FileSystem_Impl> file_system) | 37 PP_FileSystemType file_system_type) |
| 30 : callback_(callback), | 38 : callback_(callback), |
| 31 info_(info), | 39 info_(info), |
| 32 file_system_(file_system) { | 40 file_system_type_(file_system_type) { |
| 33 } | 41 } |
| 34 | 42 |
| 35 FileCallbacks::~FileCallbacks() {} | 43 FileCallbacks::~FileCallbacks() {} |
| 36 | 44 |
| 37 void FileCallbacks::DidSucceed() { | 45 void FileCallbacks::DidSucceed() { |
| 38 if (callback_->completed()) | 46 if (callback_->completed()) |
| 39 return; | 47 return; |
| 40 | 48 |
| 41 callback_->Run(PP_OK); | 49 callback_->Run(PP_OK); |
| 42 } | 50 } |
| 43 | 51 |
| 44 void FileCallbacks::DidReadMetadata( | 52 void FileCallbacks::DidReadMetadata( |
| 45 const base::PlatformFileInfo& file_info, | 53 const base::PlatformFileInfo& file_info, |
| 46 const base::FilePath& unused) { | 54 const base::FilePath& unused) { |
| 47 if (callback_->completed()) | 55 if (callback_->completed()) |
| 48 return; | 56 return; |
| 49 | 57 |
| 50 DCHECK(info_); | 58 DCHECK(info_); |
| 51 DCHECK(file_system_); | |
| 52 info_->size = file_info.size; | 59 info_->size = file_info.size; |
| 53 info_->creation_time = TimeToPPTime(file_info.creation_time); | 60 info_->creation_time = TimeToPPTime(file_info.creation_time); |
| 54 info_->last_access_time = TimeToPPTime(file_info.last_accessed); | 61 info_->last_access_time = TimeToPPTime(file_info.last_accessed); |
| 55 info_->last_modified_time = TimeToPPTime(file_info.last_modified); | 62 info_->last_modified_time = TimeToPPTime(file_info.last_modified); |
| 56 info_->system_type = file_system_->type(); | 63 info_->system_type = file_system_type_; |
| 57 if (file_info.is_directory) | 64 if (file_info.is_directory) |
| 58 info_->type = PP_FILETYPE_DIRECTORY; | 65 info_->type = PP_FILETYPE_DIRECTORY; |
| 59 else | 66 else |
| 60 info_->type = PP_FILETYPE_REGULAR; | 67 info_->type = PP_FILETYPE_REGULAR; |
| 61 | 68 |
| 62 callback_->Run(PP_OK); | 69 callback_->Run(PP_OK); |
| 63 } | 70 } |
| 64 | 71 |
| 65 void FileCallbacks::DidCreateSnapshotFile( | 72 void FileCallbacks::DidCreateSnapshotFile( |
| 66 const base::PlatformFileInfo& file_info, | 73 const base::PlatformFileInfo& file_info, |
| 67 const base::FilePath& path) { | 74 const base::FilePath& path) { |
| 68 NOTREACHED(); | 75 NOTREACHED(); |
| 69 } | 76 } |
| 70 | 77 |
| 71 void FileCallbacks::DidReadDirectory( | 78 void FileCallbacks::DidReadDirectory( |
| 72 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | 79 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
| 73 NOTREACHED(); | 80 NOTREACHED(); |
| 74 } | 81 } |
| 75 | 82 |
| 76 void FileCallbacks::DidOpenFileSystem(const std::string&, | 83 void FileCallbacks::DidOpenFileSystem(const std::string&, |
| 77 const GURL& root_url) { | 84 const GURL& root_url) { |
| 78 if (callback_->completed()) | 85 NOTREACHED(); |
| 79 return; | |
| 80 | |
| 81 DCHECK(file_system_); | |
| 82 file_system_->set_root_url(root_url); | |
| 83 file_system_->set_opened(true); | |
| 84 | |
| 85 callback_->Run(PP_OK); | |
| 86 } | 86 } |
| 87 | 87 |
| 88 void FileCallbacks::DidFail(base::PlatformFileError error_code) { | 88 void FileCallbacks::DidFail(base::PlatformFileError error_code) { |
| 89 RunCallback(error_code); | 89 RunCallback(error_code); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void FileCallbacks::DidWrite(int64 bytes, bool complete) { | 92 void FileCallbacks::DidWrite(int64 bytes, bool complete) { |
| 93 NOTREACHED(); | 93 NOTREACHED(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { | 96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { |
| 97 if (callback_->completed()) | 97 if (callback_->completed()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); | 100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace ppapi | 103 } // namespace ppapi |
| 104 } // namespace webkit | 104 } // namespace webkit |
| OLD | NEW |