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

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

Issue 509016: Refactored code to allow associating workers with multiple renderers. (Closed)
Patch Set: Disabled overly-aggressive assertion in ResourceDispatcherHost. Created 10 years, 10 months 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
OLDNEW
(Empty)
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 #ifndef CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
6 #define CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
7
8 #include <set>
9
10 #include "base/basictypes.h"
11 #include "base/ref_counted.h"
12 #include "ipc/ipc_message.h"
13
14 // The WorkerDocumentSet tracks all of the DOM documents associated with a
15 // set of workers. With nested workers, multiple workers can share the same
16 // WorkerDocumentSet (meaning that they all share the same lifetime, and will
17 // all exit when the last document in that set exits, per the WebWorkers spec).
18 class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> {
19 public:
20 WorkerDocumentSet();
21
22 // The information we track for each document
23 class DocumentInfo {
24 public:
25 DocumentInfo(IPC::Message::Sender* sender, unsigned long long document_id,
26 int renderer_id, int render_view_route_id);
27 IPC::Message::Sender* sender() const { return sender_; }
28 unsigned long long document_id() const { return document_id_; }
29 int renderer_id() const { return renderer_id_; }
30 int render_view_route_id() const { return render_view_route_id_; }
31
32 // Define operator "<", which is used to determine uniqueness within
33 // the set.
34 bool operator <(DocumentInfo other) const {
35 // Items are identical if the sender and document_id are identical,
36 // otherwise create an arbitrary stable ordering based on the document
37 // id/sender.
38 if (sender() == other.sender()) {
39 return document_id() < other.document_id();
40 } else {
41 return reinterpret_cast<unsigned long long>(sender()) <
42 reinterpret_cast<unsigned long long>(other.sender());
43 }
44 }
45
46 private:
47 IPC::Message::Sender* sender_;
48 unsigned long long document_id_;
49 int renderer_id_;
50 int render_view_route_id_;
51 };
52
53 // Adds a document to a shared worker's document set. Also includes the
54 // associated renderer_id the document is associated with, to enable
55 // communication with the parent tab for things like http auth dialogs.
56 void Add(IPC::Message::Sender* parent,
57 unsigned long long document_id,
58 int renderer_id,
59 int render_view_route_id);
60
61 // Checks to see if a document is in a shared worker's document set.
62 bool Contains(IPC::Message::Sender* parent,
63 unsigned long long document_id) const;
64
65 // Removes a specific document from a worker's document set when that document
66 // is detached.
67 void Remove(IPC::Message::Sender* parent, unsigned long long document_id);
68
69 // Invoked when a render process exits, to remove all associated documents
70 // from a worker's document set.
71 void RemoveAll(IPC::Message::Sender* parent);
72
73 bool IsEmpty() const { return document_set_.empty(); }
74
75 // Define a typedef for convenience here when declaring iterators, etc.
76 typedef std::set<DocumentInfo> DocumentInfoSet;
77
78 // Returns the set of documents associated with this worker.
79 const DocumentInfoSet& documents() { return document_set_; }
80
81 private:
82 DocumentInfoSet document_set_;
83 };
84
85 #endif // CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/resource_request_details.h ('k') | chrome/browser/worker_host/worker_document_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698