Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webkit/plugins/ppapi/ppb_directory_reader_impl.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 PPB_DirectoryReader_Impl::~PPB_DirectoryReader_Impl() { 62 PPB_DirectoryReader_Impl::~PPB_DirectoryReader_Impl() {
63 } 63 }
64 64
65 // static 65 // static
66 PP_Resource PPB_DirectoryReader_Impl::Create(PP_Resource directory_ref) { 66 PP_Resource PPB_DirectoryReader_Impl::Create(PP_Resource directory_ref) {
67 EnterResourceNoLock<PPB_FileRef_API> enter(directory_ref, true); 67 EnterResourceNoLock<PPB_FileRef_API> enter(directory_ref, true);
68 if (enter.failed()) 68 if (enter.failed())
69 return 0; 69 return 0;
70 70 return (new PPB_DirectoryReader_Impl(
71 PPB_DirectoryReader_Impl* reader = new PPB_DirectoryReader_Impl( 71 static_cast<PPB_FileRef_Impl*>(enter.object())))->GetReference();
72 static_cast<PPB_FileRef_Impl*>(enter.object()));
73 return reader->GetReference();
74 } 72 }
75 73
76 PPB_DirectoryReader_API* PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_API() { 74 PPB_DirectoryReader_API* PPB_DirectoryReader_Impl::AsPPB_DirectoryReader_API() {
77 return this; 75 return this;
78 } 76 }
79 77
80 int32_t PPB_DirectoryReader_Impl::GetNextEntry( 78 int32_t PPB_DirectoryReader_Impl::GetNextEntry(
81 PP_DirectoryEntry_Dev* entry, 79 PP_DirectoryEntry_Dev* entry,
82 PP_CompletionCallback callback) { 80 PP_CompletionCallback callback) {
83 if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) 81 if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL)
84 return PP_ERROR_FAILED; 82 return PP_ERROR_FAILED;
85 83
86 entry_ = entry; 84 entry_ = entry;
87 if (FillUpEntry()) { 85 if (FillUpEntry()) {
88 entry_ = NULL; 86 entry_ = NULL;
89 return PP_OK; 87 return PP_OK;
90 } 88 }
91 89
92 PluginInstance* instance = directory_ref_->instance(); 90 PluginInstance* instance = directory_ref_->instance();
93 PP_Resource resource_id = GetReferenceNoAddRef();
94 DCHECK(resource_id != 0);
95 if (!instance->delegate()->ReadDirectory( 91 if (!instance->delegate()->ReadDirectory(
96 directory_ref_->GetFileSystemURL(), 92 directory_ref_->GetFileSystemURL(),
97 new FileCallbacks(instance->module()->AsWeakPtr(), 93 new FileCallbacks(instance->module()->AsWeakPtr(),
98 resource_id, 94 pp_resource(), callback, NULL, NULL, this)))
99 callback, NULL, NULL, this)))
100 return PP_ERROR_FAILED; 95 return PP_ERROR_FAILED;
101 96
102 return PP_OK_COMPLETIONPENDING; 97 return PP_OK_COMPLETIONPENDING;
103 } 98 }
104 99
105 void PPB_DirectoryReader_Impl::AddNewEntries( 100 void PPB_DirectoryReader_Impl::AddNewEntries(
106 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { 101 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) {
107 DCHECK(!entries.empty() || !has_more); 102 DCHECK(!entries.empty() || !has_more);
108 has_more_ = has_more; 103 has_more_ = has_more;
109 std::string dir_path = directory_ref_->virtual_path(); 104 std::string dir_path = directory_ref_->virtual_path();
(...skipping 11 matching lines...) Expand all
121 FillUpEntry(); 116 FillUpEntry();
122 entry_ = NULL; 117 entry_ = NULL;
123 } 118 }
124 119
125 bool PPB_DirectoryReader_Impl::FillUpEntry() { 120 bool PPB_DirectoryReader_Impl::FillUpEntry() {
126 DCHECK(entry_); 121 DCHECK(entry_);
127 if (!entries_.empty()) { 122 if (!entries_.empty()) {
128 base::FileUtilProxy::Entry dir_entry = entries_.front(); 123 base::FileUtilProxy::Entry dir_entry = entries_.front();
129 entries_.pop(); 124 entries_.pop();
130 if (entry_->file_ref) 125 if (entry_->file_ref)
131 ResourceTracker::Get()->UnrefResource(entry_->file_ref); 126 ResourceTracker::Get()->ReleaseResource(entry_->file_ref);
132 PPB_FileRef_Impl* file_ref = 127 PPB_FileRef_Impl* file_ref =
133 new PPB_FileRef_Impl(instance(), directory_ref_->file_system(), 128 new PPB_FileRef_Impl(instance(), directory_ref_->file_system(),
134 FilePathStringToUTF8String(dir_entry.name)); 129 FilePathStringToUTF8String(dir_entry.name));
135 entry_->file_ref = file_ref->GetReference(); 130 entry_->file_ref = file_ref->GetReference();
136 entry_->file_type = 131 entry_->file_type =
137 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); 132 (dir_entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR);
138 return true; 133 return true;
139 } 134 }
140 135
141 if (!has_more_) { 136 if (!has_more_) {
142 entry_->file_ref = 0; 137 entry_->file_ref = 0;
143 return true; 138 return true;
144 } 139 }
145 140
146 return false; 141 return false;
147 } 142 }
148 143
149 } // namespace ppapi 144 } // namespace ppapi
150 } // namespace webkit 145 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698