1 // Copyright (c) 2009 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 "content/browser/worker_host/worker_document_set.h" 6 7 #include "base/logging.h" 8 9 namespace content { 10 11 WorkerDocumentSet::WorkerDocumentSet() { 12 } 13 14 void WorkerDocumentSet::Add(WorkerMessageFilter* parent, 15 unsigned long long document_id, 16 int render_process_id, 17 int render_view_id) { 18 DocumentInfo info(parent, document_id, render_process_id, render_view_id); 19 document_set_.insert(info); 20 } 21 22 bool WorkerDocumentSet::Contains(WorkerMessageFilter* parent, 23 unsigned long long document_id) const { 24 for (DocumentInfoSet::const_iterator i = document_set_.begin(); 25 i != document_set_.end(); ++i) { 26 if (i->filter() == parent && i->document_id() == document_id) 27 return true; 28 } 29 return false; 30 } 31 32 void WorkerDocumentSet::Remove(WorkerMessageFilter* parent, 33 unsigned long long document_id) { 34 for (DocumentInfoSet::iterator i = document_set_.begin(); 35 i != document_set_.end(); i++) { 36 if (i->filter() == parent && i->document_id() == document_id) { 37 document_set_.erase(i); 38 break; 39 } 40 } 41 // Should not be duplicate copies in the document set. 42 DCHECK(!Contains(parent, document_id)); 43 } 44 45 void WorkerDocumentSet::RemoveAll(WorkerMessageFilter* parent) { 46 for (DocumentInfoSet::iterator i = document_set_.begin(); 47 i != document_set_.end();) { 48 49 // Note this idiom is somewhat tricky - calling document_set_.erase(iter) 50 // invalidates any iterators that point to the element being removed, so 51 // bump the iterator beyond the item being removed before calling erase. 52 if (i->filter() == parent) { 53 DocumentInfoSet::iterator item_to_delete = i++; 54 document_set_.erase(item_to_delete); 55 } else { 56 ++i; 57 } 58 } 59 } 60 61 WorkerDocumentSet::DocumentInfo::DocumentInfo( 62 WorkerMessageFilter* filter, unsigned long long document_id, 63 int render_process_id, int render_view_id) 64 : filter_(filter), 65 document_id_(document_id), 66 render_process_id_(render_process_id), 67 render_view_id_(render_view_id) { 68 } 69 70 WorkerDocumentSet::~WorkerDocumentSet() { 71 } 72 73 } // namespace content 74