Chromium Code Reviews| 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 "url/gurl.h" | 9 #include "url/gurl.h" |
| 9 #include "webkit/browser/blob/blob_data_handle.h" | 10 #include "webkit/browser/blob/blob_data_handle.h" |
| 10 #include "webkit/browser/blob/blob_storage_context.h" | 11 #include "webkit/browser/blob/blob_storage_context.h" |
| 11 | 12 |
| 12 namespace webkit_blob { | 13 namespace webkit_blob { |
| 13 | 14 |
| 14 BlobStorageHost::BlobStorageHost(BlobStorageContext* context) | 15 BlobStorageHost::BlobStorageHost(BlobStorageContext* context) |
| 15 : context_(context->AsWeakPtr()) { | 16 : context_(context->AsWeakPtr()) { |
| 16 } | 17 } |
| 17 | 18 |
| 18 BlobStorageHost::~BlobStorageHost() { | 19 BlobStorageHost::~BlobStorageHost() { |
| 19 if (!context_.get()) | 20 if (!context_.get()) |
| 20 return; | 21 return; |
| 21 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); | 22 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); |
| 22 iter != public_blob_urls_.end(); ++iter) { | 23 iter != public_blob_urls_.end(); ++iter) { |
| 23 context_->RevokePublicBlobURL(*iter); | 24 context_->RevokePublicBlobURL(*iter); |
| 24 } | 25 } |
| 25 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); | 26 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); |
| 26 iter != blobs_inuse_map_.end(); ++iter) { | 27 iter != blobs_inuse_map_.end(); ++iter) { |
| 27 for (int i = 0; i < iter->second; ++i) | 28 for (int i = 0; i < iter->second; ++i) |
| 28 context_->DecrementBlobRefCount(iter->first); | 29 context_->DecrementBlobRefCount(iter->first); |
| 29 } | 30 } |
| 31 for (std::set<GURL>::iterator iter = private_blob_urls_.begin(); | |
| 32 iter != private_blob_urls_.end(); ++iter) { | |
| 33 context_->DeprecatedRevokePrivateBlobURL(*iter); | |
| 34 } | |
| 30 } | 35 } |
| 31 | 36 |
| 32 bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { | 37 bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { |
| 33 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) | 38 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) |
| 34 return false; | 39 return false; |
| 35 context_->StartBuildingBlob(uuid); | 40 context_->StartBuildingBlob(uuid); |
| 36 blobs_inuse_map_[uuid] = 1; | 41 blobs_inuse_map_[uuid] = 1; |
| 37 return true; | 42 return true; |
| 38 } | 43 } |
| 39 | 44 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 } | 96 } |
| 92 | 97 |
| 93 bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) { | 98 bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) { |
| 94 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) | 99 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) |
| 95 return false; | 100 return false; |
| 96 context_->RevokePublicBlobURL(blob_url); | 101 context_->RevokePublicBlobURL(blob_url); |
| 97 public_blob_urls_.erase(blob_url); | 102 public_blob_urls_.erase(blob_url); |
| 98 return true; | 103 return true; |
| 99 } | 104 } |
| 100 | 105 |
| 106 namespace { | |
| 107 bool IsPrivateBlobURL(const GURL& url) { | |
|
darin (slow to review)
2013/08/30 19:55:32
nit: I usually recommend putting small helper func
michaeln
2013/08/30 21:08:43
i usually like that too, but i want to delete this
| |
| 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 | |
| 101 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { | 156 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { |
| 102 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); | 157 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); |
| 103 } | 158 } |
| 104 | 159 |
| 105 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { | 160 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { |
| 106 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); | 161 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); |
| 107 } | 162 } |
| 108 | 163 |
| 109 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { | 164 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { |
| 110 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 165 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 111 } | 166 } |
| 112 | 167 |
| 113 } // namespace webkit_blob | 168 } // namespace webkit_blob |
| OLD | NEW |