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

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

Issue 62203007: Implement memory-persistent registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Working version Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/service_worker/service_worker_register_job.h"
6
7 #include "content/browser/service_worker/service_worker_registration.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "url/gurl.h"
10
11 namespace content {
12
13 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
14 const base::WeakPtr<ServiceWorkerStorage>& storage,
15 const RegistrationCompleteCallback& callback)
16 : storage_(storage), callback_(callback), weak_factory_(this) {}
17 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() {}
18
19 void ServiceWorkerRegisterJob::StartRegister(const GURL& pattern,
20 const GURL& script_url) {
21 storage_->FindRegistrationForPattern(
22 pattern,
23 base::Bind(
24 &ServiceWorkerRegisterJob::UnregisterPatternAndContinue,
25 weak_factory_.GetWeakPtr(),
26 pattern,
27 script_url,
28 base::Bind(&ServiceWorkerRegisterJob::RegisterPatternAndContinue,
29 weak_factory_.GetWeakPtr(),
30 pattern,
31 script_url,
32 base::Bind(&ServiceWorkerRegisterJob::RegisterComplete,
33 weak_factory_.GetWeakPtr()))));
kinuko 2013/11/25 08:17:10 In this way of chaining when something very bad ha
alecflett 2013/11/26 00:19:14 yes - though if we add the status field like you s
kinuko 2013/11/26 08:02:00 Ok, with status code we can short-cut, which may n
34 }
35
36 void ServiceWorkerRegisterJob::StartUnregister(const GURL& pattern) {
37 storage_->FindRegistrationForPattern(
38 pattern,
39 base::Bind(&ServiceWorkerRegisterJob::UnregisterPatternAndContinue,
40 weak_factory_.GetWeakPtr(),
41 pattern,
42 GURL(),
43 base::Bind(&ServiceWorkerRegisterJob::UnregisterComplete,
44 weak_factory_.GetWeakPtr())));
45 }
46
47 void ServiceWorkerRegisterJob::UnregisterComplete() {
48 callback_.Run(this, NULL);
49 }
50 void ServiceWorkerRegisterJob::RegisterComplete(
51 const scoped_refptr<ServiceWorkerRegistration>& registration) {
52 callback_.Run(this, registration.get());
53 }
54
55 void ServiceWorkerRegisterJob::RegisterPatternAndContinue(
56 const GURL& pattern,
57 const GURL& script_url,
58 const ServiceWorkerStorage::ResponseCallback callback) {
59 if (storage_) {
kinuko 2013/11/25 08:17:10 storage_ owns this job, so technically this should
alecflett 2013/11/26 00:19:14 Well this allows storage_ to go away in the middle
kinuko 2013/11/26 08:02:00 But storage class does own this Job instance via S
60 scoped_refptr<ServiceWorkerRegistration> registration =
61 storage_->RegisterInternal(pattern, script_url);
62 BrowserThread::PostTask(
63 BrowserThread::IO, FROM_HERE, base::Bind(callback, registration));
64 }
65 }
66
67 void ServiceWorkerRegisterJob::UnregisterPatternAndContinue(
68 const GURL& pattern,
69 const GURL& new_script_url,
70 const base::Closure& callback,
71 const scoped_refptr<ServiceWorkerRegistration>& previous_registration) {
72 if (previous_registration &&
73 (new_script_url.is_empty() ||
74 previous_registration->script_url() != new_script_url)) {
75 storage_->UnregisterInternal(pattern);
76 }
77 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback);
78 }
79
80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698