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

Side by Side Diff: Source/core/fileapi/BlobRegistry.cpp

Issue 23992003: blob hacking webcore style (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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
« no previous file with comments | « Source/core/fileapi/BlobRegistry.h ('k') | Source/core/fileapi/BlobURL.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 KURL url; 98 KURL url;
99 KURL srcURL; 99 KURL srcURL;
100 OwnPtr<BlobData> blobData; 100 OwnPtr<BlobData> blobData;
101 PassRefPtr<RawData> streamData; 101 PassRefPtr<RawData> streamData;
102 String type; 102 String type;
103 }; 103 };
104 104
105 static WebBlobRegistry* blobRegistry() 105 static WebBlobRegistry* blobRegistry()
106 { 106 {
107 ASSERT(isMainThread());
108 return WebKit::Platform::current()->blobRegistry(); 107 return WebKit::Platform::current()->blobRegistry();
109 } 108 }
110 109
111 typedef HashMap<String, RefPtr<SecurityOrigin> > BlobURLOriginMap; 110 typedef HashMap<String, RefPtr<SecurityOrigin> > BlobURLOriginMap;
112 static ThreadSpecific<BlobURLOriginMap>& originMap() 111 static ThreadSpecific<BlobURLOriginMap>& originMap()
113 { 112 {
114 // We want to create the BlobOriginCache exactly once because it is shared b y all the threads. 113 // We want to create the BlobOriginCache exactly once because it is shared b y all the threads.
115 AtomicallyInitializedStatic(BlobOriginCache*, cache = new BlobOriginCache); 114 AtomicallyInitializedStatic(BlobOriginCache*, cache = new BlobOriginCache);
116 115
117 AtomicallyInitializedStatic(ThreadSpecific<BlobURLOriginMap>*, map = new Thr eadSpecific<BlobURLOriginMap>); 116 AtomicallyInitializedStatic(ThreadSpecific<BlobURLOriginMap>*, map = new Thr eadSpecific<BlobURLOriginMap>);
118 return *map; 117 return *map;
119 } 118 }
120 119
121 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url) 120 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url)
122 { 121 {
123 // If the blob URL contains null origin, as in the context with unique 122 // If the blob URL contains null origin, as in the context with unique
124 // security origin or file URL, save the mapping between url and origin so 123 // security origin or file URL, save the mapping between url and origin so
125 // that the origin can be retrived when doing security origin check. 124 // that the origin can be retrived when doing security origin check.
126 if (origin && BlobURL::getOrigin(url) == "null") 125 if (origin && BlobURL::getOrigin(url) == "null")
127 originMap()->add(url.string(), origin); 126 originMap()->add(url.string(), origin);
128 } 127 }
129 128
130 static void removeFromOriginMap(const KURL& url) 129 static void removeFromOriginMap(const KURL& url)
131 { 130 {
132 if (BlobURL::getOrigin(url) == "null") 131 if (BlobURL::getOrigin(url) == "null")
133 originMap()->remove(url.string()); 132 originMap()->remove(url.string());
134 } 133 }
135 134
136 static void registerBlobURLTask(void* context) 135 void BlobRegistry::registerBlobData(const String& uuid, PassOwnPtr<BlobData> dat a)
137 { 136 {
138 OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobR egistryContext*>(context)); 137 blobRegistry()->registerBlobData(uuid, WebKit::WebBlobData(data));
139 if (WebBlobRegistry* registry = blobRegistry()) {
140 WebBlobData webBlobData(blobRegistryContext->blobData.release());
141 registry->registerBlobURL(blobRegistryContext->url, webBlobData);
142 }
143 } 138 }
144 139
145 void BlobRegistry::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blobDat a) 140 void BlobRegistry::addBlobDataRef(const String& uuid)
146 { 141 {
147 if (isMainThread()) { 142 blobRegistry()->addBlobDataRef(uuid);
148 if (WebBlobRegistry* registry = blobRegistry()) {
149 WebBlobData webBlobData(blobData);
150 registry->registerBlobURL(url, webBlobData);
151 }
152 } else {
153 OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(u rl, blobData));
154 callOnMainThread(&registerBlobURLTask, context.leakPtr());
155 }
156 } 143 }
157 144
158 static void registerBlobURLFromTask(void* context) 145 void BlobRegistry::removeBlobDataRef(const String& uuid)
159 { 146 {
160 OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobR egistryContext*>(context)); 147 blobRegistry()->removeBlobDataRef(uuid);
161 if (WebBlobRegistry* registry = blobRegistry())
162 registry->registerBlobURL(blobRegistryContext->url, blobRegistryContext- >srcURL);
163 } 148 }
164 149
165 void BlobRegistry::registerBlobURL(SecurityOrigin* origin, const KURL& url, cons t KURL& srcURL) 150 void BlobRegistry::registerPublicBlobURL(SecurityOrigin* origin, const KURL& url , PassRefPtr<BlobDataHandle> handle)
166 { 151 {
167 saveToOriginMap(origin, url); 152 saveToOriginMap(origin, url);
168 153 blobRegistry()->registerPublicBlobURL(url, handle->uuid());
169 if (isMainThread()) {
170 if (WebBlobRegistry* registry = blobRegistry())
171 registry->registerBlobURL(url, srcURL);
172 } else {
173 OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(u rl, srcURL));
174 callOnMainThread(&registerBlobURLFromTask, context.leakPtr());
175 }
176 } 154 }
177 155
178 static void unregisterBlobURLTask(void* context) 156 void BlobRegistry::revokePublicBlobURL(const KURL& url)
179 {
180 OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobR egistryContext*>(context));
181 if (WebBlobRegistry* registry = blobRegistry())
182 registry->unregisterBlobURL(blobRegistryContext->url);
183 }
184
185 void BlobRegistry::unregisterBlobURL(const KURL& url)
186 { 157 {
187 removeFromOriginMap(url); 158 removeFromOriginMap(url);
188 159 blobRegistry()->revokePublicBlobURL(url);
189 if (isMainThread()) {
190 if (WebBlobRegistry* registry = blobRegistry())
191 registry->unregisterBlobURL(url);
192 } else {
193 OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(u rl));
194 callOnMainThread(&unregisterBlobURLTask, context.leakPtr());
195 }
196 } 160 }
197 161
198 static void registerStreamURLTask(void* context) 162 static void registerStreamURLTask(void* context)
199 { 163 {
200 OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobR egistryContext*>(context)); 164 OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobR egistryContext*>(context));
201 if (WebBlobRegistry* registry = blobRegistry()) 165 if (WebBlobRegistry* registry = blobRegistry())
202 registry->registerStreamURL(blobRegistryContext->url, blobRegistryContex t->type); 166 registry->registerStreamURL(blobRegistryContext->url, blobRegistryContex t->type);
203 } 167 }
204 168
205 void BlobRegistry::registerStreamURL(const KURL& url, const String& type) 169 void BlobRegistry::registerStreamURL(const KURL& url, const String& type)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 281 }
318 282
319 SecurityOrigin* BlobOriginCache::cachedOrigin(const KURL& url) 283 SecurityOrigin* BlobOriginCache::cachedOrigin(const KURL& url)
320 { 284 {
321 if (url.protocolIs("blob")) 285 if (url.protocolIs("blob"))
322 return originMap()->get(url.string()); 286 return originMap()->get(url.string());
323 return 0; 287 return 0;
324 } 288 }
325 289
326 } // namespace WebCore 290 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/fileapi/BlobRegistry.h ('k') | Source/core/fileapi/BlobURL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698