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

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

Issue 10827414: Factor out common Element struct from BlobData and ResourceRequestBody (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: webkit/common -> webkit/base 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_data.cc ('k') | webkit/blob/blob_url_request_job.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 "webkit/blob/blob_data.h" 9 #include "webkit/blob/blob_data.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 memory_usage_ -= target_blob_data->GetMemoryUsage(); 60 memory_usage_ -= target_blob_data->GetMemoryUsage();
61 61
62 // The blob data is stored in the "canonical" way. That is, it only contains a 62 // The blob data is stored in the "canonical" way. That is, it only contains a
63 // list of Data and File items. 63 // list of Data and File items.
64 // 1) The Data item is denoted by the raw data and the range. 64 // 1) The Data item is denoted by the raw data and the range.
65 // 2) The File item is denoted by the file path, the range and the expected 65 // 2) The File item is denoted by the file path, the range and the expected
66 // modification time. 66 // modification time.
67 // All the Blob items in the passing blob data are resolved and expanded into 67 // All the Blob items in the passing blob data are resolved and expanded into
68 // a set of Data and File items. 68 // a set of Data and File items.
69 69
70 DCHECK(item.length > 0); 70 DCHECK(item.length() > 0);
71 switch (item.type) { 71 switch (item.type()) {
72 case BlobData::TYPE_DATA: 72 case BlobData::Item::TYPE_BYTES:
73 // WebBlobData does not allow partial data. 73 DCHECK(!item.offset());
74 DCHECK(!(item.offset) && item.length == item.data.size()); 74 target_blob_data->AppendData(item.bytes(), item.length());
75 target_blob_data->AppendData(item.data.c_str(), item.data.size());
76 break; 75 break;
77 case BlobData::TYPE_DATA_EXTERNAL: 76 case BlobData::Item::TYPE_FILE:
78 DCHECK(!item.offset); 77 AppendFileItem(target_blob_data,
79 target_blob_data->AppendData(item.data_external, item.length); 78 item.path(),
79 item.offset(),
80 item.length(),
81 item.expected_modification_time());
80 break; 82 break;
81 case BlobData::TYPE_FILE: 83 case BlobData::Item::TYPE_BLOB: {
82 AppendFileItem(target_blob_data, 84 BlobData* src_blob_data = GetBlobDataFromUrl(item.url());
83 item.file_path,
84 item.offset,
85 item.length,
86 item.expected_modification_time);
87 break;
88 case BlobData::TYPE_BLOB:
89 BlobData* src_blob_data = GetBlobDataFromUrl(item.blob_url);
90 DCHECK(src_blob_data); 85 DCHECK(src_blob_data);
91 if (src_blob_data) 86 if (src_blob_data)
92 AppendStorageItems(target_blob_data, 87 AppendStorageItems(target_blob_data,
93 src_blob_data, 88 src_blob_data,
94 item.offset, 89 item.offset(),
95 item.length); 90 item.length());
91 break;
92 }
93 default:
94 NOTREACHED();
96 break; 95 break;
97 } 96 }
98 97
99 memory_usage_ += target_blob_data->GetMemoryUsage(); 98 memory_usage_ += target_blob_data->GetMemoryUsage();
100 99
101 // If we're using too much memory, drop this blob. 100 // If we're using too much memory, drop this blob.
102 // TODO(michaeln): Blob memory storage does not yet spill over to disk, 101 // TODO(michaeln): Blob memory storage does not yet spill over to disk,
103 // until it does, we'll prevent memory usage over a max amount. 102 // until it does, we'll prevent memory usage over a max amount.
104 if (memory_usage_ > kMaxMemoryUsage) 103 if (memory_usage_ > kMaxMemoryUsage)
105 RemoveBlob(url); 104 RemoveBlob(url);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void BlobStorageController::AppendStorageItems( 170 void BlobStorageController::AppendStorageItems(
172 BlobData* target_blob_data, BlobData* src_blob_data, 171 BlobData* target_blob_data, BlobData* src_blob_data,
173 uint64 offset, uint64 length) { 172 uint64 offset, uint64 length) {
174 DCHECK(target_blob_data && src_blob_data && 173 DCHECK(target_blob_data && src_blob_data &&
175 length != static_cast<uint64>(-1)); 174 length != static_cast<uint64>(-1));
176 175
177 std::vector<BlobData::Item>::const_iterator iter = 176 std::vector<BlobData::Item>::const_iterator iter =
178 src_blob_data->items().begin(); 177 src_blob_data->items().begin();
179 if (offset) { 178 if (offset) {
180 for (; iter != src_blob_data->items().end(); ++iter) { 179 for (; iter != src_blob_data->items().end(); ++iter) {
181 if (offset >= iter->length) 180 if (offset >= iter->length())
182 offset -= iter->length; 181 offset -= iter->length();
183 else 182 else
184 break; 183 break;
185 } 184 }
186 } 185 }
187 186
188 for (; iter != src_blob_data->items().end() && length > 0; ++iter) { 187 for (; iter != src_blob_data->items().end() && length > 0; ++iter) {
189 uint64 current_length = iter->length - offset; 188 uint64 current_length = iter->length() - offset;
190 uint64 new_length = current_length > length ? length : current_length; 189 uint64 new_length = current_length > length ? length : current_length;
191 if (iter->type == BlobData::TYPE_DATA) { 190 if (iter->type() == BlobData::Item::TYPE_BYTES) {
192 target_blob_data->AppendData( 191 target_blob_data->AppendData(
193 iter->data.c_str() + static_cast<size_t>(iter->offset + offset), 192 iter->bytes() + static_cast<size_t>(iter->offset() + offset),
194 static_cast<uint32>(new_length)); 193 static_cast<uint32>(new_length));
195 } else { 194 } else {
196 DCHECK(iter->type == BlobData::TYPE_FILE); 195 DCHECK(iter->type() == BlobData::Item::TYPE_FILE);
197 AppendFileItem(target_blob_data, 196 AppendFileItem(target_blob_data,
198 iter->file_path, 197 iter->path(),
199 iter->offset + offset, 198 iter->offset() + offset,
200 new_length, 199 new_length,
201 iter->expected_modification_time); 200 iter->expected_modification_time());
202 } 201 }
203 length -= new_length; 202 length -= new_length;
204 offset = 0; 203 offset = 0;
205 } 204 }
206 } 205 }
207 206
208 void BlobStorageController::AppendFileItem( 207 void BlobStorageController::AppendFileItem(
209 BlobData* target_blob_data, 208 BlobData* target_blob_data,
210 const FilePath& file_path, uint64 offset, uint64 length, 209 const FilePath& file_path, uint64 offset, uint64 length,
211 const base::Time& expected_modification_time) { 210 const base::Time& expected_modification_time) {
(...skipping 14 matching lines...) Expand all
226 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) { 225 bool BlobStorageController::DecrementBlobDataUsage(BlobData* blob_data) {
227 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data); 226 BlobDataUsageMap::iterator found = blob_data_usage_count_.find(blob_data);
228 DCHECK(found != blob_data_usage_count_.end()); 227 DCHECK(found != blob_data_usage_count_.end());
229 if (--(found->second)) 228 if (--(found->second))
230 return false; // Still in use 229 return false; // Still in use
231 blob_data_usage_count_.erase(found); 230 blob_data_usage_count_.erase(found);
232 return true; 231 return true;
233 } 232 }
234 233
235 } // namespace webkit_blob 234 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/blob_data.cc ('k') | webkit/blob/blob_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698