Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / shared_worker / worker_document_set.cc
blobf3ef7d2636d39221e029a428ad9d03af424b070d
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.
5 #include "content/browser/shared_worker/worker_document_set.h"
7 #include "base/logging.h"
9 namespace content {
11 WorkerDocumentSet::WorkerDocumentSet() {
14 void WorkerDocumentSet::Add(BrowserMessageFilter* parent,
15 unsigned long long document_id,
16 int render_process_id,
17 int render_frame_id) {
18 DocumentInfo info(parent, document_id, render_process_id, render_frame_id);
19 document_set_.insert(info);
22 bool WorkerDocumentSet::Contains(BrowserMessageFilter* 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;
29 return false;
32 bool WorkerDocumentSet::ContainsExternalRenderer(
33 int worker_process_id) const {
34 for (DocumentInfoSet::const_iterator i = document_set_.begin();
35 i != document_set_.end(); ++i) {
36 if (i->render_process_id() != worker_process_id)
37 return true;
39 return false;
42 void WorkerDocumentSet::Remove(BrowserMessageFilter* parent,
43 unsigned long long document_id) {
44 for (DocumentInfoSet::iterator i = document_set_.begin();
45 i != document_set_.end(); i++) {
46 if (i->filter() == parent && i->document_id() == document_id) {
47 document_set_.erase(i);
48 break;
51 // Should not be duplicate copies in the document set.
52 DCHECK(!Contains(parent, document_id));
55 void WorkerDocumentSet::RemoveAll(BrowserMessageFilter* parent) {
56 for (DocumentInfoSet::iterator i = document_set_.begin();
57 i != document_set_.end();) {
59 // Note this idiom is somewhat tricky - calling document_set_.erase(iter)
60 // invalidates any iterators that point to the element being removed, so
61 // bump the iterator beyond the item being removed before calling erase.
62 if (i->filter() == parent) {
63 DocumentInfoSet::iterator item_to_delete = i++;
64 document_set_.erase(item_to_delete);
65 } else {
66 ++i;
71 WorkerDocumentSet::DocumentInfo::DocumentInfo(
72 BrowserMessageFilter* filter, unsigned long long document_id,
73 int render_process_id, int render_frame_id)
74 : filter_(filter),
75 document_id_(document_id),
76 render_process_id_(render_process_id),
77 render_frame_id_(render_frame_id) {
80 WorkerDocumentSet::~WorkerDocumentSet() {
83 } // namespace content