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/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" | 9 #include "net/base/upload_data.h" |
10 #include "webkit/blob/blob_data.h" | 10 #include "webkit/blob/blob_data.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 // Remove this element. | 192 // Remove this element. |
193 iter = uploads->erase(iter); | 193 iter = uploads->erase(iter); |
194 | 194 |
195 // If there is no element in the referred blob data, continue the loop. | 195 // If there is no element in the referred blob data, continue the loop. |
196 // Note that we should not increase iter since it already points to the one | 196 // Note that we should not increase iter since it already points to the one |
197 // after the removed element. | 197 // after the removed element. |
198 if (blob_data->items().empty()) | 198 if (blob_data->items().empty()) |
199 continue; | 199 continue; |
200 | 200 |
| 201 // Ensure the blob and any attached shareable files survive until |
| 202 // upload completion. |
| 203 upload_data->SetUserData(blob_data, |
| 204 new base::UserDataAdapter<BlobData>(blob_data)); |
| 205 |
201 // Insert the elements in the referred blob data. | 206 // Insert the elements in the referred blob data. |
202 // Note that we traverse from the bottom so that the elements can be | 207 // Note that we traverse from the bottom so that the elements can be |
203 // inserted in the original order. | 208 // inserted in the original order. |
204 for (size_t i = blob_data->items().size(); i > 0; --i) { | 209 for (size_t i = blob_data->items().size(); i > 0; --i) { |
205 iter = uploads->insert(iter, net::UploadData::Element()); | 210 iter = uploads->insert(iter, net::UploadData::Element()); |
206 | 211 |
207 const BlobData::Item& item = blob_data->items().at(i - 1); | 212 const BlobData::Item& item = blob_data->items().at(i - 1); |
208 switch (item.type) { | 213 switch (item.type) { |
209 case BlobData::TYPE_DATA: | 214 case BlobData::TYPE_DATA: |
210 // TODO(jianli): Figure out how to avoid copying the data. | 215 // TODO(jianli): Figure out how to avoid copying the data. |
| 216 // TODO(michaeln): Now that blob_data surives for the duration, |
| 217 // maybe UploadData could take a raw ptr without having to copy. |
211 iter->SetToBytes( | 218 iter->SetToBytes( |
212 &item.data.at(0) + static_cast<int>(item.offset), | 219 &item.data.at(0) + static_cast<int>(item.offset), |
213 static_cast<int>(item.length)); | 220 static_cast<int>(item.length)); |
214 break; | 221 break; |
215 case BlobData::TYPE_FILE: | 222 case BlobData::TYPE_FILE: |
216 // TODO(michaeln): Ensure that any temp files survive till the | |
217 // net::URLRequest is done with the upload. | |
218 iter->SetToFilePathRange( | 223 iter->SetToFilePathRange( |
219 item.file_path, | 224 item.file_path, |
220 item.offset, | 225 item.offset, |
221 item.length, | 226 item.length, |
222 item.expected_modification_time); | 227 item.expected_modification_time); |
223 break; | 228 break; |
224 default: | 229 default: |
225 NOTREACHED(); | 230 NOTREACHED(); |
226 break; | 231 break; |
227 } | 232 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { | 292 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { |
288 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); | 293 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); |
289 DCHECK(found != blob_data_usage_count_.end()); | 294 DCHECK(found != blob_data_usage_count_.end()); |
290 if (--(found->second)) | 295 if (--(found->second)) |
291 return false; // Still in use | 296 return false; // Still in use |
292 blob_data_usage_count_.erase(found); | 297 blob_data_usage_count_.erase(found); |
293 return true; | 298 return true; |
294 } | 299 } |
295 | 300 |
296 } // namespace webkit_blob | 301 } // namespace webkit_blob |
OLD | NEW |