Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / browser / shared_worker / shared_worker_host.h
blob53cc218669c7b387986bd33c8ce16eca12d5865c
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 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_
8 #include <list>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/time/time.h"
14 #include "content/browser/shared_worker/shared_worker_message_filter.h"
15 #include "content/browser/worker_host/worker_document_set.h"
17 class GURL;
19 namespace IPC {
20 class Message;
23 namespace content {
24 class SharedWorkerMessageFilter;
25 class SharedWorkerInstance;
27 // The SharedWorkerHost is the interface that represents the browser side of
28 // the browser <-> worker communication channel.
29 class SharedWorkerHost {
30 public:
31 SharedWorkerHost(SharedWorkerInstance* instance,
32 SharedWorkerMessageFilter* filter,
33 int worker_route_id);
34 ~SharedWorkerHost();
36 // Sends |message| to the SharedWorker.
37 bool Send(IPC::Message* message);
39 // Starts the SharedWorker in the renderer process which is associated with
40 // |filter_|.
41 void Start(bool pause_on_start);
43 // Returns true iff the given message from a renderer process was forwarded to
44 // the worker.
45 bool FilterMessage(const IPC::Message& message,
46 SharedWorkerMessageFilter* filter);
48 // Handles the shutdown of the filter. If the worker has no other client,
49 // sends TerminateWorkerContext message to shut it down.
50 void FilterShutdown(SharedWorkerMessageFilter* filter);
52 // Shuts down any shared workers that are no longer referenced by active
53 // documents.
54 void DocumentDetached(SharedWorkerMessageFilter* filter,
55 unsigned long long document_id);
57 void WorkerContextClosed();
58 void WorkerScriptLoaded();
59 void WorkerScriptLoadFailed();
60 void WorkerConnected(int message_port_id);
61 void WorkerContextDestroyed();
62 void AllowDatabase(const GURL& url,
63 const base::string16& name,
64 const base::string16& display_name,
65 unsigned long estimated_size,
66 bool* result);
67 void AllowFileSystem(const GURL& url, bool* result);
68 void AllowIndexedDB(const GURL& url,
69 const base::string16& name,
70 bool* result);
72 // Terminates the given worker, i.e. based on a UI action.
73 void TerminateWorker();
75 void AddFilter(SharedWorkerMessageFilter* filter, int route_id);
77 SharedWorkerInstance* instance() { return instance_.get(); }
78 WorkerDocumentSet* worker_document_set() const {
79 return worker_document_set_.get();
81 SharedWorkerMessageFilter* container_render_filter() const {
82 return container_render_filter_;
84 int process_id() const { return worker_process_id_; }
85 int worker_route_id() const { return worker_route_id_; }
86 bool load_failed() const { return load_failed_; }
87 bool closed() const { return closed_; }
89 private:
90 // Unique identifier for a worker client.
91 class FilterInfo {
92 public:
93 FilterInfo(SharedWorkerMessageFilter* filter, int route_id)
94 : filter_(filter), route_id_(route_id), message_port_id_(0) {}
95 SharedWorkerMessageFilter* filter() const { return filter_; }
96 int route_id() const { return route_id_; }
97 int message_port_id() const { return message_port_id_; }
98 void set_message_port_id(int id) { message_port_id_ = id; }
100 private:
101 SharedWorkerMessageFilter* filter_;
102 int route_id_;
103 int message_port_id_;
106 typedef std::list<FilterInfo> FilterList;
108 // Relays |message| to the SharedWorker. Takes care of parsing the message if
109 // it contains a message port and sending it a valid route id.
110 void RelayMessage(const IPC::Message& message,
111 SharedWorkerMessageFilter* incoming_filter);
113 // Return a vector of all the render process/render frame IDs.
114 std::vector<std::pair<int, int> > GetRenderFrameIDsForWorker();
116 void RemoveFilters(SharedWorkerMessageFilter* filter);
117 bool HasFilter(SharedWorkerMessageFilter* filter, int route_id) const;
118 void SetMessagePortID(SharedWorkerMessageFilter* filter,
119 int route_id,
120 int message_port_id);
122 scoped_ptr<SharedWorkerInstance> instance_;
123 scoped_refptr<WorkerDocumentSet> worker_document_set_;
124 FilterList filters_;
125 SharedWorkerMessageFilter* container_render_filter_;
126 int worker_process_id_;
127 int worker_route_id_;
128 bool load_failed_;
129 bool closed_;
130 const base::TimeTicks creation_time_;
131 DISALLOW_COPY_AND_ASSIGN(SharedWorkerHost);
133 } // namespace content
135 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_