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

Side by Side Diff: webkit/browser/blob/blob_storage_host.cc

Issue 23223003: Chromium Blob hacking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) {
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 ignore_result(IncrementBlobRefCount(uuid));
138 ignore_result(RegisterPublicBlobURL(url, uuid));
139 ignore_result(DecrementBlobRefCount(uuid));
kinuko 2013/08/28 17:24:31 I'm lost here... do we need to surround RegisterPu
michaeln 2013/08/28 20:21:34 Sorry for the confusion. Yes it is needed, but not
kinuko 2013/08/29 02:33:03 I see, thanks for the explanation. Could you note
140 }
141 }
142
143 void BlobStorageHost::DeprecatedRevokeBlobURL(const GURL& url) {
144 if (!context_.get())
145 return;
146 if (IsPrivateBlobURL(url)) {
147 context_->DeprecatedRevokePrivateBlobURL(url);
148 private_blob_urls_.erase(url);
149 } else {
150 ignore_result(RevokePublicBlobURL(url));
151 }
152 }
153
101 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) { 154 bool BlobStorageHost::IsInUseInHost(const std::string& uuid) {
102 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); 155 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end();
103 } 156 }
104 157
105 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) { 158 bool BlobStorageHost::IsBeingBuiltInHost(const std::string& uuid) {
106 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid); 159 return IsInUseInHost(uuid) && context_->IsBeingBuilt(uuid);
107 } 160 }
108 161
109 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) { 162 bool BlobStorageHost::IsUrlRegisteredInHost(const GURL& blob_url) {
110 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); 163 return public_blob_urls_.find(blob_url) != public_blob_urls_.end();
111 } 164 }
112 165
113 } // namespace webkit_blob 166 } // namespace webkit_blob
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698