| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/fileapi/blob_storage_host.h" | 5 #include "content/browser/fileapi/blob_storage_host_impl.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" |
| 11 #include "webkit/browser/blob/blob_storage_context.h" | 11 #include "webkit/browser/blob/blob_storage_context.h" |
| 12 | 12 |
| 13 using webkit_blob::BlobStorageContext; | 13 using webkit_blob::BlobStorageContext; |
| 14 using webkit_blob::BlobData; | 14 using webkit_blob::BlobData; |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 BlobStorageHost::BlobStorageHost(BlobStorageContext* context) | 18 BlobStorageHostImpl::BlobStorageHostImpl(BlobStorageContext* context) |
| 19 : context_(context->AsWeakPtr()) { | 19 : context_(context->AsWeakPtr()) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 BlobStorageHost::~BlobStorageHost() { | 22 BlobStorageHostImpl::~BlobStorageHostImpl() { |
| 23 if (!context_.get()) | 23 if (!context_.get()) |
| 24 return; | 24 return; |
| 25 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); | 25 for (std::set<GURL>::iterator iter = public_blob_urls_.begin(); |
| 26 iter != public_blob_urls_.end(); ++iter) { | 26 iter != public_blob_urls_.end(); ++iter) { |
| 27 context_->RevokePublicBlobURL(*iter); | 27 context_->RevokePublicBlobURL(*iter); |
| 28 } | 28 } |
| 29 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); | 29 for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin(); |
| 30 iter != blobs_inuse_map_.end(); ++iter) { | 30 iter != blobs_inuse_map_.end(); ++iter) { |
| 31 for (int i = 0; i < iter->second; ++i) | 31 for (int i = 0; i < iter->second; ++i) |
| 32 context_->DecrementBlobRefCount(iter->first); | 32 context_->DecrementBlobRefCount(iter->first); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { | 36 bool BlobStorageHostImpl::StartBuildingBlob(const std::string& uuid) { |
| 37 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) | 37 if (!context_.get() || uuid.empty() || context_->IsInUse(uuid)) |
| 38 return false; | 38 return false; |
| 39 context_->StartBuildingBlob(uuid); | 39 context_->StartBuildingBlob(uuid); |
| 40 blobs_inuse_map_[uuid] = 1; | 40 blobs_inuse_map_[uuid] = 1; |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool BlobStorageHost::AppendBlobDataItem( | 44 bool BlobStorageHostImpl::AppendBlobDataItem( |
| 45 const std::string& uuid, const BlobData::Item& data_item) { | 45 const std::string& uuid, const BlobData::Item& data_item) { |
| 46 if (!context_.get() || !IsBeingBuiltInHost(uuid)) | 46 if (!context_.get() || !IsBeingBuiltInHost(uuid)) |
| 47 return false; | 47 return false; |
| 48 context_->AppendBlobDataItem(uuid, data_item); | 48 context_->AppendBlobDataItem(uuid, data_item); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool BlobStorageHost::CancelBuildingBlob(const std::string& uuid) { | 52 bool BlobStorageHostImpl::CancelBuildingBlob(const std::string& uuid) { |
| 53 if (!context_.get() || !IsBeingBuiltInHost(uuid)) | 53 if (!context_.get() || !IsBeingBuiltInHost(uuid)) |
| 54 return false; | 54 return false; |
| 55 blobs_inuse_map_.erase(uuid); | 55 blobs_inuse_map_.erase(uuid); |
| 56 context_->CancelBuildingBlob(uuid); | 56 context_->CancelBuildingBlob(uuid); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool BlobStorageHost::FinishBuildingBlob( | 60 bool BlobStorageHostImpl::FinishBuildingBlob( |
| 61 const std::string& uuid, const std::string& content_type) { | 61 const std::string& uuid, const std::string& content_type) { |
| 62 if (!context_.get() || !IsBeingBuiltInHost(uuid)) | 62 if (!context_.get() || !IsBeingBuiltInHost(uuid)) |
| 63 return false; | 63 return false; |
| 64 context_->FinishBuildingBlob(uuid, content_type); | 64 context_->FinishBuildingBlob(uuid, content_type); |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool BlobStorageHost::IncrementBlobRefCount(const std::string& uuid) { | 68 bool BlobStorageHostImpl::IncrementBlobRefCount(const std::string& uuid) { |
| 69 if (!context_.get() || !context_->IsInUse(uuid) || | 69 if (!context_.get() || !context_->IsInUse(uuid) || |
| 70 context_->IsBeingBuilt(uuid)) | 70 context_->IsBeingBuilt(uuid)) |
| 71 return false; | 71 return false; |
| 72 context_->IncrementBlobRefCount(uuid); | 72 context_->IncrementBlobRefCount(uuid); |
| 73 blobs_inuse_map_[uuid] += 1; | 73 blobs_inuse_map_[uuid] += 1; |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool BlobStorageHost::DecrementBlobRefCount(const std::string& uuid) { | 77 bool BlobStorageHostImpl::DecrementBlobRefCount(const std::string& uuid) { |
| 78 if (!context_.get() || !IsInUseInHost(uuid)) | 78 if (!context_.get() || !IsInUseInHost(uuid)) |
| 79 return false; | 79 return false; |
| 80 context_->DecrementBlobRefCount(uuid); | 80 context_->DecrementBlobRefCount(uuid); |
| 81 blobs_inuse_map_[uuid] -= 1; | 81 blobs_inuse_map_[uuid] -= 1; |
| 82 if (blobs_inuse_map_[uuid] == 0) | 82 if (blobs_inuse_map_[uuid] == 0) |
| 83 blobs_inuse_map_.erase(uuid); | 83 blobs_inuse_map_.erase(uuid); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool BlobStorageHost::RegisterPublicBlobURL( | 87 bool BlobStorageHostImpl::RegisterPublicBlobURL( |
| 88 const GURL& blob_url, const std::string& uuid) { | 88 const GURL& blob_url, const std::string& uuid) { |
| 89 if (!context_.get() || !IsInUseInHost(uuid) || | 89 if (!context_.get() || !IsInUseInHost(uuid) || |
| 90 context_->IsUrlRegistered(blob_url)) | 90 context_->IsUrlRegistered(blob_url)) |
| 91 return false; | 91 return false; |
| 92 context_->RegisterPublicBlobURL(blob_url, uuid); | 92 context_->RegisterPublicBlobURL(blob_url, uuid); |
| 93 public_blob_urls_.insert(blob_url); | 93 public_blob_urls_.insert(blob_url); |
| 94 return true; | 94 return true; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) { | 97 bool BlobStorageHostImpl::RevokePublicBlobURL(const GURL& blob_url) { |
| 98 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) | 98 if (!context_.get() || !IsUrlRegisteredInHost(blob_url)) |
| 99 return false; | 99 return false; |
| 100 context_->RevokePublicBlobURL(blob_url); | 100 context_->RevokePublicBlobURL(blob_url); |
| 101 public_blob_urls_.erase(blob_url); | 101 public_blob_urls_.erase(blob_url); |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { | 105 bool BlobStorageHostImpl::IsInUseInHost(const std::string& uuid) { |
| 106 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); | 106 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { | 109 bool BlobStorageHostImpl::IsBeingBuiltInHost(const std::string& uuid) { |
| 110 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); | 110 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { | 113 bool BlobStorageHostImpl::IsUrlRegisteredInHost(const GURL& blob_url) { |
| 114 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 114 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace content | 117 } // namespace content |
| OLD | NEW |