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

Side by Side Diff: content/browser/worker_host/worker_service_impl.h

Issue 14137016: Lower the priority of shared workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved visible check into worker_service_impl. Created 7 years, 7 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
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_SERVICE_H_ 5 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_
6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "content/browser/worker_host/worker_process_host.h" 13 #include "content/browser/worker_host/worker_process_host.h"
14 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/worker_service.h" 16 #include "content/public/browser/worker_service.h"
16 17
17 class GURL; 18 class GURL;
18 struct ViewHostMsg_CreateWorker_Params; 19 struct ViewHostMsg_CreateWorker_Params;
19 20
20 namespace content { 21 namespace content {
21 class ResourceContext; 22 class ResourceContext;
22 class WorkerServiceObserver; 23 class WorkerServiceObserver;
23 class WorkerStoragePartition; 24 class WorkerStoragePartition;
24 25
25 class CONTENT_EXPORT WorkerServiceImpl 26 class CONTENT_EXPORT WorkerServiceImpl
26 : public NON_EXPORTED_BASE(WorkerService) { 27 : public NON_EXPORTED_BASE(WorkerService),
28 public content::NotificationObserver {
jam 2013/05/09 18:02:57 no "content::" since this is in the content namesp
shatch 2013/05/09 22:42:49 Done.
27 public: 29 public:
28 // Returns the WorkerServiceImpl singleton. 30 // Returns the WorkerServiceImpl singleton.
29 static WorkerServiceImpl* GetInstance(); 31 static WorkerServiceImpl* GetInstance();
30 32
33
jam 2013/05/09 18:02:57 nit: remove
shatch 2013/05/09 22:42:49 Done.
31 // WorkerService implementation: 34 // WorkerService implementation:
32 virtual bool TerminateWorker(int process_id, int route_id) OVERRIDE; 35 virtual bool TerminateWorker(int process_id, int route_id) OVERRIDE;
33 virtual std::vector<WorkerInfo> GetWorkers() OVERRIDE; 36 virtual std::vector<WorkerInfo> GetWorkers() OVERRIDE;
34 virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE; 37 virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE;
35 virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE; 38 virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE;
36 39
37 // These methods correspond to worker related IPCs. 40 // These methods correspond to worker related IPCs.
38 void CreateWorker(const ViewHostMsg_CreateWorker_Params& params, 41 void CreateWorker(const ViewHostMsg_CreateWorker_Params& params,
39 int route_id, 42 int route_id,
40 WorkerMessageFilter* filter, 43 WorkerMessageFilter* filter,
(...skipping 24 matching lines...) Expand all
65 bool GetRendererForWorker(int worker_process_id, 68 bool GetRendererForWorker(int worker_process_id,
66 int* render_process_id, 69 int* render_process_id,
67 int* render_view_id) const; 70 int* render_view_id) const;
68 const WorkerProcessHost::WorkerInstance* FindWorkerInstance( 71 const WorkerProcessHost::WorkerInstance* FindWorkerInstance(
69 int worker_process_id); 72 int worker_process_id);
70 73
71 void NotifyWorkerDestroyed( 74 void NotifyWorkerDestroyed(
72 WorkerProcessHost* process, 75 WorkerProcessHost* process,
73 int worker_route_id); 76 int worker_route_id);
74 77
78 void NotifyWorkerProcessCreated();
79
75 // Used when we run each worker in a separate process. 80 // Used when we run each worker in a separate process.
76 static const int kMaxWorkersWhenSeparate; 81 static const int kMaxWorkersWhenSeparate;
77 static const int kMaxWorkersPerTabWhenSeparate; 82 static const int kMaxWorkersPerTabWhenSeparate;
78 83
79 private: 84 private:
80 friend struct DefaultSingletonTraits<WorkerServiceImpl>; 85 friend struct DefaultSingletonTraits<WorkerServiceImpl>;
81 86
82 WorkerServiceImpl(); 87 WorkerServiceImpl();
83 virtual ~WorkerServiceImpl(); 88 virtual ~WorkerServiceImpl();
84 89
(...skipping 30 matching lines...) Expand all
115 const string16& name, 120 const string16& name,
116 const WorkerStoragePartition& worker_partition, 121 const WorkerStoragePartition& worker_partition,
117 ResourceContext* resource_context); 122 ResourceContext* resource_context);
118 123
119 WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance( 124 WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance(
120 const GURL& url, 125 const GURL& url,
121 const string16& name, 126 const string16& name,
122 const WorkerStoragePartition& worker_partition, 127 const WorkerStoragePartition& worker_partition,
123 ResourceContext* resource_context); 128 ResourceContext* resource_context);
124 129
130 // Registers as an observer to receive notifications about
131 // widgets being shown.
132 void RegisterObserver();
133
134 // Called to refresh worker priorities when focus changes between tabs.
135 void OnRenderWidgetVisibilityChanged(std::pair<int, int>);
136
137 // Sets priorities for shared workers given a set of visible tabs (as a
138 // std::set of std::pair<render_process, render_view> ids.
139 void UpdateWorkerPrioritiesFromVisibleSet(
140 const std::set<std::pair<int, int> >* visible);
141
142 // Gathers up a list of the visible tabs and then priorities for
143 // all the shared workers.
144 void GatherVisibleIDsAndUpdateWorkerPriorities();
145
146 // Posts a task to perform a worker priority update.
147 void PostTaskToGatherAndUpdateWorkerPriorities();
148
149 // NotificationObserver implementation.
150 virtual void Observe(int type,
151 const NotificationSource& source,
152 const NotificationDetails& details) OVERRIDE;
153
125 NotificationRegistrar registrar_; 154 NotificationRegistrar registrar_;
126 int next_worker_route_id_; 155 int next_worker_route_id_;
127 156
128 WorkerProcessHost::Instances queued_workers_; 157 WorkerProcessHost::Instances queued_workers_;
129 158
130 // These are shared workers that have been looked up, but not created yet. 159 // These are shared workers that have been looked up, but not created yet.
131 // We need to keep a list of these to synchronously detect shared worker 160 // We need to keep a list of these to synchronously detect shared worker
132 // URL mismatches when two pages launch shared workers simultaneously. 161 // URL mismatches when two pages launch shared workers simultaneously.
133 WorkerProcessHost::Instances pending_shared_workers_; 162 WorkerProcessHost::Instances pending_shared_workers_;
134 163
135 ObserverList<WorkerServiceObserver> observers_; 164 ObserverList<WorkerServiceObserver> observers_;
136 165
137 DISALLOW_COPY_AND_ASSIGN(WorkerServiceImpl); 166 DISALLOW_COPY_AND_ASSIGN(WorkerServiceImpl);
138 }; 167 };
139 168
140 } // namespace content 169 } // namespace content
141 170
142 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ 171 #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698