| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser/blob/blob_storage_context.h" | 5 #include "webkit/browser/blob/blob_storage_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { | 109 void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { |
| 110 DCHECK(!BlobUrlHasRef(blob_url)); | 110 DCHECK(!BlobUrlHasRef(blob_url)); |
| 111 if (!IsUrlRegistered(blob_url)) | 111 if (!IsUrlRegistered(blob_url)) |
| 112 return; | 112 return; |
| 113 DecrementBlobRefCount(public_blob_urls_[blob_url]); | 113 DecrementBlobRefCount(public_blob_urls_[blob_url]); |
| 114 public_blob_urls_.erase(blob_url); | 114 public_blob_urls_.erase(blob_url); |
| 115 } | 115 } |
| 116 | 116 |
| 117 std::string BlobStorageContext::LookupUuidFromDeprecatedURL( | |
| 118 const GURL& url) { | |
| 119 BlobURLMap::const_iterator found = deprecated_blob_urls_.find(url); | |
| 120 if (found == deprecated_blob_urls_.end()) | |
| 121 return std::string(); | |
| 122 return found->second; | |
| 123 } | |
| 124 | |
| 125 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { | 117 void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { |
| 126 DCHECK(!IsInUse(uuid) && !uuid.empty()); | 118 DCHECK(!IsInUse(uuid) && !uuid.empty()); |
| 127 blob_map_[uuid] = BlobMapEntry(1, BEING_BUILT, new BlobData(uuid)); | 119 blob_map_[uuid] = BlobMapEntry(1, BEING_BUILT, new BlobData(uuid)); |
| 128 } | 120 } |
| 129 | 121 |
| 130 void BlobStorageContext::AppendBlobDataItem( | 122 void BlobStorageContext::AppendBlobDataItem( |
| 131 const std::string& uuid, const BlobData::Item& item) { | 123 const std::string& uuid, const BlobData::Item& item) { |
| 132 DCHECK(IsBeingBuilt(uuid)); | 124 DCHECK(IsBeingBuilt(uuid)); |
| 133 BlobMap::iterator found = blob_map_.find(uuid); | 125 BlobMap::iterator found = blob_map_.find(uuid); |
| 134 if (found == blob_map_.end()) | 126 if (found == blob_map_.end()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 item.expected_modification_time()); | 159 item.expected_modification_time()); |
| 168 break; | 160 break; |
| 169 case BlobData::Item::TYPE_FILE_FILESYSTEM: | 161 case BlobData::Item::TYPE_FILE_FILESYSTEM: |
| 170 AppendFileSystemFileItem(target_blob_data, | 162 AppendFileSystemFileItem(target_blob_data, |
| 171 item.filesystem_url(), | 163 item.filesystem_url(), |
| 172 item.offset(), | 164 item.offset(), |
| 173 item.length(), | 165 item.length(), |
| 174 item.expected_modification_time()); | 166 item.expected_modification_time()); |
| 175 break; | 167 break; |
| 176 case BlobData::Item::TYPE_BLOB: { | 168 case BlobData::Item::TYPE_BLOB: { |
| 177 scoped_ptr<BlobDataHandle> src = GetBlobDataFromUUID( | 169 scoped_ptr<BlobDataHandle> src = GetBlobDataFromUUID(item.blob_uuid()); |
| 178 item.blob_uuid().empty() | |
| 179 ? LookupUuidFromDeprecatedURL(item.blob_url()) | |
| 180 : item.blob_uuid()); | |
| 181 if (src) | 170 if (src) |
| 182 exceeded_memory = !ExpandStorageItems(target_blob_data, | 171 exceeded_memory = !ExpandStorageItems(target_blob_data, |
| 183 src->data(), | 172 src->data(), |
| 184 item.offset(), | 173 item.offset(), |
| 185 item.length()); | 174 item.length()); |
| 186 break; | 175 break; |
| 187 } | 176 } |
| 188 default: | 177 default: |
| 189 NOTREACHED(); | 178 NOTREACHED(); |
| 190 break; | 179 break; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 BlobMap::iterator found = blob_map_.find(uuid); | 218 BlobMap::iterator found = blob_map_.find(uuid); |
| 230 if (found == blob_map_.end()) | 219 if (found == blob_map_.end()) |
| 231 return; | 220 return; |
| 232 DCHECK_EQ(found->second.data->uuid(), uuid); | 221 DCHECK_EQ(found->second.data->uuid(), uuid); |
| 233 if (--(found->second.refcount) == 0) { | 222 if (--(found->second.refcount) == 0) { |
| 234 memory_usage_ -= found->second.data->GetMemoryUsage(); | 223 memory_usage_ -= found->second.data->GetMemoryUsage(); |
| 235 blob_map_.erase(found); | 224 blob_map_.erase(found); |
| 236 } | 225 } |
| 237 } | 226 } |
| 238 | 227 |
| 239 void BlobStorageContext::DeprecatedRegisterPrivateBlobURL( | |
| 240 const GURL& url, const std::string& uuid) { | |
| 241 if (!IsInUse(uuid)) | |
| 242 return; | |
| 243 IncrementBlobRefCount(uuid); | |
| 244 deprecated_blob_urls_[url] = uuid; | |
| 245 } | |
| 246 | |
| 247 void BlobStorageContext::DeprecatedRevokePrivateBlobURL(const GURL& url) { | |
| 248 if (deprecated_blob_urls_.find(url) == deprecated_blob_urls_.end()) | |
| 249 return; | |
| 250 DecrementBlobRefCount(deprecated_blob_urls_[url]); | |
| 251 deprecated_blob_urls_.erase(url); | |
| 252 } | |
| 253 | |
| 254 bool BlobStorageContext::ExpandStorageItems( | 228 bool BlobStorageContext::ExpandStorageItems( |
| 255 BlobData* target_blob_data, BlobData* src_blob_data, | 229 BlobData* target_blob_data, BlobData* src_blob_data, |
| 256 uint64 offset, uint64 length) { | 230 uint64 offset, uint64 length) { |
| 257 DCHECK(target_blob_data && src_blob_data && | 231 DCHECK(target_blob_data && src_blob_data && |
| 258 length != static_cast<uint64>(-1)); | 232 length != static_cast<uint64>(-1)); |
| 259 | 233 |
| 260 std::vector<BlobData::Item>::const_iterator iter = | 234 std::vector<BlobData::Item>::const_iterator iter = |
| 261 src_blob_data->items().begin(); | 235 src_blob_data->items().begin(); |
| 262 if (offset) { | 236 if (offset) { |
| 263 for (; iter != src_blob_data->items().end(); ++iter) { | 237 for (; iter != src_blob_data->items().end(); ++iter) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 if (found == blob_map_.end()) | 316 if (found == blob_map_.end()) |
| 343 return false; | 317 return false; |
| 344 return found->second.flags & BEING_BUILT; | 318 return found->second.flags & BEING_BUILT; |
| 345 } | 319 } |
| 346 | 320 |
| 347 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { | 321 bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { |
| 348 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 322 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 349 } | 323 } |
| 350 | 324 |
| 351 } // namespace webkit_blob | 325 } // namespace webkit_blob |
| OLD | NEW |