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

Side by Side Diff: content/browser/shared_worker/shared_worker_service_impl.h

Issue 187533002: Add SharedWorkerServiceImpl::CheckWorkerDependency(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ExternalClient
Patch Set: Add unit test for SharedWorkerServiceImpl Created 6 years, 9 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 2014 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_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_ 6 #define CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
7 7
8 #include <set>
9
8 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
9 #include "base/containers/scoped_ptr_hash_map.h" 11 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
11 #include "base/observer_list.h" 13 #include "base/observer_list.h"
12 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/worker_service.h" 16 #include "content/public/browser/worker_service.h"
15 17
16 struct ViewHostMsg_CreateWorker_Params; 18 struct ViewHostMsg_CreateWorker_Params;
17 19
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const GURL& url, 82 const GURL& url,
81 const base::string16& name, 83 const base::string16& name,
82 bool* result, 84 bool* result,
83 SharedWorkerMessageFilter* filter); 85 SharedWorkerMessageFilter* filter);
84 86
85 void OnSharedWorkerMessageFilterClosing( 87 void OnSharedWorkerMessageFilterClosing(
86 SharedWorkerMessageFilter* filter); 88 SharedWorkerMessageFilter* filter);
87 89
88 private: 90 private:
89 friend struct DefaultSingletonTraits<SharedWorkerServiceImpl>; 91 friend struct DefaultSingletonTraits<SharedWorkerServiceImpl>;
92 friend class SharedWorkerServiceImplTest;
93
94 typedef void (*UpdateWorkerDependencyFunc)(const std::vector<int>,
95 const std::vector<int>);
kinuko 2014/03/10 04:25:43 const vector<int>& ?
horo 2014/03/10 11:48:31 Done.
96
97 class CONTENT_EXPORT ScopedWorkerDependencyChecker {
kinuko 2014/03/10 04:25:43 Does this class need to be exported? In a quick l
horo 2014/03/10 11:48:31 Done. Moved to .cc.
98 public:
99 explicit ScopedWorkerDependencyChecker(SharedWorkerServiceImpl* service)
100 : service_(service) {}
101 ~ScopedWorkerDependencyChecker() { service_->CheckWorkerDependency(); }
102
103 private:
104 SharedWorkerServiceImpl* service_;
105 DISALLOW_COPY_AND_ASSIGN(ScopedWorkerDependencyChecker);
106 };
90 107
91 SharedWorkerServiceImpl(); 108 SharedWorkerServiceImpl();
92 virtual ~SharedWorkerServiceImpl(); 109 virtual ~SharedWorkerServiceImpl();
93 110
111 void ResetForTesting();
112
94 SharedWorkerHost* FindSharedWorkerHost( 113 SharedWorkerHost* FindSharedWorkerHost(
95 SharedWorkerMessageFilter* filter, 114 SharedWorkerMessageFilter* filter,
96 int worker_route_id); 115 int worker_route_id);
97 116
98 SharedWorkerInstance* FindSharedWorkerInstance( 117 SharedWorkerInstance* FindSharedWorkerInstance(
99 const GURL& url, 118 const GURL& url,
100 const base::string16& name, 119 const base::string16& name,
101 const WorkerStoragePartition& worker_partition, 120 const WorkerStoragePartition& worker_partition,
102 ResourceContext* resource_context); 121 ResourceContext* resource_context);
103 122
123 // Returns the IDs of the renderer processes which are executing
124 // SharedWorkers connected to other renderer processes.
125 const std::set<int> GetRenderersWithWorkerDependency();
126
127 // Checks the worker dependency of renderer processes and calls
128 // IncrementWorkerRefCount and DecrementWorkerRefCount of
129 // RenderProcessHostImpl on UI thread if necessary.
130 void CheckWorkerDependency();
131
132 void ChangeUpdateWorkerDependencyFuncForTesting(
133 UpdateWorkerDependencyFunc new_func);
134
135 std::set<int> last_worker_depended_renderers_;
136 UpdateWorkerDependencyFunc update_worker_dependency_;
137
104 // Pair of render_process_id and worker_route_id. 138 // Pair of render_process_id and worker_route_id.
105 typedef std::pair<int, int> ProcessRouteIdPair; 139 typedef std::pair<int, int> ProcessRouteIdPair;
106 typedef base::ScopedPtrHashMap<ProcessRouteIdPair, 140 typedef base::ScopedPtrHashMap<ProcessRouteIdPair,
107 SharedWorkerHost> WorkerHostMap; 141 SharedWorkerHost> WorkerHostMap;
108 WorkerHostMap worker_hosts_; 142 WorkerHostMap worker_hosts_;
109 143
110 ObserverList<WorkerServiceObserver> observers_; 144 ObserverList<WorkerServiceObserver> observers_;
111 145
112 DISALLOW_COPY_AND_ASSIGN(SharedWorkerServiceImpl); 146 DISALLOW_COPY_AND_ASSIGN(SharedWorkerServiceImpl);
113 }; 147 };
114 148
115 } // namespace content 149 } // namespace content
116 150
117 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_ 151 #endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698