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