| OLD | NEW |
| 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> |
| 11 | 11 |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 14 #include "content/common/service_worker/embedded_worker_settings.h" | 14 #include "content/common/service_worker/embedded_worker_settings.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/site_instance.h" | 17 #include "content/public/browser/site_instance.h" |
| 18 #include "content/public/common/child_process_host.h" | 18 #include "content/public/common/child_process_host.h" |
| 19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 20 #include "third_party/WebKit/public/web/WebDataSaverFlag.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Functor to sort by the .second element of a struct. | 27 // Functor to sort by the .second element of a struct. |
| 27 struct SecondGreater { | 28 struct SecondGreater { |
| 28 template <typename Value> | 29 template <typename Value> |
| 29 bool operator()(const Value& lhs, const Value& rhs) { | 30 bool operator()(const Value& lhs, const Value& rhs) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const EmbeddedWorkerSettings&)>& callback) { | 165 const EmbeddedWorkerSettings&)>& callback) { |
| 165 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 166 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 166 BrowserThread::PostTask( | 167 BrowserThread::PostTask( |
| 167 BrowserThread::UI, FROM_HERE, | 168 BrowserThread::UI, FROM_HERE, |
| 168 base::Bind(&ServiceWorkerProcessManager::AllocateWorkerProcess, | 169 base::Bind(&ServiceWorkerProcessManager::AllocateWorkerProcess, |
| 169 weak_this_, embedded_worker_id, pattern, script_url, | 170 weak_this_, embedded_worker_id, pattern, script_url, |
| 170 can_use_existing_process, callback)); | 171 can_use_existing_process, callback)); |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 | 174 |
| 174 // This |EmbeddedWorkerSettings| only populates |data_saver_enabled|, | 175 // This |EmbeddedWorkerSettings| only populates |data_saver_flag|, |
| 175 // but in general, this function will populate settings from prefs, while | 176 // but in general, this function will populate settings from prefs, while |
| 176 // the caller will be responsible for populating settings from other sources, | 177 // the caller will be responsible for populating settings from other sources, |
| 177 // such as command line switches. | 178 // such as command line switches. |
| 178 EmbeddedWorkerSettings settings; | 179 EmbeddedWorkerSettings settings; |
| 179 settings.data_saver_enabled = | 180 settings.data_saver_flag = |
| 180 GetContentClient()->browser()->IsDataSaverEnabled(browser_context_); | 181 GetContentClient()->browser()->IsDataSaverEnabled(browser_context_) |
| 182 ? blink::WebDataSaverFlag::kEnabled |
| 183 : blink::WebDataSaverFlag::kDisabled; |
| 181 | 184 |
| 182 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) { | 185 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) { |
| 183 // Let tests specify the returned process ID. Note: We may need to be able | 186 // Let tests specify the returned process ID. Note: We may need to be able |
| 184 // to specify the error code too. | 187 // to specify the error code too. |
| 185 int result = can_use_existing_process ? process_id_for_test_ | 188 int result = can_use_existing_process ? process_id_for_test_ |
| 186 : new_process_id_for_test_; | 189 : new_process_id_for_test_; |
| 187 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 190 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 188 base::Bind(callback, SERVICE_WORKER_OK, result, | 191 base::Bind(callback, SERVICE_WORKER_OK, result, |
| 189 false /* is_new_process */, settings)); | 192 false /* is_new_process */, settings)); |
| 190 return; | 193 return; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 namespace std { | 342 namespace std { |
| 340 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the | 343 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the |
| 341 // member WeakPtr to safely guard the object's lifetime when used on that | 344 // member WeakPtr to safely guard the object's lifetime when used on that |
| 342 // thread. | 345 // thread. |
| 343 void default_delete<content::ServiceWorkerProcessManager>::operator()( | 346 void default_delete<content::ServiceWorkerProcessManager>::operator()( |
| 344 content::ServiceWorkerProcessManager* ptr) const { | 347 content::ServiceWorkerProcessManager* ptr) const { |
| 345 content::BrowserThread::DeleteSoon( | 348 content::BrowserThread::DeleteSoon( |
| 346 content::BrowserThread::UI, FROM_HERE, ptr); | 349 content::BrowserThread::UI, FROM_HERE, ptr); |
| 347 } | 350 } |
| 348 } // namespace std | 351 } // namespace std |
| OLD | NEW |