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 19 matching lines...) Expand all Loading... | |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 BlobStorageController::BlobStorageController() { | 34 BlobStorageController::BlobStorageController() { |
35 } | 35 } |
36 | 36 |
37 BlobStorageController::~BlobStorageController() { | 37 BlobStorageController::~BlobStorageController() { |
38 } | 38 } |
39 | 39 |
40 void BlobStorageController::RegisterBlobUrl( | 40 void BlobStorageController::RegisterUnfinalizedBlobUrl(const GURL& url) { |
41 const GURL& url, const BlobData* blob_data) { | |
42 DCHECK(url.SchemeIs("blob")); | 41 DCHECK(url.SchemeIs("blob")); |
43 DCHECK(!BlobUrlHasRef(url)); | 42 DCHECK(!BlobUrlHasRef(url)); |
43 unfinalized_blob_map_[url.spec()] = new BlobData(); | |
44 } | |
44 | 45 |
45 scoped_refptr<BlobData> target_blob_data(new BlobData()); | 46 void BlobStorageController::AppendBlobDataItem( |
46 target_blob_data->set_content_type(blob_data->content_type()); | 47 const GURL& url, const webkit_blob::BlobData::Item& item) { |
47 target_blob_data->set_content_disposition(blob_data->content_disposition()); | 48 DCHECK(url.SchemeIs("blob")); |
49 DCHECK(!BlobUrlHasRef(url)); | |
50 BlobMap::iterator found = unfinalized_blob_map_.find(url.spec()); | |
51 if (found == unfinalized_blob_map_.end()) | |
52 return; | |
53 BlobData* target_blob_data = found->second; | |
54 DCHECK(target_blob_data); | |
48 | 55 |
49 // The blob data is stored in the "canonical" way. That is, it only contains a | 56 // The blob data is stored in the "canonical" way. That is, it only contains a |
50 // list of Data and File items. | 57 // list of Data and File items. |
51 // 1) The Data item is denoted by the raw data and the range. | 58 // 1) The Data item is denoted by the raw data and the range. |
52 // 2) The File item is denoted by the file path, the range and the expected | 59 // 2) The File item is denoted by the file path, the range and the expected |
53 // modification time. | 60 // modification time. |
54 // All the Blob items in the passing blob data are resolved and expanded into | 61 // All the Blob items in the passing blob data are resolved and expanded into |
55 // a set of Data and File items. | 62 // a set of Data and File items. |
56 | 63 |
57 for (std::vector<BlobData::Item>::const_iterator iter = | 64 switch (item.type()) { |
58 blob_data->items().begin(); | 65 case BlobData::TYPE_DATA: |
59 iter != blob_data->items().end(); ++iter) { | 66 // WebBlobData does not allow partial data. |
60 switch (iter->type()) { | 67 DCHECK(!(item.offset()) && item.length() == item.data().size()); |
61 case BlobData::TYPE_DATA: { | 68 target_blob_data->AppendData(item.data()); |
michaeln
2011/09/22 22:59:26
Since there's no spilling over to disk if things g
| |
62 // WebBlobData does not allow partial data. | 69 break; |
63 DCHECK(!(iter->offset()) && iter->length() == iter->data().size()); | 70 case BlobData::TYPE_FILE: |
64 target_blob_data->AppendData(iter->data()); | 71 AppendFileItem(target_blob_data, |
65 break; | 72 item.file_path(), |
66 } | 73 item.offset(), |
67 case BlobData::TYPE_FILE: | 74 item.length(), |
68 AppendFileItem(target_blob_data, | 75 item.expected_modification_time()); |
69 iter->file_path(), | 76 break; |
70 iter->offset(), | 77 case BlobData::TYPE_BLOB: |
71 iter->length(), | 78 BlobData* src_blob_data = GetBlobDataFromUrl(item.blob_url()); |
72 iter->expected_modification_time()); | 79 DCHECK(src_blob_data); |
73 break; | 80 if (src_blob_data) |
74 case BlobData::TYPE_BLOB: { | 81 AppendStorageItems(target_blob_data, |
75 BlobData* src_blob_data = GetBlobDataFromUrl(iter->blob_url()); | 82 src_blob_data, |
76 DCHECK(src_blob_data); | 83 item.offset(), |
77 if (src_blob_data) | 84 item.length()); |
78 AppendStorageItems(target_blob_data.get(), | 85 break; |
79 src_blob_data, | |
80 iter->offset(), | |
81 iter->length()); | |
82 break; | |
83 } | |
84 } | |
85 } | 86 } |
87 } | |
86 | 88 |
87 blob_map_[url.spec()] = target_blob_data; | 89 void BlobStorageController::FinalizeBlob( |
90 const GURL& url, const std::string& content_type) { | |
91 DCHECK(url.SchemeIs("blob")); | |
92 DCHECK(!BlobUrlHasRef(url)); | |
93 BlobMap::iterator found = unfinalized_blob_map_.find(url.spec()); | |
94 if (found == unfinalized_blob_map_.end()) | |
95 return; | |
96 found->second->set_content_type(content_type); | |
97 blob_map_[url.spec()] = found->second; | |
98 unfinalized_blob_map_.erase(found); | |
88 } | 99 } |
89 | 100 |
90 void BlobStorageController::RegisterBlobUrlFrom( | 101 void BlobStorageController::RegisterBlobUrlFrom( |
91 const GURL& url, const GURL& src_url) { | 102 const GURL& url, const GURL& src_url) { |
92 DCHECK(url.SchemeIs("blob")); | 103 DCHECK(url.SchemeIs("blob")); |
93 DCHECK(!BlobUrlHasRef(url)); | 104 DCHECK(!BlobUrlHasRef(url)); |
94 | 105 |
95 BlobData* blob_data = GetBlobDataFromUrl(src_url); | 106 BlobData* blob_data = GetBlobDataFromUrl(src_url); |
96 DCHECK(blob_data); | 107 DCHECK(blob_data); |
97 if (!blob_data) | 108 if (!blob_data) |
98 return; | 109 return; |
99 | 110 |
100 blob_map_[url.spec()] = blob_data; | 111 blob_map_[url.spec()] = blob_data; |
101 } | 112 } |
102 | 113 |
103 void BlobStorageController::UnregisterBlobUrl(const GURL& url) { | 114 void BlobStorageController::UnregisterBlobUrl(const GURL& url) { |
115 DCHECK(url.SchemeIs("blob")); | |
116 DCHECK(!BlobUrlHasRef(url)); | |
104 blob_map_.erase(url.spec()); | 117 blob_map_.erase(url.spec()); |
118 unfinalized_blob_map_.erase(url.spec()); | |
105 } | 119 } |
106 | 120 |
107 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { | 121 BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { |
108 BlobMap::iterator found = blob_map_.find( | 122 BlobMap::iterator found = blob_map_.find( |
109 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); | 123 BlobUrlHasRef(url) ? ClearBlobUrlRef(url).spec() : url.spec()); |
110 return (found != blob_map_.end()) ? found->second : NULL; | 124 return (found != blob_map_.end()) ? found->second : NULL; |
111 } | 125 } |
112 | 126 |
113 void BlobStorageController::ResolveBlobReferencesInUploadData( | 127 void BlobStorageController::ResolveBlobReferencesInUploadData( |
114 net::UploadData* upload_data) { | 128 net::UploadData* upload_data) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 expected_modification_time); | 230 expected_modification_time); |
217 | 231 |
218 // It may be a temporary file that should be deleted when no longer needed. | 232 // It may be a temporary file that should be deleted when no longer needed. |
219 scoped_refptr<DeletableFileReference> deletable_file = | 233 scoped_refptr<DeletableFileReference> deletable_file = |
220 DeletableFileReference::Get(file_path); | 234 DeletableFileReference::Get(file_path); |
221 if (deletable_file) | 235 if (deletable_file) |
222 target_blob_data->AttachDeletableFileReference(deletable_file); | 236 target_blob_data->AttachDeletableFileReference(deletable_file); |
223 } | 237 } |
224 | 238 |
225 } // namespace webkit_blob | 239 } // namespace webkit_blob |
OLD | NEW |