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

Side by Side Diff: content/browser/service_worker/service_worker_process_manager.h

Issue 2027583002: service worker: Avoid starting up for activation during shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: maybe fix win Created 4 years, 6 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_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 // Adds/removes process reference for the |pattern|, the process with highest 76 // Adds/removes process reference for the |pattern|, the process with highest
77 // references count will be chosen to start a worker. 77 // references count will be chosen to start a worker.
78 void AddProcessReferenceToPattern(const GURL& pattern, int process_id); 78 void AddProcessReferenceToPattern(const GURL& pattern, int process_id);
79 void RemoveProcessReferenceFromPattern(const GURL& pattern, int process_id); 79 void RemoveProcessReferenceFromPattern(const GURL& pattern, int process_id);
80 80
81 // Returns true if the |pattern| has at least one process to run. 81 // Returns true if the |pattern| has at least one process to run.
82 bool PatternHasProcessToRun(const GURL& pattern) const; 82 bool PatternHasProcessToRun(const GURL& pattern) const;
83 83
84 // Returns true if Shutdown() has been called.
85 bool IsShutdown() const { return !browser_context_; }
86
84 private: 87 private:
85 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, SortProcess); 88 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, SortProcess);
86 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, 89 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest,
87 FindAvailableProcess); 90 FindAvailableProcess);
88 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, 91 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest,
89 AllocateWorkerProcess_FindAvailableProcess); 92 AllocateWorkerProcess_FindAvailableProcess);
90 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest, 93 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerProcessManagerTest,
91 AllocateWorkerProcess_InShutdown); 94 AllocateWorkerProcess_InShutdown);
92 95
93 // Information about the process for an EmbeddedWorkerInstance. 96 // Information about the process for an EmbeddedWorkerInstance.
94 struct ProcessInfo { 97 struct ProcessInfo {
95 explicit ProcessInfo(const scoped_refptr<SiteInstance>& site_instance); 98 explicit ProcessInfo(const scoped_refptr<SiteInstance>& site_instance);
96 explicit ProcessInfo(int process_id); 99 explicit ProcessInfo(int process_id);
97 ProcessInfo(const ProcessInfo& other); 100 ProcessInfo(const ProcessInfo& other);
98 ~ProcessInfo(); 101 ~ProcessInfo();
99 102
100 // Stores the SiteInstance the Worker lives inside. This needs to outlive 103 // Stores the SiteInstance the Worker lives inside. This needs to outlive
101 // the instance's use of its RPH to uphold assumptions in the 104 // the instance's use of its RPH to uphold assumptions in the
102 // ContentBrowserClient interface. 105 // ContentBrowserClient interface.
103 scoped_refptr<SiteInstance> site_instance; 106 scoped_refptr<SiteInstance> site_instance;
104 107
105 // In case the process was allocated without using a SiteInstance, we need 108 // In case the process was allocated without using a SiteInstance, we need
106 // to store a process ID to decrement a worker reference on shutdown. 109 // to store a process ID to decrement a worker reference on shutdown.
107 // TODO(jyasskin): Implement http://crbug.com/372045 or thread a frame_id in 110 // TODO(jyasskin): Implement http://crbug.com/372045 or thread a frame_id in
108 // so all processes can be allocated with a SiteInstance. 111 // so all processes can be allocated with a SiteInstance.
109 int process_id; 112 int process_id;
110 }; 113 };
111 114
112 // Returns true if Shutdown() has been called.
113 bool IsShutdown() const { return !browser_context_; }
114
115 // Maps the process ID to its reference count. 115 // Maps the process ID to its reference count.
116 typedef std::map<int, int> ProcessRefMap; 116 typedef std::map<int, int> ProcessRefMap;
117 117
118 // Maps registration scope pattern to ProcessRefMap. 118 // Maps registration scope pattern to ProcessRefMap.
119 typedef std::map<const GURL, ProcessRefMap> PatternProcessRefMap; 119 typedef std::map<const GURL, ProcessRefMap> PatternProcessRefMap;
120 120
121 // Returns a process vector sorted by the reference count for the |pattern|. 121 // Returns a process vector sorted by the reference count for the |pattern|.
122 std::vector<int> SortProcessesForPattern(const GURL& pattern) const; 122 std::vector<int> SortProcessesForPattern(const GURL& pattern) const;
123 123
124 // Returns the id of an available process for this pattern, or 124 // Returns the id of an available process for this pattern, or
(...skipping 30 matching lines...) Expand all
155 155
156 namespace std { 156 namespace std {
157 // Specialized to post the deletion to the UI thread. 157 // Specialized to post the deletion to the UI thread.
158 template <> 158 template <>
159 struct CONTENT_EXPORT default_delete<content::ServiceWorkerProcessManager> { 159 struct CONTENT_EXPORT default_delete<content::ServiceWorkerProcessManager> {
160 void operator()(content::ServiceWorkerProcessManager* ptr) const; 160 void operator()(content::ServiceWorkerProcessManager* ptr) const;
161 }; 161 };
162 } // namespace std 162 } // namespace std
163 163
164 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_ 164 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROCESS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698