Chromium Code Reviews| 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/browser/service_worker/service_worker_process_manager.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 29 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 30 BrowserThread::PostTask( | 30 BrowserThread::PostTask( |
| 31 BrowserThread::IO, | 31 BrowserThread::IO, |
| 32 FROM_HERE, | 32 FROM_HERE, |
| 33 base::Bind(&ServiceWorkerContextWrapper::Init, | 33 base::Bind(&ServiceWorkerContextWrapper::Init, |
| 34 this, | 34 this, |
| 35 user_data_directory, | 35 user_data_directory, |
| 36 make_scoped_refptr(quota_manager_proxy))); | 36 make_scoped_refptr(quota_manager_proxy))); |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 observer_list_->AddObserver(this); | |
| 39 DCHECK(!context_core_); | 40 DCHECK(!context_core_); |
| 40 context_core_.reset(new ServiceWorkerContextCore( | 41 context_core_.reset(new ServiceWorkerContextCore( |
| 41 user_data_directory, | 42 user_data_directory, |
| 42 quota_manager_proxy, | 43 quota_manager_proxy, |
| 43 observer_list_, | 44 observer_list_, |
| 44 make_scoped_ptr(new ServiceWorkerProcessManager(this)))); | 45 make_scoped_ptr(new ServiceWorkerProcessManager(this)))); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ServiceWorkerContextWrapper::Shutdown() { | 48 void ServiceWorkerContextWrapper::Shutdown() { |
| 48 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 49 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 browser_context_ = NULL; | 51 browser_context_ = NULL; |
| 51 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| 52 BrowserThread::IO, FROM_HERE, | 53 BrowserThread::IO, FROM_HERE, |
| 53 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); | 54 base::Bind(&ServiceWorkerContextWrapper::Shutdown, this)); |
| 54 return; | 55 return; |
| 55 } | 56 } |
| 57 observer_list_->RemoveObserver(this); | |
| 56 // Breaks the reference cycle through ServiceWorkerProcessManager. | 58 // Breaks the reference cycle through ServiceWorkerProcessManager. |
| 57 context_core_.reset(); | 59 context_core_.reset(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 62 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 62 return context_core_.get(); | 64 return context_core_.get(); |
| 63 } | 65 } |
| 64 | 66 |
| 65 static void FinishRegistrationOnIO( | 67 static void FinishRegistrationOnIO( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 pattern, | 122 pattern, |
| 121 continuation)); | 123 continuation)); |
| 122 return; | 124 return; |
| 123 } | 125 } |
| 124 | 126 |
| 125 context()->UnregisterServiceWorker( | 127 context()->UnregisterServiceWorker( |
| 126 pattern, | 128 pattern, |
| 127 base::Bind(&FinishUnregistrationOnIO, continuation)); | 129 base::Bind(&FinishUnregistrationOnIO, continuation)); |
| 128 } | 130 } |
| 129 | 131 |
| 132 void ServiceWorkerContextWrapper::AddStatusChangeObserver( | |
| 133 StatusChangeObserver* observer) { | |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 135 status_change_observers_.AddObserver(observer); | |
| 136 } | |
| 137 | |
| 138 void ServiceWorkerContextWrapper::RemoveStatusChangeObserver( | |
| 139 StatusChangeObserver* observer) { | |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 141 status_change_observers_.RemoveObserver(observer); | |
| 142 } | |
| 143 | |
| 130 void ServiceWorkerContextWrapper::AddObserver( | 144 void ServiceWorkerContextWrapper::AddObserver( |
| 131 ServiceWorkerContextObserver* observer) { | 145 ServiceWorkerContextObserver* observer) { |
| 132 observer_list_->AddObserver(observer); | 146 observer_list_->AddObserver(observer); |
| 133 } | 147 } |
| 134 | 148 |
| 135 void ServiceWorkerContextWrapper::RemoveObserver( | 149 void ServiceWorkerContextWrapper::RemoveObserver( |
| 136 ServiceWorkerContextObserver* observer) { | 150 ServiceWorkerContextObserver* observer) { |
| 137 observer_list_->RemoveObserver(observer); | 151 observer_list_->RemoveObserver(observer); |
| 138 } | 152 } |
| 139 | 153 |
| 154 void ServiceWorkerContextWrapper::GetRunningServiceWorkerInfo( | |
| 155 const GetRunningServiceWorkerInfoCallback& callback) { | |
| 156 // TODO(horo): Implement this. | |
| 157 NOTIMPLEMENTED(); | |
| 158 } | |
| 159 | |
| 160 void ServiceWorkerContextWrapper::OnWorkerStarted(int64 version_id, | |
| 161 int process_id, | |
| 162 int thread_id) { | |
| 163 NotifyStatusChangeObservers(); | |
| 164 } | |
| 165 | |
| 166 void ServiceWorkerContextWrapper::OnWorkerStopped(int64 version_id, | |
| 167 int process_id, | |
| 168 int thread_id) { | |
| 169 NotifyStatusChangeObservers(); | |
| 170 } | |
| 171 | |
| 172 void ServiceWorkerContextWrapper::OnVersionStateChanged(int64 version_id) { | |
|
michaeln
2014/05/05 21:01:15
does the devtools use case care about this one?
| |
| 173 NotifyStatusChangeObservers(); | |
| 174 } | |
| 175 | |
| 176 void ServiceWorkerContextWrapper::NotifyStatusChangeObservers() { | |
| 177 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 178 BrowserThread::PostTask( | |
| 179 BrowserThread::UI, | |
| 180 FROM_HERE, | |
| 181 base::Bind(&ServiceWorkerContextWrapper::NotifyStatusChangeObservers, | |
| 182 this)); | |
| 183 return; | |
| 184 } | |
| 185 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 186 FOR_EACH_OBSERVER( | |
| 187 StatusChangeObserver, status_change_observers_, OnStatusChanged()); | |
| 188 } | |
| 189 | |
| 140 } // namespace content | 190 } // namespace content |
| OLD | NEW |