Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_SHARED_WORKER_DOCUMENT_SET_H_ |
| 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ | 6 #define CONTENT_BROWSER_WORKER_HOST_SHARED_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 { |
|
kinuko
2014/02/12 08:09:49
nit: not mandatory or not in our style guide, but
| |
| 14 class WorkerMessageFilter; | 14 class SharedWorkerMessageFilter; |
| 15 | 15 |
| 16 // The WorkerDocumentSet tracks all of the DOM documents associated with a | 16 // The SharedWorkerDocumentSet 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 // SharedWorkerDocumentSet (meaning that they all share the same lifetime, and |
| 19 // all exit when the last document in that set exits, per the WebWorkers spec). | 19 // willall exit when the last document in that set exits, per the WebWorkers |
|
kinuko
2014/02/12 08:09:49
willall -> will all
| |
| 20 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> { | 20 // spec). |
| 21 // If "enable-embedded-shared-worker" is set this class will be used in stead of | |
|
kinuko
2014/02/12 08:09:49
nit: 'in stead of' works, but 'instead of' might b
| |
| 22 // SharedWorkerDocument. | |
| 23 class SharedWorkerDocumentSet | |
|
kinuko
2014/02/12 08:09:49
This class's mostly same as WorkerDocumentSet-- ca
| |
| 24 : public base::RefCounted<SharedWorkerDocumentSet> { | |
| 21 public: | 25 public: |
| 22 WorkerDocumentSet(); | 26 SharedWorkerDocumentSet(); |
| 23 | 27 |
| 24 // The information we track for each document | 28 // The information we track for each document |
| 25 class DocumentInfo { | 29 class DocumentInfo { |
| 26 public: | 30 public: |
| 27 DocumentInfo(WorkerMessageFilter* filter, unsigned long long document_id, | 31 DocumentInfo(SharedWorkerMessageFilter* filter, |
| 28 int renderer_process_id, int render_frame_id); | 32 unsigned long long document_id, |
| 29 WorkerMessageFilter* filter() const { return filter_; } | 33 int renderer_process_id, |
| 34 int render_frame_id); | |
| 35 SharedWorkerMessageFilter* filter() const { return filter_; } | |
| 30 unsigned long long document_id() const { return document_id_; } | 36 unsigned long long document_id() const { return document_id_; } |
| 31 int render_process_id() const { return render_process_id_; } | 37 int render_process_id() const { return render_process_id_; } |
| 32 int render_frame_id() const { return render_frame_id_; } | 38 int render_frame_id() const { return render_frame_id_; } |
| 33 | 39 |
| 34 // Define operator "<", which is used to determine uniqueness within | 40 // Define operator "<", which is used to determine uniqueness within |
| 35 // the set. | 41 // the set. |
| 36 bool operator <(const DocumentInfo& other) const { | 42 bool operator <(const DocumentInfo& other) const { |
| 37 // Items are identical if the sender and document_id are identical, | 43 // Items are identical if the sender and document_id are identical, |
| 38 // otherwise create an arbitrary stable ordering based on the document | 44 // otherwise create an arbitrary stable ordering based on the document |
| 39 // id/filter. | 45 // id/filter. |
| 40 if (filter() == other.filter()) { | 46 if (filter() == other.filter()) { |
| 41 return document_id() < other.document_id(); | 47 return document_id() < other.document_id(); |
| 42 } else { | 48 } else { |
| 43 return reinterpret_cast<unsigned long long>(filter()) < | 49 return reinterpret_cast<unsigned long long>(filter()) < |
| 44 reinterpret_cast<unsigned long long>(other.filter()); | 50 reinterpret_cast<unsigned long long>(other.filter()); |
| 45 } | 51 } |
| 46 } | 52 } |
| 47 | 53 |
| 48 private: | 54 private: |
| 49 WorkerMessageFilter* filter_; | 55 SharedWorkerMessageFilter* filter_; |
| 50 unsigned long long document_id_; | 56 unsigned long long document_id_; |
| 51 int render_process_id_; | 57 int render_process_id_; |
| 52 int render_frame_id_; | 58 int render_frame_id_; |
| 53 }; | 59 }; |
| 54 | 60 |
| 55 // Adds a document to a shared worker's document set. Also includes the | 61 // Adds a document to a shared worker's document set. Also includes the |
| 56 // associated render_process_id the document is associated with, to enable | 62 // associated render_process_id the document is associated with, to enable |
| 57 // communication with the parent tab for things like http auth dialogs. | 63 // communication with the parent tab for things like http auth dialogs. |
| 58 void Add(WorkerMessageFilter* parent, | 64 void Add(SharedWorkerMessageFilter* parent, |
| 59 unsigned long long document_id, | 65 unsigned long long document_id, |
| 60 int render_process_id, | 66 int render_process_id, |
| 61 int render_frame_id); | 67 int render_frame_id); |
| 62 | 68 |
| 63 // Checks to see if a document is in a shared worker's document set. | 69 // Checks to see if a document is in a shared worker's document set. |
| 64 bool Contains(WorkerMessageFilter* parent, | 70 bool Contains(SharedWorkerMessageFilter* parent, |
| 65 unsigned long long document_id) const; | 71 unsigned long long document_id) const; |
| 66 | 72 |
| 73 // Checks to see if the document set contains any documents which are | |
| 74 // associated with other renderer process than worker_process_id. | |
| 75 bool ContainsExternalRenderer(int worker_process_id) const; | |
| 76 | |
| 67 // Removes a specific document from a worker's document set when that document | 77 // Removes a specific document from a worker's document set when that document |
| 68 // is detached. | 78 // is detached. |
| 69 void Remove(WorkerMessageFilter* parent, unsigned long long document_id); | 79 void Remove(SharedWorkerMessageFilter* parent, |
| 80 unsigned long long document_id); | |
| 70 | 81 |
| 71 // Invoked when a render process exits, to remove all associated documents | 82 // Invoked when a render process exits, to remove all associated documents |
| 72 // from a worker's document set. | 83 // from a worker's document set. |
| 73 void RemoveAll(WorkerMessageFilter* parent); | 84 void RemoveAll(SharedWorkerMessageFilter* parent); |
| 74 | 85 |
| 75 bool IsEmpty() const { return document_set_.empty(); } | 86 bool IsEmpty() const { return document_set_.empty(); } |
| 76 | 87 |
| 77 // Define a typedef for convenience here when declaring iterators, etc. | 88 // Define a typedef for convenience here when declaring iterators, etc. |
| 78 typedef std::set<DocumentInfo> DocumentInfoSet; | 89 typedef std::set<DocumentInfo> DocumentInfoSet; |
| 79 | 90 |
| 80 // Returns the set of documents associated with this worker. | 91 // Returns the set of documents associated with this worker. |
| 81 const DocumentInfoSet& documents() { return document_set_; } | 92 const DocumentInfoSet& documents() { return document_set_; } |
| 82 | 93 |
| 83 private: | 94 private: |
| 84 friend class base::RefCounted<WorkerDocumentSet>; | 95 friend class base::RefCounted<SharedWorkerDocumentSet>; |
| 85 virtual ~WorkerDocumentSet(); | 96 virtual ~SharedWorkerDocumentSet(); |
| 86 | 97 |
| 87 DocumentInfoSet document_set_; | 98 DocumentInfoSet document_set_; |
| 88 }; | 99 }; |
| 89 | 100 |
| 90 } // namespace content | 101 } // namespace content |
| 91 | 102 |
| 92 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ | 103 #endif // CONTENT_BROWSER_WORKER_HOST_SHARED_WORKER_DOCUMENT_SET_H_ |
| OLD | NEW |