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

Side by Side Diff: webkit/blob/blob_storage_controller.cc

Issue 10834289: Split net::UploadData into two: for IPC and for upload handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + moved ResolveBlobRef from webkit_blob to webkit_glue Created 8 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
« no previous file with comments | « webkit/blob/blob_storage_controller.h ('k') | webkit/blob/blob_storage_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/blob/blob_storage_controller.h" 5 #include "webkit/blob/blob_storage_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "net/base/upload_data.h"
10 #include "webkit/blob/blob_data.h" 9 #include "webkit/blob/blob_data.h"
11 10
12 namespace webkit_blob { 11 namespace webkit_blob {
13 12
14 namespace { 13 namespace {
15 14
16 // We can't use GURL directly for these hash fragment manipulations 15 // We can't use GURL directly for these hash fragment manipulations
17 // since it doesn't have specific knowlege of the BlobURL format. GURL 16 // since it doesn't have specific knowlege of the BlobURL format. GURL
18 // treats BlobURLs as if they were PathURLs which don't support hash 17 // treats BlobURLs as if they were PathURLs which don't support hash
19 // fragments. 18 // fragments.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return true; 161 return true;
163 } 162 }
164 163
165 164
166 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { 165 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) {
167 BlobMap::iterator found = blob_map_.find( 166 BlobMap::iterator found = blob_map_.find(
168 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); 167 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec());
169 return (found != blob_map_.end()) ? found->second : NULL; 168 return (found != blob_map_.end()) ? found->second : NULL;
170 } 169 }
171 170
172 void BlobStorageController::ResolveBlobReferencesInUploadData(
173 net::UploadData* upload_data) {
174 DCHECK(upload_data);
175
176 std::vector<net::UploadElement>* uploads =
177 upload_data->elements_mutable();
178 std::vector<net::UploadElement>::iterator iter;
179 for (iter = uploads->begin(); iter != uploads->end();) {
180 if (iter->type() != net::UploadElement::TYPE_BLOB) {
181 iter++;
182 continue;
183 }
184
185 // Find the referred blob data.
186 BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url());
187 DCHECK(blob_data);
188 if (!blob_data) {
189 // TODO(jianli): We should probably fail uploading the data
190 iter++;
191 continue;
192 }
193
194 // Remove this element.
195 iter = uploads->erase(iter);
196
197 // If there is no element in the referred blob data, continue the loop.
198 // Note that we should not increase iter since it already points to the one
199 // after the removed element.
200 if (blob_data->items().empty())
201 continue;
202
203 // Ensure the blob and any attached shareable files survive until
204 // upload completion.
205 upload_data->SetUserData(blob_data,
206 new base::UserDataAdapter<BlobData>(blob_data));
207
208 // Insert the elements in the referred blob data.
209 // Note that we traverse from the bottom so that the elements can be
210 // inserted in the original order.
211 for (size_t i = blob_data->items().size(); i > 0; --i) {
212 iter = uploads->insert(iter, net::UploadElement());
213
214 const BlobData::Item& item = blob_data->items().at(i - 1);
215 switch (item.type) {
216 case BlobData::TYPE_DATA:
217 // TODO(jianli): Figure out how to avoid copying the data.
218 // TODO(michaeln): Now that blob_data surives for the duration,
219 // maybe UploadData could take a raw ptr without having to copy.
220 iter->SetToBytes(
221 &item.data.at(0) + static_cast<int>(item.offset),
222 static_cast<int>(item.length));
223 break;
224 case BlobData::TYPE_FILE:
225 iter->SetToFilePathRange(
226 item.file_path,
227 item.offset,
228 item.length,
229 item.expected_modification_time);
230 break;
231 default:
232 NOTREACHED();
233 break;
234 }
235 }
236 }
237 }
238
239 void BlobStorageController::AppendStorageItems( 171 void BlobStorageController::AppendStorageItems(
240 BlobData* target_blob_data, BlobData* src_blob_data, 172 BlobData* target_blob_data, BlobData* src_blob_data,
241 uint64 offset, uint64 length) { 173 uint64 offset, uint64 length) {
242 DCHECK(target_blob_data && src_blob_data && 174 DCHECK(target_blob_data && src_blob_data &&
243 length != static_cast<uint64>(-1)); 175 length != static_cast<uint64>(-1));
244 176
245 std::vector<BlobData::Item>::const_iterator iter = 177 std::vector<BlobData::Item>::const_iterator iter =
246 src_blob_data->items().begin(); 178 src_blob_data->items().begin();
247 if (offset) { 179 if (offset) {
248 for (; iter != src_blob_data->items().end(); ++iter) { 180 for (; iter != src_blob_data->items().end(); ++iter) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { 226 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) {
295 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); 227 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data);
296 DCHECK(found != blob_data_usage_count_.end()); 228 DCHECK(found != blob_data_usage_count_.end());
297 if (--(found->second)) 229 if (--(found->second))
298 return false; // Still in use 230 return false; // Still in use
299 blob_data_usage_count_.erase(found); 231 blob_data_usage_count_.erase(found);
300 return true; 232 return true;
301 } 233 }
302 234
303 } // namespace webkit_blob 235 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/blob_storage_controller.h ('k') | webkit/blob/blob_storage_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698