Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_watcher.h" | 5 #include "content/browser/service_worker/service_worker_context_watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.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_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 void ServiceWorkerContextWatcher::Stop() { | 48 void ServiceWorkerContextWatcher::Stop() { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
| 51 BrowserThread::IO, FROM_HERE, | 51 BrowserThread::IO, FROM_HERE, |
| 52 base::Bind(&ServiceWorkerContextWatcher::StopOnIOThread, this)); | 52 base::Bind(&ServiceWorkerContextWatcher::StopOnIOThread, this)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void ServiceWorkerContextWatcher::GetStoredRegistrationsOnIOThread() { | 55 void ServiceWorkerContextWatcher::GetStoredRegistrationsOnIOThread() { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 context_->context()->storage()->GetAllRegistrations(base::Bind( | 57 context_->GetAllRegistrations(base::Bind( |
| 58 &ServiceWorkerContextWatcher::OnStoredRegistrationsOnIOThread, this)); | 58 &ServiceWorkerContextWatcher::OnStoredRegistrationsOnIOThread, this)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ServiceWorkerContextWatcher::OnStoredRegistrationsOnIOThread( | 61 void ServiceWorkerContextWatcher::OnStoredRegistrationsOnIOThread( |
| 62 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 62 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 64 context_->AddObserver(this); | 64 context_->AddObserver(this); |
| 65 | 65 |
| 66 base::ScopedPtrHashMap<int64, ServiceWorkerRegistrationInfo> | 66 base::ScopedPtrHashMap<int64, ServiceWorkerRegistrationInfo> |
| 67 registration_info_map; | 67 registration_info_map; |
| 68 for (const auto& registration : stored_registrations) | 68 for (const auto& registration : stored_registrations) |
| 69 StoreRegistrationInfo(registration, ®istration_info_map); | 69 StoreRegistrationInfo(registration, ®istration_info_map); |
| 70 for (const auto& registration : | 70 for (const auto& registration : context_->GetAllLiveRegistrationInfo()) { |
| 71 context_->context()->GetAllLiveRegistrationInfo()) { | |
| 72 StoreRegistrationInfo(registration, ®istration_info_map); | 71 StoreRegistrationInfo(registration, ®istration_info_map); |
| 73 } | 72 } |
|
falken
2015/04/15 08:03:20
nit: braces not needed
nhiroki
2015/04/15 23:38:16
Done.
| |
| 74 for (const auto& version : context_->context()->GetAllLiveVersionInfo()) | 73 for (const auto& version : context_->GetAllLiveVersionInfo()) |
| 75 StoreVersionInfo(version); | 74 StoreVersionInfo(version); |
| 76 | 75 |
| 77 std::vector<ServiceWorkerRegistrationInfo> registrations; | 76 std::vector<ServiceWorkerRegistrationInfo> registrations; |
| 78 registrations.reserve(registration_info_map.size()); | 77 registrations.reserve(registration_info_map.size()); |
| 79 for (const auto& registration_id_info_pair : registration_info_map) | 78 for (const auto& registration_id_info_pair : registration_info_map) |
| 80 registrations.push_back(*registration_id_info_pair.second); | 79 registrations.push_back(*registration_id_info_pair.second); |
| 81 | 80 |
| 82 std::vector<ServiceWorkerVersionInfo> versions; | 81 std::vector<ServiceWorkerVersionInfo> versions; |
| 83 versions.reserve(version_info_map_.size()); | 82 versions.reserve(version_info_map_.size()); |
| 84 | 83 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 244 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
| 246 } | 245 } |
| 247 | 246 |
| 248 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, | 247 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, |
| 249 const GURL& pattern) { | 248 const GURL& pattern) { |
| 250 SendRegistrationInfo(registration_id, pattern, | 249 SendRegistrationInfo(registration_id, pattern, |
| 251 ServiceWorkerRegistrationInfo::IS_DELETED); | 250 ServiceWorkerRegistrationInfo::IS_DELETED); |
| 252 } | 251 } |
| 253 | 252 |
| 254 } // namespace content | 253 } // namespace content |
| OLD | NEW |