| 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_host.h" | 5 #include "webkit/browser/blob/blob_storage_host.h" |
| 6 | 6 |
| 7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 #include "webkit/browser/blob/blob_data_handle.h" | 10 #include "webkit/browser/blob/blob_data_handle.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return; | 21 return; |
| 22 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); | 22 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); |
| 23 iter != public_blob_urls_.end(); ++iter) { | 23 iter != public_blob_urls_.end(); ++iter) { |
| 24 context_->RevokePublicBlobURL(*iter); | 24 context_->RevokePublicBlobURL(*iter); |
| 25 } | 25 } |
| 26 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); | 26 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); |
| 27 iter != blobs_inuse_map_.end(); ++iter) { | 27 iter != blobs_inuse_map_.end(); ++iter) { |
| 28 for (int i = 0; i < iter->second; ++i) | 28 for (int i = 0; i < iter->second; ++i) |
| 29 context_->DecrementBlobRefCount(iter->first); | 29 context_->DecrementBlobRefCount(iter->first); |
| 30 } | 30 } |
| 31 for (std::set<GURL>::iterator iter = private_blob_urls_.begin(); | |
| 32 iter != private_blob_urls_.end(); ++iter) { | |
| 33 context_->DeprecatedRevokePrivateBlobURL(*iter); | |
| 34 } | |
| 35 } | 31 } |
| 36 | 32 |
| 37 bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { | 33 bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { |
| 38 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) | 34 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) |
| 39 return false; | 35 return false; |
| 40 context_->StartBuildingBlob(uuid); | 36 context_->StartBuildingBlob(uuid); |
| 41 blobs_inuse_map_[uuid] = 1; | 37 blobs_inuse_map_[uuid] = 1; |
| 42 return true; | 38 return true; |
| 43 } | 39 } |
| 44 | 40 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 92 } |
| 97 | 93 |
| 98 bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) { | 94 bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) { |
| 99 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) | 95 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) |
| 100 return false; | 96 return false; |
| 101 context_->RevokePublicBlobURL(blob_url); | 97 context_->RevokePublicBlobURL(blob_url); |
| 102 public_blob_urls_.erase(blob_url); | 98 public_blob_urls_.erase(blob_url); |
| 103 return true; | 99 return true; |
| 104 } | 100 } |
| 105 | 101 |
| 106 namespace { | |
| 107 bool IsPrivateBlobURL(const GURL& url) { | |
| 108 return StartsWithASCII(url.spec(), "blob:blobinternal", true); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void BlobStorageHost::DeprecatedRegisterBlobURL( | |
| 113 const GURL& private_url, const std::string& uuid) { | |
| 114 DCHECK(IsPrivateBlobURL(private_url)); | |
| 115 if (!context_.get()) | |
| 116 return; | |
| 117 context_->DeprecatedRegisterPrivateBlobURL(private_url, uuid); | |
| 118 private_blob_urls_.insert(private_url); | |
| 119 } | |
| 120 | |
| 121 void BlobStorageHost::DeprecatedCloneBlobURL( | |
| 122 const GURL& url, const GURL& src_private_url) { | |
| 123 // This method is used in two ways. | |
| 124 // 1. During serialization/deserialization to 'clone' an existing blob. | |
| 125 // In this case the src and dest urls are 'private' blob urls. | |
| 126 // 2. To register public blob urls. In this case the dest url is a | |
| 127 // 'public' blob url. | |
| 128 DCHECK(IsPrivateBlobURL(src_private_url)); | |
| 129 if (!context_.get()) | |
| 130 return; | |
| 131 std::string uuid = context_->LookupUuidFromDeprecatedURL(src_private_url); | |
| 132 if (uuid.empty()) | |
| 133 return; | |
| 134 if (IsPrivateBlobURL(url)) { | |
| 135 DeprecatedRegisterBlobURL(url, uuid); | |
| 136 } else { | |
| 137 // Temporarily bump the refcount so the uuid passes the InUse | |
| 138 // check inside the RegisterPublicBlobURL method. | |
| 139 ignore_result(IncrementBlobRefCount(uuid)); | |
| 140 ignore_result(RegisterPublicBlobURL(url, uuid)); | |
| 141 ignore_result(DecrementBlobRefCount(uuid)); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void BlobStorageHost::DeprecatedRevokeBlobURL(const GURL& url) { | |
| 146 if (!context_.get()) | |
| 147 return; | |
| 148 if (IsPrivateBlobURL(url)) { | |
| 149 context_->DeprecatedRevokePrivateBlobURL(url); | |
| 150 private_blob_urls_.erase(url); | |
| 151 } else { | |
| 152 ignore_result(RevokePublicBlobURL(url)); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { | 102 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { |
| 157 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); | 103 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); |
| 158 } | 104 } |
| 159 | 105 |
| 160 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { | 106 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { |
| 161 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); | 107 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); |
| 162 } | 108 } |
| 163 | 109 |
| 164 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { | 110 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { |
| 165 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 111 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 166 } | 112 } |
| 167 | 113 |
| 168 } // namespace webkit_blob | 114 } // namespace webkit_blob |
| OLD | NEW |