OLD | NEW |
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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
9 #include "content/browser/service_worker/service_worker_context_observer.h" | 9 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 10 #include "content/browser/service_worker/service_worker_process_manager.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "webkit/browser/quota/quota_manager_proxy.h" | 12 #include "webkit/browser/quota/quota_manager_proxy.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper() | 16 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
| 17 BrowserContext* browser_context) |
16 : observer_list_( | 18 : observer_list_( |
17 new ObserverListThreadSafe<ServiceWorkerContextObserver>()) {} | 19 new ObserverListThreadSafe<ServiceWorkerContextObserver>()), |
| 20 browser_context_(browser_context) { |
| 21 } |
18 | 22 |
19 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { | 23 ServiceWorkerContextWrapper::~ServiceWorkerContextWrapper() { |
20 } | 24 } |
21 | 25 |
22 void ServiceWorkerContextWrapper::Init( | 26 void ServiceWorkerContextWrapper::Init( |
23 const base::FilePath& user_data_directory, | 27 const base::FilePath& user_data_directory, |
24 quota::QuotaManagerProxy* quota_manager_proxy) { | 28 quota::QuotaManagerProxy* quota_manager_proxy) { |
25 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 29 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
26 BrowserThread::PostTask( | 30 BrowserThread::PostTask( |
27 BrowserThread::IO, FROM_HERE, | 31 BrowserThread::IO, |
28 base::Bind(&ServiceWorkerContextWrapper::Init, this, | 32 FROM_HERE, |
| 33 base::Bind(&ServiceWorkerContextWrapper::Init, |
| 34 this, |
29 user_data_directory, | 35 user_data_directory, |
30 make_scoped_refptr(quota_manager_proxy))); | 36 make_scoped_refptr(quota_manager_proxy))); |
31 return; | 37 return; |
32 } | 38 } |
33 DCHECK(!context_core_); | 39 DCHECK(!context_core_); |
34 context_core_.reset(new ServiceWorkerContextCore( | 40 context_core_.reset(new ServiceWorkerContextCore( |
35 user_data_directory, quota_manager_proxy, observer_list_)); | 41 user_data_directory, |
| 42 quota_manager_proxy, |
| 43 observer_list_, |
| 44 make_scoped_ptr(new ServiceWorkerProcessManager(this)))); |
36 } | 45 } |
37 | 46 |
38 void ServiceWorkerContextWrapper::Shutdown() { | 47 void ServiceWorkerContextWrapper::Shutdown() { |
39 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 48 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 browser_context_ = NULL; |
40 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
41 BrowserThread::IO, FROM_HERE, | 52 BrowserThread::IO, FROM_HERE, |
42 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); | 53 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); |
43 return; | 54 return; |
44 } | 55 } |
45 context_core_.reset(); | 56 context_core_.reset(); |
46 } | 57 } |
47 | 58 |
48 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 59 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
49 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
50 return context_core_.get(); | 61 return context_core_.get(); |
51 } | 62 } |
52 | 63 |
53 static void FinishRegistrationOnIO( | 64 static void FinishRegistrationOnIO( |
54 const ServiceWorkerContext::ResultCallback& continuation, | 65 const ServiceWorkerContext::ResultCallback& continuation, |
55 ServiceWorkerStatusCode status, | 66 ServiceWorkerStatusCode status, |
56 int64 registration_id, | 67 int64 registration_id, |
57 int64 version_id) { | 68 int64 version_id) { |
58 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
59 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
60 BrowserThread::UI, | 71 BrowserThread::UI, |
61 FROM_HERE, | 72 FROM_HERE, |
62 base::Bind(continuation, status == SERVICE_WORKER_OK)); | 73 base::Bind(continuation, status == SERVICE_WORKER_OK)); |
63 } | 74 } |
64 | 75 |
65 void ServiceWorkerContextWrapper::RegisterServiceWorker( | 76 void ServiceWorkerContextWrapper::RegisterServiceWorker( |
66 const GURL& pattern, | 77 const GURL& pattern, |
67 const GURL& script_url, | 78 const GURL& script_url, |
68 int source_process_id, | |
69 const ResultCallback& continuation) { | 79 const ResultCallback& continuation) { |
70 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 80 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
71 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
72 BrowserThread::IO, | 82 BrowserThread::IO, |
73 FROM_HERE, | 83 FROM_HERE, |
74 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker, | 84 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker, |
75 this, | 85 this, |
76 pattern, | 86 pattern, |
77 script_url, | 87 script_url, |
78 source_process_id, | |
79 continuation)); | 88 continuation)); |
80 return; | 89 return; |
81 } | 90 } |
82 | 91 |
83 context()->RegisterServiceWorker( | 92 context()->RegisterServiceWorker( |
84 pattern, | 93 pattern, |
85 script_url, | 94 script_url, |
86 source_process_id, | 95 -1, |
87 NULL /* provider_host */, | 96 NULL /* provider_host */, |
88 base::Bind(&FinishRegistrationOnIO, continuation)); | 97 base::Bind(&FinishRegistrationOnIO, continuation)); |
89 } | 98 } |
90 | 99 |
91 static void FinishUnregistrationOnIO( | 100 static void FinishUnregistrationOnIO( |
92 const ServiceWorkerContext::ResultCallback& continuation, | 101 const ServiceWorkerContext::ResultCallback& continuation, |
93 ServiceWorkerStatusCode status) { | 102 ServiceWorkerStatusCode status) { |
94 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 103 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
95 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
96 BrowserThread::UI, | 105 BrowserThread::UI, |
(...skipping 28 matching lines...) Expand all Loading... |
125 ServiceWorkerContextObserver* observer) { | 134 ServiceWorkerContextObserver* observer) { |
126 observer_list_->AddObserver(observer); | 135 observer_list_->AddObserver(observer); |
127 } | 136 } |
128 | 137 |
129 void ServiceWorkerContextWrapper::RemoveObserver( | 138 void ServiceWorkerContextWrapper::RemoveObserver( |
130 ServiceWorkerContextObserver* observer) { | 139 ServiceWorkerContextObserver* observer) { |
131 observer_list_->RemoveObserver(observer); | 140 observer_list_->RemoveObserver(observer); |
132 } | 141 } |
133 | 142 |
134 } // namespace content | 143 } // namespace content |
OLD | NEW |