OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ | 5 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ |
6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ | 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 class WorkerMessageFilter; | 14 class WorkerMessageFilter; |
15 | 15 |
16 // The WorkerDocumentSet tracks all of the DOM documents associated with a | 16 // The WorkerDocumentSet tracks all of the DOM documents associated with a |
17 // set of workers. With nested workers, multiple workers can share the same | 17 // set of workers. With nested workers, multiple workers can share the same |
18 // WorkerDocumentSet (meaning that they all share the same lifetime, and will | 18 // WorkerDocumentSet (meaning that they all share the same lifetime, and will |
19 // all exit when the last document in that set exits, per the WebWorkers spec). | 19 // all exit when the last document in that set exits, per the WebWorkers spec). |
20 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> { | 20 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> { |
21 public: | 21 public: |
22 WorkerDocumentSet(); | 22 WorkerDocumentSet(); |
23 | 23 |
24 // The information we track for each document | 24 // The information we track for each document |
25 class DocumentInfo { | 25 class DocumentInfo { |
26 public: | 26 public: |
27 DocumentInfo(WorkerMessageFilter* filter, unsigned long long document_id, | 27 DocumentInfo(WorkerMessageFilter* filter, unsigned long long document_id, |
28 int renderer_process_id, int render_view_id, | 28 int renderer_process_id, int render_frame_id); |
29 int render_frame_id); | |
30 WorkerMessageFilter* filter() const { return filter_; } | 29 WorkerMessageFilter* filter() const { return filter_; } |
31 unsigned long long document_id() const { return document_id_; } | 30 unsigned long long document_id() const { return document_id_; } |
32 int render_process_id() const { return render_process_id_; } | 31 int render_process_id() const { return render_process_id_; } |
33 int render_view_id() const { return render_view_id_; } | |
34 int render_frame_id() const { return render_frame_id_; } | 32 int render_frame_id() const { return render_frame_id_; } |
35 | 33 |
36 // Define operator "<", which is used to determine uniqueness within | 34 // Define operator "<", which is used to determine uniqueness within |
37 // the set. | 35 // the set. |
38 bool operator <(const DocumentInfo& other) const { | 36 bool operator <(const DocumentInfo& other) const { |
39 // Items are identical if the sender and document_id are identical, | 37 // Items are identical if the sender and document_id are identical, |
40 // otherwise create an arbitrary stable ordering based on the document | 38 // otherwise create an arbitrary stable ordering based on the document |
41 // id/filter. | 39 // id/filter. |
42 if (filter() == other.filter()) { | 40 if (filter() == other.filter()) { |
43 return document_id() < other.document_id(); | 41 return document_id() < other.document_id(); |
44 } else { | 42 } else { |
45 return reinterpret_cast<unsigned long long>(filter()) < | 43 return reinterpret_cast<unsigned long long>(filter()) < |
46 reinterpret_cast<unsigned long long>(other.filter()); | 44 reinterpret_cast<unsigned long long>(other.filter()); |
47 } | 45 } |
48 } | 46 } |
49 | 47 |
50 private: | 48 private: |
51 WorkerMessageFilter* filter_; | 49 WorkerMessageFilter* filter_; |
52 unsigned long long document_id_; | 50 unsigned long long document_id_; |
53 int render_process_id_; | 51 int render_process_id_; |
54 int render_view_id_; | |
55 int render_frame_id_; | 52 int render_frame_id_; |
56 }; | 53 }; |
57 | 54 |
58 // Adds a document to a shared worker's document set. Also includes the | 55 // Adds a document to a shared worker's document set. Also includes the |
59 // associated render_process_id the document is associated with, to enable | 56 // associated render_process_id the document is associated with, to enable |
60 // communication with the parent tab for things like http auth dialogs. | 57 // communication with the parent tab for things like http auth dialogs. |
61 void Add(WorkerMessageFilter* parent, | 58 void Add(WorkerMessageFilter* parent, |
62 unsigned long long document_id, | 59 unsigned long long document_id, |
63 int render_process_id, | 60 int render_process_id, |
64 int render_view_id, | |
65 int render_frame_id); | 61 int render_frame_id); |
66 | 62 |
67 // Checks to see if a document is in a shared worker's document set. | 63 // Checks to see if a document is in a shared worker's document set. |
68 bool Contains(WorkerMessageFilter* parent, | 64 bool Contains(WorkerMessageFilter* parent, |
69 unsigned long long document_id) const; | 65 unsigned long long document_id) const; |
70 | 66 |
71 // Removes a specific document from a worker's document set when that document | 67 // Removes a specific document from a worker's document set when that document |
72 // is detached. | 68 // is detached. |
73 void Remove(WorkerMessageFilter* parent, unsigned long long document_id); | 69 void Remove(WorkerMessageFilter* parent, unsigned long long document_id); |
74 | 70 |
(...skipping 12 matching lines...) Expand all Loading... |
87 private: | 83 private: |
88 friend class base::RefCounted<WorkerDocumentSet>; | 84 friend class base::RefCounted<WorkerDocumentSet>; |
89 virtual ~WorkerDocumentSet(); | 85 virtual ~WorkerDocumentSet(); |
90 | 86 |
91 DocumentInfoSet document_set_; | 87 DocumentInfoSet document_set_; |
92 }; | 88 }; |
93 | 89 |
94 } // namespace content | 90 } // namespace content |
95 | 91 |
96 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ | 92 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ |
OLD | NEW |