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 "base/utf_string_conversions.h" |
8 #include "ppapi/c/pp_file_info.h" | 9 #include "ppapi/c/pp_file_info.h" |
9 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/ppb_file_system.h" | 11 #include "ppapi/c/ppb_file_system.h" |
11 #include "ppapi/shared_impl/file_type_conversion.h" | 12 #include "ppapi/shared_impl/file_type_conversion.h" |
| 13 #include "ppapi/shared_impl/ppb_file_ref_shared.h" |
12 #include "ppapi/shared_impl/time_conversion.h" | 14 #include "ppapi/shared_impl/time_conversion.h" |
13 #include "ppapi/shared_impl/tracked_callback.h" | 15 #include "ppapi/shared_impl/tracked_callback.h" |
14 #include "webkit/fileapi/file_system_types.h" | 16 #include "webkit/fileapi/file_system_types.h" |
| 17 #include "webkit/fileapi/file_system_util.h" |
15 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
| 19 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
16 | 20 |
17 using ppapi::Resource; | 21 using ppapi::Resource; |
18 using ppapi::TimeToPPTime; | 22 using ppapi::TimeToPPTime; |
19 using ppapi::TrackedCallback; | 23 using ppapi::TrackedCallback; |
20 | 24 |
21 namespace webkit { | 25 namespace webkit { |
22 namespace ppapi { | 26 namespace ppapi { |
23 | 27 |
24 FileCallbacks::FileCallbacks( | 28 FileCallbacks::FileCallbacks( |
25 Resource* resource, | 29 Resource* resource, |
26 scoped_refptr<TrackedCallback> callback, | 30 scoped_refptr<TrackedCallback> callback) |
27 PP_FileInfo* info) | |
28 : callback_(callback), | 31 : callback_(callback), |
29 info_(info), | 32 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
30 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { | 33 read_entries_dir_ref_(NULL) { |
31 } | 34 } |
32 | 35 |
33 FileCallbacks::FileCallbacks( | 36 FileCallbacks::FileCallbacks( |
34 Resource* resource, | 37 Resource* resource, |
35 scoped_refptr<TrackedCallback> callback, | 38 scoped_refptr<TrackedCallback> callback, |
36 PP_FileInfo* info, | 39 maybe_linked_ptr<PP_FileInfo> info, |
37 PP_FileSystemType file_system_type) | 40 PP_FileSystemType file_system_type) |
38 : callback_(callback), | 41 : callback_(callback), |
39 info_(info), | 42 info_(info), |
40 file_system_type_(file_system_type) { | 43 file_system_type_(file_system_type), |
| 44 read_entries_dir_ref_(NULL) { |
| 45 } |
| 46 |
| 47 FileCallbacks::FileCallbacks( |
| 48 ::ppapi::Resource* resource, |
| 49 scoped_refptr< ::ppapi::TrackedCallback> callback, |
| 50 const ReadDirectoryEntriesParams& params) |
| 51 : callback_(callback), |
| 52 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| 53 read_entries_dir_ref_(params.dir_ref), |
| 54 read_entries_files_(params.files), |
| 55 read_entries_file_types_(params.file_types) { |
41 } | 56 } |
42 | 57 |
43 FileCallbacks::~FileCallbacks() {} | 58 FileCallbacks::~FileCallbacks() {} |
44 | 59 |
45 void FileCallbacks::DidSucceed() { | 60 void FileCallbacks::DidSucceed() { |
46 if (callback_->completed()) | 61 if (callback_->completed()) |
47 return; | 62 return; |
48 | 63 |
49 callback_->Run(PP_OK); | 64 callback_->Run(PP_OK); |
50 } | 65 } |
51 | 66 |
52 void FileCallbacks::DidReadMetadata( | 67 void FileCallbacks::DidReadMetadata( |
53 const base::PlatformFileInfo& file_info, | 68 const base::PlatformFileInfo& file_info, |
54 const base::FilePath& unused) { | 69 const base::FilePath& unused) { |
55 if (callback_->completed()) | 70 if (callback_->completed()) |
56 return; | 71 return; |
57 | 72 |
58 DCHECK(info_); | 73 DCHECK(info_.get()); |
59 info_->size = file_info.size; | 74 info_->size = file_info.size; |
60 info_->creation_time = TimeToPPTime(file_info.creation_time); | 75 info_->creation_time = TimeToPPTime(file_info.creation_time); |
61 info_->last_access_time = TimeToPPTime(file_info.last_accessed); | 76 info_->last_access_time = TimeToPPTime(file_info.last_accessed); |
62 info_->last_modified_time = TimeToPPTime(file_info.last_modified); | 77 info_->last_modified_time = TimeToPPTime(file_info.last_modified); |
63 info_->system_type = file_system_type_; | 78 info_->system_type = file_system_type_; |
64 if (file_info.is_directory) | 79 if (file_info.is_directory) |
65 info_->type = PP_FILETYPE_DIRECTORY; | 80 info_->type = PP_FILETYPE_DIRECTORY; |
66 else | 81 else |
67 info_->type = PP_FILETYPE_REGULAR; | 82 info_->type = PP_FILETYPE_REGULAR; |
68 | 83 |
69 callback_->Run(PP_OK); | 84 callback_->Run(PP_OK); |
70 } | 85 } |
71 | 86 |
72 void FileCallbacks::DidCreateSnapshotFile( | 87 void FileCallbacks::DidCreateSnapshotFile( |
73 const base::PlatformFileInfo& file_info, | 88 const base::PlatformFileInfo& file_info, |
74 const base::FilePath& path) { | 89 const base::FilePath& path) { |
75 NOTREACHED(); | 90 NOTREACHED(); |
76 } | 91 } |
77 | 92 |
78 void FileCallbacks::DidReadDirectory( | 93 void FileCallbacks::DidReadDirectory( |
79 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | 94 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
80 NOTREACHED(); | 95 if (callback_->completed()) |
| 96 return; |
| 97 |
| 98 // The current filesystem backend always returns false. |
| 99 DCHECK(!has_more); |
| 100 |
| 101 DCHECK(read_entries_dir_ref_); |
| 102 DCHECK(read_entries_files_.get()); |
| 103 DCHECK(read_entries_file_types_.get()); |
| 104 |
| 105 std::string dir_path = read_entries_dir_ref_->GetCreateInfo().path; |
| 106 if (dir_path[dir_path.size() - 1] != '/') |
| 107 dir_path += '/'; |
| 108 |
| 109 for (size_t i = 0; i < entries.size(); ++i) { |
| 110 const base::FileUtilProxy::Entry& entry = entries[i]; |
| 111 scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal( |
| 112 read_entries_dir_ref_->pp_instance(), |
| 113 read_entries_dir_ref_->file_system_resource(), |
| 114 dir_path + fileapi::FilePathToString(base::FilePath(entry.name)))); |
| 115 read_entries_files_->push_back(file_ref->GetCreateInfo()); |
| 116 read_entries_file_types_->push_back( |
| 117 entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); |
| 118 // Add a ref count on behalf of the plugin side. |
| 119 file_ref->GetReference(); |
| 120 } |
| 121 CHECK_EQ(read_entries_files_->size(), read_entries_file_types_->size()); |
| 122 |
| 123 callback_->Run(PP_OK); |
81 } | 124 } |
82 | 125 |
83 void FileCallbacks::DidOpenFileSystem(const std::string&, | 126 void FileCallbacks::DidOpenFileSystem(const std::string&, |
84 const GURL& root_url) { | 127 const GURL& root_url) { |
85 NOTREACHED(); | 128 NOTREACHED(); |
86 } | 129 } |
87 | 130 |
88 void FileCallbacks::DidFail(base::PlatformFileError error_code) { | 131 void FileCallbacks::DidFail(base::PlatformFileError error_code) { |
89 RunCallback(error_code); | 132 RunCallback(error_code); |
90 } | 133 } |
91 | 134 |
92 void FileCallbacks::DidWrite(int64 bytes, bool complete) { | 135 void FileCallbacks::DidWrite(int64 bytes, bool complete) { |
93 NOTREACHED(); | 136 NOTREACHED(); |
94 } | 137 } |
95 | 138 |
96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { | 139 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { |
97 if (callback_->completed()) | 140 if (callback_->completed()) |
98 return; | 141 return; |
99 | 142 |
100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); | 143 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); |
101 } | 144 } |
102 | 145 |
103 } // namespace ppapi | 146 } // namespace ppapi |
104 } // namespace webkit | 147 } // namespace webkit |
OLD | NEW |