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

Side by Side Diff: chrome/browser/worker_host/worker_document_set.h

Issue 6055002: Create a message filter for message port messages. This allows a nice cleanu... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ 5 #ifndef CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
6 #define CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ 6 #define CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "ipc/ipc_message.h" 13
14 class WorkerMessageFilter;
14 15
15 // The WorkerDocumentSet tracks all of the DOM documents associated with a 16 // The WorkerDocumentSet tracks all of the DOM documents associated with a
16 // 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
17 // WorkerDocumentSet (meaning that they all share the same lifetime, and will 18 // WorkerDocumentSet (meaning that they all share the same lifetime, and will
18 // 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).
19 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> { 20 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> {
20 public: 21 public:
21 WorkerDocumentSet(); 22 WorkerDocumentSet();
22 23
23 // The information we track for each document 24 // The information we track for each document
24 class DocumentInfo { 25 class DocumentInfo {
25 public: 26 public:
26 DocumentInfo(IPC::Message::Sender* sender, unsigned long long document_id, 27 DocumentInfo(WorkerMessageFilter* filter, unsigned long long document_id,
27 int renderer_id, int render_view_route_id); 28 int renderer_process_id, int render_view_id);
28 IPC::Message::Sender* sender() const { return sender_; } 29 WorkerMessageFilter* filter() const { return filter_; }
29 unsigned long long document_id() const { return document_id_; } 30 unsigned long long document_id() const { return document_id_; }
30 int renderer_id() const { return renderer_id_; } 31 int render_process_id() const { return render_process_id_; }
31 int render_view_route_id() const { return render_view_route_id_; } 32 int render_view_id() const { return render_view_id_; }
32 33
33 // Define operator "<", which is used to determine uniqueness within 34 // Define operator "<", which is used to determine uniqueness within
34 // the set. 35 // the set.
35 bool operator <(const DocumentInfo& other) const { 36 bool operator <(const DocumentInfo& other) const {
36 // Items are identical if the sender and document_id are identical, 37 // Items are identical if the sender and document_id are identical,
37 // otherwise create an arbitrary stable ordering based on the document 38 // otherwise create an arbitrary stable ordering based on the document
38 // id/sender. 39 // id/sender.
Andrew T Wilson (Slow) 2010/12/21 03:12:21 comment is obsolete - change sender => filter.
jam 2010/12/21 07:41:51 Done.
39 if (sender() == other.sender()) { 40 if (filter() == other.filter()) {
40 return document_id() < other.document_id(); 41 return document_id() < other.document_id();
41 } else { 42 } else {
42 return reinterpret_cast<unsigned long long>(sender()) < 43 return reinterpret_cast<unsigned long long>(filter()) <
43 reinterpret_cast<unsigned long long>(other.sender()); 44 reinterpret_cast<unsigned long long>(other.filter());
44 } 45 }
45 } 46 }
46 47
47 private: 48 private:
48 IPC::Message::Sender* sender_; 49 WorkerMessageFilter* filter_;
49 unsigned long long document_id_; 50 unsigned long long document_id_;
50 int renderer_id_; 51 int render_process_id_;
51 int render_view_route_id_; 52 int render_view_id_;
52 }; 53 };
53 54
54 // 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
55 // associated renderer_id the document is associated with, to enable 56 // associated render_process_id the document is associated with, to enable
56 // communication with the parent tab for things like http auth dialogs. 57 // communication with the parent tab for things like http auth dialogs.
57 void Add(IPC::Message::Sender* parent, 58 void Add(WorkerMessageFilter* parent,
58 unsigned long long document_id, 59 unsigned long long document_id,
59 int renderer_id, 60 int render_process_id,
60 int render_view_route_id); 61 int render_view_id);
61 62
62 // 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.
63 bool Contains(IPC::Message::Sender* parent, 64 bool Contains(WorkerMessageFilter* parent,
64 unsigned long long document_id) const; 65 unsigned long long document_id) const;
65 66
66 // 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
67 // is detached. 68 // is detached.
68 void Remove(IPC::Message::Sender* parent, unsigned long long document_id); 69 void Remove(WorkerMessageFilter* parent, unsigned long long document_id);
69 70
70 // Invoked when a render process exits, to remove all associated documents 71 // Invoked when a render process exits, to remove all associated documents
71 // from a worker's document set. 72 // from a worker's document set.
72 void RemoveAll(IPC::Message::Sender* parent); 73 void RemoveAll(WorkerMessageFilter* parent);
73 74
74 bool IsEmpty() const { return document_set_.empty(); } 75 bool IsEmpty() const { return document_set_.empty(); }
75 76
76 // Define a typedef for convenience here when declaring iterators, etc. 77 // Define a typedef for convenience here when declaring iterators, etc.
77 typedef std::set<DocumentInfo> DocumentInfoSet; 78 typedef std::set<DocumentInfo> DocumentInfoSet;
78 79
79 // Returns the set of documents associated with this worker. 80 // Returns the set of documents associated with this worker.
80 const DocumentInfoSet& documents() { return document_set_; } 81 const DocumentInfoSet& documents() { return document_set_; }
81 82
82 private: 83 private:
83 friend class base::RefCounted<WorkerDocumentSet>; 84 friend class base::RefCounted<WorkerDocumentSet>;
84 virtual ~WorkerDocumentSet(); 85 virtual ~WorkerDocumentSet();
85 86
86 DocumentInfoSet document_set_; 87 DocumentInfoSet document_set_;
87 }; 88 };
88 89
89 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_ 90 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698