| OLD | NEW |
| 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" |
| 10 #include "webkit/glue/webupload_data.h" |
| 11 | 11 |
| 12 namespace webkit_blob { | 12 namespace webkit_blob { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // We can't use GURL directly for these hash fragment manipulations | 16 // We can't use GURL directly for these hash fragment manipulations |
| 17 // since it doesn't have specific knowlege of the BlobURL format. GURL | 17 // 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 | 18 // treats BlobURLs as if they were PathURLs which don't support hash |
| 19 // fragments. | 19 // fragments. |
| 20 | 20 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { | 166 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { |
| 167 BlobMap::iterator found = blob_map_.find( | 167 BlobMap::iterator found = blob_map_.find( |
| 168 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); | 168 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); |
| 169 return (found != blob_map_.end()) ? found->second : NULL; | 169 return (found != blob_map_.end()) ? found->second : NULL; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void BlobStorageController::ResolveBlobReferencesInUploadData( | 172 void BlobStorageController::ResolveBlobReferencesInUploadData( |
| 173 net::UploadData* upload_data) { | 173 WebUploadData* upload_data) { |
| 174 DCHECK(upload_data); | 174 DCHECK(upload_data); |
| 175 | 175 |
| 176 std::vector<net::UploadData::Element>* uploads = | 176 std::vector<WebUploadData::Element>* uploads = |
| 177 upload_data->elements_mutable(); | 177 upload_data->elements_mutable(); |
| 178 std::vector<net::UploadData::Element>::iterator iter; | 178 std::vector<WebUploadData::Element>::iterator iter; |
| 179 for (iter = uploads->begin(); iter != uploads->end();) { | 179 for (iter = uploads->begin(); iter != uploads->end();) { |
| 180 if (iter->type() != net::UploadData::TYPE_BLOB) { | 180 if (iter->type() != WebUploadData::TYPE_BLOB) { |
| 181 iter++; | 181 iter++; |
| 182 continue; | 182 continue; |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Find the referred blob data. | 185 // Find the referred blob data. |
| 186 BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url()); | 186 BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url()); |
| 187 DCHECK(blob_data); | 187 DCHECK(blob_data); |
| 188 if (!blob_data) { | 188 if (!blob_data) { |
| 189 // TODO(jianli): We should probably fail uploading the data | 189 // TODO(jianli): We should probably fail uploading the data |
| 190 iter++; | 190 iter++; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 | 202 |
| 203 // Ensure the blob and any attached shareable files survive until | 203 // Ensure the blob and any attached shareable files survive until |
| 204 // upload completion. | 204 // upload completion. |
| 205 upload_data->SetUserData(blob_data, | 205 upload_data->SetUserData(blob_data, |
| 206 new base::UserDataAdapter<BlobData>(blob_data)); | 206 new base::UserDataAdapter<BlobData>(blob_data)); |
| 207 | 207 |
| 208 // Insert the elements in the referred blob data. | 208 // Insert the elements in the referred blob data. |
| 209 // Note that we traverse from the bottom so that the elements can be | 209 // Note that we traverse from the bottom so that the elements can be |
| 210 // inserted in the original order. | 210 // inserted in the original order. |
| 211 for (size_t i = blob_data->items().size(); i > 0; --i) { | 211 for (size_t i = blob_data->items().size(); i > 0; --i) { |
| 212 iter = uploads->insert(iter, net::UploadData::Element()); | 212 iter = uploads->insert(iter, WebUploadData::Element()); |
| 213 | 213 |
| 214 const BlobData::Item& item = blob_data->items().at(i - 1); | 214 const BlobData::Item& item = blob_data->items().at(i - 1); |
| 215 switch (item.type) { | 215 switch (item.type) { |
| 216 case BlobData::TYPE_DATA: | 216 case BlobData::TYPE_DATA: |
| 217 // TODO(jianli): Figure out how to avoid copying the data. | 217 // TODO(jianli): Figure out how to avoid copying the data. |
| 218 // TODO(michaeln): Now that blob_data surives for the duration, | 218 // TODO(michaeln): Now that blob_data surives for the duration, |
| 219 // maybe UploadData could take a raw ptr without having to copy. | 219 // maybe WebUploadData could take a raw ptr without having to copy. |
| 220 iter->SetToBytes( | 220 iter->SetToBytes( |
| 221 &item.data.at(0) + static_cast<int>(item.offset), | 221 &item.data.at(0) + static_cast<int>(item.offset), |
| 222 static_cast<int>(item.length)); | 222 static_cast<int>(item.length)); |
| 223 break; | 223 break; |
| 224 case BlobData::TYPE_FILE: | 224 case BlobData::TYPE_FILE: |
| 225 iter->SetToFilePathRange( | 225 iter->SetToFilePathRange( |
| 226 item.file_path, | 226 item.file_path, |
| 227 item.offset, | 227 item.offset, |
| 228 item.length, | 228 item.length, |
| 229 item.expected_modification_time); | 229 item.expected_modification_time); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { | 294 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { |
| 295 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); | 295 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); |
| 296 DCHECK(found != blob_data_usage_count_.end()); | 296 DCHECK(found != blob_data_usage_count_.end()); |
| 297 if (--(found->second)) | 297 if (--(found->second)) |
| 298 return false; // Still in use | 298 return false; // Still in use |
| 299 blob_data_usage_count_.erase(found); | 299 blob_data_usage_count_.erase(found); |
| 300 return true; | 300 return true; |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace webkit_blob | 303 } // namespace webkit_blob |
| OLD | NEW |