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

Unified Diff: webkit/blob/blob_storage_host.cc

Issue 14139026: New blobstoragecontext for use in the main browser process, not plugged in yet. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/blob/blob_storage_host.h ('k') | webkit/blob/webkit_blob.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/blob/blob_storage_host.cc
===================================================================
--- webkit/blob/blob_storage_host.cc (revision 0)
+++ webkit/blob/blob_storage_host.cc (revision 0)
@@ -0,0 +1,111 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/blob/blob_storage_host.h"
+
+#include "base/sequenced_task_runner.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/blob/blob_data_handle.h"
+#include "webkit/blob/blob_storage_context.h"
+
+namespace webkit_blob {
+
+BlobStorageHost::BlobStorageHost(BlobStorageContext* context)
+ : context_(context->AsWeakPtr()) {
+}
+
+BlobStorageHost::~BlobStorageHost() {
+ if (!context_)
+ return;
+ for (std::set<GURL>::iterator iter = public_blob_urls_.begin();
+ iter != public_blob_urls_.end(); ++iter) {
+ context_->RevokePublicBlobURL(*iter);
+ }
+ for (BlobReferenceMap::iterator iter = blobs_inuse_map_.begin();
+ iter != blobs_inuse_map_.end(); ++iter) {
+ for (int i = 0; i < iter->second; ++i)
+ context_->DecrementBlobRefCount(iter->first);
+ }
+}
+
+bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) {
+ if (!context_ || uuid.empty() || context_->IsInUse(uuid))
+ return false;
+ context_->StartBuildingBlob(uuid);
+ blobs_inuse_map_[uuid] = 1;
+ return true;
+}
+
+bool BlobStorageHost::AppendBlobDataItem(
+ const std::string& uuid, const BlobData::Item& data_item) {
+ if (!context_ || !IsBeingBuiltInHost(uuid))
+ return false;
+ context_->AppendBlobDataItem(uuid, data_item);
+ return true;
+}
+
+bool BlobStorageHost::CancelBuildingBlob(const std::string& uuid) {
+ if (!context_ || !IsBeingBuiltInHost(uuid))
+ return false;
+ blobs_inuse_map_.erase(uuid);
+ context_->CancelBuildingBlob(uuid);
+ return true;
+}
+
+bool BlobStorageHost::FinishBuildingBlob(
+ const std::string& uuid, const std::string& content_type) {
+ if (!context_ || !IsBeingBuiltInHost(uuid))
+ return false;
+ context_->FinishBuildingBlob(uuid, content_type);
+ return true;
+}
+
+bool BlobStorageHost::IncrementBlobRefCount(const std::string& uuid) {
+ if (!context_ || !context_->IsInUse(uuid) || context_->IsBeingBuilt(uuid))
+ return false;
+ context_->IncrementBlobRefCount(uuid);
+ blobs_inuse_map_[uuid] += 1;
+ return true;
+}
+
+bool BlobStorageHost::DecrementBlobRefCount(const std::string& uuid) {
+ if (!context_ || !IsInUseInHost(uuid))
+ return false;
+ context_->DecrementBlobRefCount(uuid);
+ blobs_inuse_map_[uuid] -= 1;
+ if (blobs_inuse_map_[uuid] == 0)
+ blobs_inuse_map_.erase(uuid);
+ return true;
+}
+
+bool BlobStorageHost::RegisterPublicBlobURL(
+ const GURL& blob_url, const std::string& uuid) {
+ if (!context_ || !IsInUseInHost(uuid) || context_->IsUrlRegistered(blob_url))
+ return false;
+ context_->RegisterPublicBlobURL(blob_url, uuid);
+ public_blob_urls_.insert(blob_url);
+ return true;
+}
+
+bool BlobStorageHost::RevokePublicBlobURL(const GURL& blob_url) {
+ if (!context_ || !IsUrlRegisteredInHost(blob_url))
+ return false;
+ context_->RevokePublicBlobURL(blob_url);
+ public_blob_urls_.erase(blob_url);
+ return true;
+}
+
+bool BlobStorageHost::IsInUseInHost(const std::string& uuid) {
+ return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end();
+}
+
+bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) {
+ return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid);
+}
+
+bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) {
+ return public_blob_urls_.find(blob_url) != public_blob_urls_.end();
+}
+
+} // namespace webkit_blob
Property changes on: webkit\blob\blob_storage_host.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « webkit/blob/blob_storage_host.h ('k') | webkit/blob/webkit_blob.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698