| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppb_directory_reader_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 pp_resource(), callback, NULL, NULL, this))) | 97 pp_resource(), callback, NULL, NULL, this))) |
| 98 return PP_ERROR_FAILED; | 98 return PP_ERROR_FAILED; |
| 99 | 99 |
| 100 return PP_OK_COMPLETIONPENDING; | 100 return PP_OK_COMPLETIONPENDING; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void PPB_DirectoryReader_Impl::AddNewEntries( | 103 void PPB_DirectoryReader_Impl::AddNewEntries( |
| 104 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | 104 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
| 105 DCHECK(!entries.empty() || !has_more); | 105 DCHECK(!entries.empty() || !has_more); |
| 106 has_more_ = has_more; | 106 has_more_ = has_more; |
| 107 std::string dir_path = directory_ref_->virtual_path(); | 107 |
| 108 std::string dir_path = directory_ref_->GetCreateInfo().path; |
| 108 if (dir_path[dir_path.size() - 1] != '/') | 109 if (dir_path[dir_path.size() - 1] != '/') |
| 109 dir_path += '/'; | 110 dir_path += '/'; |
| 110 FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path); | 111 FilePath::StringType dir_file_path = UTF8StringToFilePathString(dir_path); |
| 111 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = | 112 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = |
| 112 entries.begin(); it != entries.end(); it++) { | 113 entries.begin(); it != entries.end(); it++) { |
| 113 base::FileUtilProxy::Entry entry; | 114 base::FileUtilProxy::Entry entry; |
| 114 entry.name = dir_file_path + it->name; | 115 entry.name = dir_file_path + it->name; |
| 115 entry.is_directory = it->is_directory; | 116 entry.is_directory = it->is_directory; |
| 116 entries_.push(entry); | 117 entries_.push(entry); |
| 117 } | 118 } |
| 118 | 119 |
| 119 FillUpEntry(); | 120 FillUpEntry(); |
| 120 entry_ = NULL; | 121 entry_ = NULL; |
| 121 } | 122 } |
| 122 | 123 |
| 123 bool PPB_DirectoryReader_Impl::FillUpEntry() { | 124 bool PPB_DirectoryReader_Impl::FillUpEntry() { |
| 124 DCHECK(entry_); | 125 DCHECK(entry_); |
| 125 if (!entries_.empty()) { | 126 if (!entries_.empty()) { |
| 126 base::FileUtilProxy::Entry dir_entry = entries_.front(); | 127 base::FileUtilProxy::Entry dir_entry = entries_.front(); |
| 127 entries_.pop(); | 128 entries_.pop(); |
| 128 if (entry_->file_ref) | 129 if (entry_->file_ref) |
| 129 ResourceTracker::Get()->ReleaseResource(entry_->file_ref); | 130 ResourceTracker::Get()->ReleaseResource(entry_->file_ref); |
| 130 PPB_FileRef_Impl* file_ref = | 131 |
| 131 new PPB_FileRef_Impl(pp_instance(), directory_ref_->file_system(), | 132 PPB_FileRef_Impl* file_ref = PPB_FileRef_Impl::CreateInternal( |
| 132 FilePathStringToUTF8String(dir_entry.name)); | 133 directory_ref_->file_system()->pp_resource(), |
| 134 FilePathStringToUTF8String(dir_entry.name)); |
| 135 if (!file_ref) |
| 136 return false; |
| 133 entry_->file_ref = file_ref->GetReference(); | 137 entry_->file_ref = file_ref->GetReference(); |
| 134 entry_->file_type = | 138 entry_->file_type = |
| 135 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); | 139 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); |
| 136 return true; | 140 return true; |
| 137 } | 141 } |
| 138 | 142 |
| 139 if (!has_more_) { | 143 if (!has_more_) { |
| 140 entry_->file_ref = 0; | 144 entry_->file_ref = 0; |
| 141 return true; | 145 return true; |
| 142 } | 146 } |
| 143 | 147 |
| 144 return false; | 148 return false; |
| 145 } | 149 } |
| 146 | 150 |
| 147 } // namespace ppapi | 151 } // namespace ppapi |
| 148 } // namespace webkit | 152 } // namespace webkit |
| OLD | NEW |