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) | 31 PP_FileInfo* info) |
28 : callback_(callback), | 32 : callback_(callback), |
29 info_(info), | 33 info_(info), |
30 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { | 34 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
35 read_entries_dir_ref_(NULL), | |
36 read_entries_files_(NULL), | |
37 read_entries_file_types_(NULL) { | |
31 } | 38 } |
32 | 39 |
33 FileCallbacks::FileCallbacks( | 40 FileCallbacks::FileCallbacks( |
34 Resource* resource, | 41 Resource* resource, |
35 scoped_refptr<TrackedCallback> callback, | 42 scoped_refptr<TrackedCallback> callback, |
36 PP_FileInfo* info, | 43 PP_FileInfo* info, |
37 PP_FileSystemType file_system_type) | 44 PP_FileSystemType file_system_type) |
38 : callback_(callback), | 45 : callback_(callback), |
39 info_(info), | 46 info_(info), |
40 file_system_type_(file_system_type) { | 47 file_system_type_(file_system_type), |
48 read_entries_dir_ref_(NULL), | |
49 read_entries_files_(NULL), | |
50 read_entries_file_types_(NULL) { | |
51 } | |
52 | |
53 FileCallbacks::FileCallbacks( | |
54 ::ppapi::Resource* resource, | |
55 scoped_refptr< ::ppapi::TrackedCallback> callback, | |
56 const ReadEntriesParams& params) | |
57 : callback_(callback), | |
58 info_(NULL), | |
59 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | |
60 read_entries_dir_ref_(params.dir_ref), | |
61 read_entries_files_(params.files), | |
62 read_entries_file_types_(params.file_types) { | |
41 } | 63 } |
42 | 64 |
43 FileCallbacks::~FileCallbacks() {} | 65 FileCallbacks::~FileCallbacks() {} |
44 | 66 |
45 void FileCallbacks::DidSucceed() { | 67 void FileCallbacks::DidSucceed() { |
46 if (callback_->completed()) | 68 if (callback_->completed()) |
47 return; | 69 return; |
48 | 70 |
49 callback_->Run(PP_OK); | 71 callback_->Run(PP_OK); |
50 } | 72 } |
(...skipping 19 matching lines...) Expand all Loading... | |
70 } | 92 } |
71 | 93 |
72 void FileCallbacks::DidCreateSnapshotFile( | 94 void FileCallbacks::DidCreateSnapshotFile( |
73 const base::PlatformFileInfo& file_info, | 95 const base::PlatformFileInfo& file_info, |
74 const base::FilePath& path) { | 96 const base::FilePath& path) { |
75 NOTREACHED(); | 97 NOTREACHED(); |
76 } | 98 } |
77 | 99 |
78 void FileCallbacks::DidReadDirectory( | 100 void FileCallbacks::DidReadDirectory( |
79 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | 101 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
80 NOTREACHED(); | 102 if (callback_->completed()) |
103 return; | |
104 | |
105 // The current filesystem backend always returns false. | |
106 DCHECK(!has_more); | |
107 | |
108 DCHECK(read_entries_dir_ref_); | |
109 DCHECK(read_entries_files_); | |
110 DCHECK(read_entries_file_types_); | |
111 | |
112 std::string dir_path = read_entries_dir_ref_->GetCreateInfo().path; | |
113 if (dir_path[dir_path.size() - 1] != '/') | |
palmer
2013/05/03 00:07:24
Could dir_path.size() ever return 0? I would do th
hamaji
2013/05/03 01:10:34
Done. I believe it won't be an empty string, but I
| |
114 dir_path += '/'; | |
115 | |
116 for (size_t i = 0; i < entries.size(); ++i) { | |
117 const base::FileUtilProxy::Entry& entry = entries[i]; | |
118 scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal( | |
119 read_entries_dir_ref_->pp_instance(), | |
120 read_entries_dir_ref_->file_system_resource(), | |
121 dir_path + fileapi::FilePathToString(base::FilePath(entry.name)))); | |
122 read_entries_files_->push_back(file_ref->GetCreateInfo()); | |
123 read_entries_file_types_->push_back( | |
124 entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); | |
125 // Add a ref count on behalf of the plugin side. | |
126 file_ref->GetReference(); | |
127 } | |
128 CHECK_EQ(read_entries_files_->size(), read_entries_file_types_->size()); | |
129 | |
130 callback_->Run(PP_OK); | |
81 } | 131 } |
82 | 132 |
83 void FileCallbacks::DidOpenFileSystem(const std::string&, | 133 void FileCallbacks::DidOpenFileSystem(const std::string&, |
84 const GURL& root_url) { | 134 const GURL& root_url) { |
85 NOTREACHED(); | 135 NOTREACHED(); |
86 } | 136 } |
87 | 137 |
88 void FileCallbacks::DidFail(base::PlatformFileError error_code) { | 138 void FileCallbacks::DidFail(base::PlatformFileError error_code) { |
89 RunCallback(error_code); | 139 RunCallback(error_code); |
90 } | 140 } |
91 | 141 |
92 void FileCallbacks::DidWrite(int64 bytes, bool complete) { | 142 void FileCallbacks::DidWrite(int64 bytes, bool complete) { |
93 NOTREACHED(); | 143 NOTREACHED(); |
94 } | 144 } |
95 | 145 |
96 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { | 146 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { |
97 if (callback_->completed()) | 147 if (callback_->completed()) |
98 return; | 148 return; |
99 | 149 |
100 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); | 150 callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); |
101 } | 151 } |
102 | 152 |
103 } // namespace ppapi | 153 } // namespace ppapi |
104 } // namespace webkit | 154 } // namespace webkit |
OLD | NEW |