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

Side by Side Diff: extensions/browser/blob_holder.cc

Issue 280393003: Blobs: Catching browser-process created Blobs in extension code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: run git cl format Created 6 years, 7 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
« no previous file with comments | « extensions/browser/blob_holder.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "extensions/browser/blob_holder.h"
6
7 #include "base/logging.h"
8 #include "content/public/browser/blob_handle.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_process_host.h"
11
12 namespace extensions {
13
14 namespace {
15
16 // Address to this variable used as the user data key.
17 const int kBlobHolderUserDataKey = 0;
18 }
19
20 // static
21 BlobHolder* BlobHolder::FromRenderProcessHost(
22 content::RenderProcessHost* render_process_host) {
23 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
24 DCHECK(render_process_host);
25 BlobHolder* existing = static_cast<BlobHolder*>(
26 render_process_host->GetUserData(&kBlobHolderUserDataKey));
27
28 if (existing)
29 return existing;
30
31 BlobHolder* new_instance = new BlobHolder(render_process_host);
32 render_process_host->SetUserData(&kBlobHolderUserDataKey, new_instance);
33 return new_instance;
34 }
35
36 BlobHolder::~BlobHolder() {
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38 }
39
40 void BlobHolder::HoldBlobReference(scoped_ptr<content::BlobHandle> blob) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
42 DCHECK(!ContainsBlobHandle(blob.get()));
michaeln 2014/05/23 17:31:36 might be able to simplify DCHECK_EQ(held_blobs_.e
tommycli 2014/05/23 18:48:39 Was possible. No longer possible since I switched
43 held_blobs_.push_back(blob.release());
44 }
45
46 BlobHolder::BlobHolder(content::RenderProcessHost* render_process_host)
47 : render_process_host_(render_process_host) {
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 }
50
51 bool BlobHolder::ContainsBlobHandle(content::BlobHandle* handle) const {
52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
53 for (BlobHandleVector::const_iterator it = held_blobs_.begin();
54 it != held_blobs_.end();
55 ++it) {
56 if (*it == handle)
57 return true;
58 }
59
60 return false;
61 }
62
63 void BlobHolder::DropBlobs(const std::vector<std::string>& blob_uuids) {
64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 for (std::vector<std::string>::const_iterator uuid_it = blob_uuids.begin();
michaeln 2014/05/23 17:31:36 this n*n loop is probably not so bad because these
tommycli 2014/05/23 18:48:39 Yeah you're right this is a little hard to underst
66 uuid_it != blob_uuids.end();
67 ++uuid_it) {
68 bool found = false;
69 for (BlobHandleVector::iterator blob_handle_it = held_blobs_.begin();
70 blob_handle_it != held_blobs_.end();
71 ++blob_handle_it) {
72 if ((*blob_handle_it)->GetUUID() == *uuid_it) {
73 held_blobs_.erase(blob_handle_it);
74 found = true;
75 break;
76 }
77 }
78
79 if (!found) {
80 DLOG(ERROR) << "Tried to release a Blob we don't have ownership to."
81 << "UUID: " << *uuid_it;
82 render_process_host_->ReceivedBadMessage();
83 }
84 }
85 }
86
87 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/blob_holder.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698