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

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

Issue 893793005: Check if there is a SW controlling the start page for app banner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and naming / comment tweaks Created 5 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_context_wrapper.h" 5 #include "content/browser/service_worker/service_worker_context_wrapper.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/barrier_closure.h" 12 #include "base/barrier_closure.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" 18 #include "content/browser/fileapi/chrome_blob_storage_context.h"
19 #include "content/browser/service_worker/service_worker_context_core.h" 19 #include "content/browser/service_worker/service_worker_context_core.h"
20 #include "content/browser/service_worker/service_worker_context_observer.h" 20 #include "content/browser/service_worker/service_worker_context_observer.h"
21 #include "content/browser/service_worker/service_worker_process_manager.h" 21 #include "content/browser/service_worker/service_worker_process_manager.h"
22 #include "content/browser/service_worker/service_worker_quota_client.h" 22 #include "content/browser/service_worker/service_worker_quota_client.h"
23 #include "content/browser/service_worker/service_worker_request_handler.h" 23 #include "content/browser/service_worker/service_worker_request_handler.h"
24 #include "content/browser/service_worker/service_worker_utils.h"
24 #include "content/browser/storage_partition_impl.h" 25 #include "content/browser/storage_partition_impl.h"
25 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/service_worker_context.h" 28 #include "content/public/browser/service_worker_context.h"
28 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
30 #include "net/base/net_util.h"
29 #include "net/url_request/url_request_context_getter.h" 31 #include "net/url_request/url_request_context_getter.h"
30 #include "storage/browser/blob/blob_storage_context.h" 32 #include "storage/browser/blob/blob_storage_context.h"
31 #include "storage/browser/quota/quota_manager_proxy.h" 33 #include "storage/browser/quota/quota_manager_proxy.h"
32 #include "storage/browser/quota/special_storage_policy.h" 34 #include "storage/browser/quota/special_storage_policy.h"
33 35
34 namespace content { 36 namespace content {
35 37
36 namespace { 38 namespace {
37 39
38 typedef std::set<std::string> HeaderNameSet; 40 typedef std::set<std::string> HeaderNameSet;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 usage_info.scopes.push_back(registration_info.pattern); 273 usage_info.scopes.push_back(registration_info.pattern);
272 usage_info.total_size_bytes += registration_info.stored_version_size_bytes; 274 usage_info.total_size_bytes += registration_info.stored_version_size_bytes;
273 } 275 }
274 276
275 for (const auto& origin_info_pair : origins) { 277 for (const auto& origin_info_pair : origins) {
276 usage_infos.push_back(origin_info_pair.second); 278 usage_infos.push_back(origin_info_pair.second);
277 } 279 }
278 callback.Run(usage_infos); 280 callback.Run(usage_infos);
279 } 281 }
280 282
283 void ServiceWorkerContextWrapper::DidFindRegistrationForCheckHasServiceWorker(
284 const GURL& other_url,
285 const CheckHasServiceWorkerCallback& callback,
286 ServiceWorkerStatusCode status,
287 const scoped_refptr<ServiceWorkerRegistration>& registration) {
288 DCHECK_CURRENTLY_ON(BrowserThread::IO);
289
290 if (status != SERVICE_WORKER_OK) {
291 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
292 base::Bind(callback, false));
293 return;
294 }
295
296 DCHECK(registration);
297 BrowserThread::PostTask(
298 BrowserThread::UI, FROM_HERE,
299 base::Bind(callback, registration->active_version() &&
300 ServiceWorkerUtils::ScopeMatches(
301 registration->pattern(), other_url)));
302 }
303
281 namespace { 304 namespace {
282 void StatusCodeToBoolCallbackAdapter( 305 void StatusCodeToBoolCallbackAdapter(
283 const ServiceWorkerContext::ResultCallback& callback, 306 const ServiceWorkerContext::ResultCallback& callback,
284 ServiceWorkerStatusCode code) { 307 ServiceWorkerStatusCode code) {
285 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); 308 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK);
286 } 309 }
287 310
288 void EmptySuccessCallback(bool success) { 311 void EmptySuccessCallback(bool success) {
289 } 312 }
290 } // namespace 313 } // namespace
(...skipping 11 matching lines...) Expand all
302 return; 325 return;
303 } 326 }
304 context()->UnregisterServiceWorkers( 327 context()->UnregisterServiceWorkers(
305 origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result)); 328 origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result));
306 } 329 }
307 330
308 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { 331 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) {
309 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); 332 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback));
310 } 333 }
311 334
335 void ServiceWorkerContextWrapper::CheckHasServiceWorker(
336 const GURL& url,
337 const GURL& other_url,
338 const CheckHasServiceWorkerCallback& callback) {
339 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
340 BrowserThread::PostTask(
341 BrowserThread::IO, FROM_HERE,
342 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this,
343 url, other_url, callback));
344 return;
345 }
346 if (!context_core_.get()) {
347 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive.";
348 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
349 base::Bind(callback, false));
350 return;
351 }
352 GURL stripped_url = net::SimplifyUrlForRequest(url);
353 context()->storage()->FindRegistrationForDocument(
354 stripped_url, base::Bind(&ServiceWorkerContextWrapper::
355 DidFindRegistrationForCheckHasServiceWorker,
356 this, other_url, callback));
357 }
358
312 void ServiceWorkerContextWrapper::AddObserver( 359 void ServiceWorkerContextWrapper::AddObserver(
313 ServiceWorkerContextObserver* observer) { 360 ServiceWorkerContextObserver* observer) {
314 observer_list_->AddObserver(observer); 361 observer_list_->AddObserver(observer);
315 } 362 }
316 363
317 void ServiceWorkerContextWrapper::RemoveObserver( 364 void ServiceWorkerContextWrapper::RemoveObserver(
318 ServiceWorkerContextObserver* observer) { 365 ServiceWorkerContextObserver* observer) {
319 observer_list_->RemoveObserver(observer); 366 observer_list_->RemoveObserver(observer);
320 } 367 }
321 368
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 context_core_.reset(); 425 context_core_.reset();
379 return; 426 return;
380 } 427 }
381 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 428 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
382 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 429 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
383 430
384 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); 431 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped);
385 } 432 }
386 433
387 } // namespace content 434 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.h ('k') | content/public/browser/service_worker_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698