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

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

Issue 2118243002: [proof-of-concept] SW thread independent of the main thread Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 3 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 #include "content/browser/service_worker/service_worker_process_manager.h" 5 #include "content/browser/service_worker/service_worker_process_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 std::vector<std::pair<int, int> > counted( 294 std::vector<std::pair<int, int> > counted(
295 it->second.begin(), it->second.end()); 295 it->second.begin(), it->second.end());
296 std::sort(counted.begin(), counted.end(), SecondGreater()); 296 std::sort(counted.begin(), counted.end(), SecondGreater());
297 297
298 std::vector<int> result(counted.size()); 298 std::vector<int> result(counted.size());
299 for (size_t i = 0; i < counted.size(); ++i) 299 for (size_t i = 0; i < counted.size(); ++i)
300 result[i] = counted[i].first; 300 result[i] = counted[i].first;
301 return result; 301 return result;
302 } 302 }
303 303
304 void ServiceWorkerProcessManager::FindAvailableProcessAndCallbackOnUI(
305 const GURL& pattern,
306 const base::Callback<void(int)> callback) {
307 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
308 BrowserThread::PostTask(
309 BrowserThread::UI, FROM_HERE,
310 base::Bind(
311 &ServiceWorkerProcessManager::FindAvailableProcessAndCallbackOnUI,
312 weak_this_, pattern, callback));
313 return;
314 }
315 callback.Run(FindAvailableProcess(pattern));
316 }
317
304 int ServiceWorkerProcessManager::FindAvailableProcess(const GURL& pattern) { 318 int ServiceWorkerProcessManager::FindAvailableProcess(const GURL& pattern) {
305 RenderProcessHost* backgrounded_candidate = nullptr; 319 RenderProcessHost* backgrounded_candidate = nullptr;
306 320
307 // Try to find an available foreground process. 321 // Try to find an available foreground process.
308 std::vector<int> sorted_candidates = SortProcessesForPattern(pattern); 322 std::vector<int> sorted_candidates = SortProcessesForPattern(pattern);
309 for (int process_id : sorted_candidates) { 323 for (int process_id : sorted_candidates) {
310 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); 324 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
311 if (!rph || rph->FastShutdownStarted()) 325 if (!rph || rph->FastShutdownStarted())
312 continue; 326 continue;
313 327
(...skipping 19 matching lines...) Expand all
333 namespace std { 347 namespace std {
334 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the 348 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the
335 // member WeakPtr to safely guard the object's lifetime when used on that 349 // member WeakPtr to safely guard the object's lifetime when used on that
336 // thread. 350 // thread.
337 void default_delete<content::ServiceWorkerProcessManager>::operator()( 351 void default_delete<content::ServiceWorkerProcessManager>::operator()(
338 content::ServiceWorkerProcessManager* ptr) const { 352 content::ServiceWorkerProcessManager* ptr) const {
339 content::BrowserThread::DeleteSoon( 353 content::BrowserThread::DeleteSoon(
340 content::BrowserThread::UI, FROM_HERE, ptr); 354 content::BrowserThread::UI, FROM_HERE, ptr);
341 } 355 }
342 } // namespace std 356 } // namespace std
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698