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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
57 context_->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, scoped_ptr<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 : context_->GetAllLiveRegistrationInfo()) | 70 for (const auto& registration : context_->GetAllLiveRegistrationInfo()) |
71 StoreRegistrationInfo(registration, ®istration_info_map); | 71 StoreRegistrationInfo(registration, ®istration_info_map); |
72 for (const auto& version : context_->GetAllLiveVersionInfo()) | 72 for (const auto& version : context_->GetAllLiveVersionInfo()) |
73 StoreVersionInfo(version); | 73 StoreVersionInfo(version); |
74 | 74 |
75 std::vector<ServiceWorkerRegistrationInfo> registrations; | 75 std::vector<ServiceWorkerRegistrationInfo> registrations; |
76 registrations.reserve(registration_info_map.size()); | 76 registrations.reserve(registration_info_map.size()); |
(...skipping 21 matching lines...) Expand all Loading... |
98 void ServiceWorkerContextWatcher::StopOnIOThread() { | 98 void ServiceWorkerContextWatcher::StopOnIOThread() { |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 context_->RemoveObserver(this); | 100 context_->RemoveObserver(this); |
101 } | 101 } |
102 | 102 |
103 ServiceWorkerContextWatcher::~ServiceWorkerContextWatcher() { | 103 ServiceWorkerContextWatcher::~ServiceWorkerContextWatcher() { |
104 } | 104 } |
105 | 105 |
106 void ServiceWorkerContextWatcher::StoreRegistrationInfo( | 106 void ServiceWorkerContextWatcher::StoreRegistrationInfo( |
107 const ServiceWorkerRegistrationInfo& registration_info, | 107 const ServiceWorkerRegistrationInfo& registration_info, |
108 base::ScopedPtrHashMap<int64, ServiceWorkerRegistrationInfo>* info_map) { | 108 base::ScopedPtrHashMap<int64, scoped_ptr<ServiceWorkerRegistrationInfo>>* |
| 109 info_map) { |
109 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
110 if (registration_info.registration_id == kInvalidServiceWorkerRegistrationId) | 111 if (registration_info.registration_id == kInvalidServiceWorkerRegistrationId) |
111 return; | 112 return; |
112 info_map->set(registration_info.registration_id, | 113 info_map->set(registration_info.registration_id, |
113 scoped_ptr<ServiceWorkerRegistrationInfo>( | 114 scoped_ptr<ServiceWorkerRegistrationInfo>( |
114 new ServiceWorkerRegistrationInfo(registration_info))); | 115 new ServiceWorkerRegistrationInfo(registration_info))); |
115 StoreVersionInfo(registration_info.active_version); | 116 StoreVersionInfo(registration_info.active_version); |
116 StoreVersionInfo(registration_info.waiting_version); | 117 StoreVersionInfo(registration_info.waiting_version); |
117 StoreVersionInfo(registration_info.installing_version); | 118 StoreVersionInfo(registration_info.installing_version); |
118 } | 119 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 244 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
244 } | 245 } |
245 | 246 |
246 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, | 247 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, |
247 const GURL& pattern) { | 248 const GURL& pattern) { |
248 SendRegistrationInfo(registration_id, pattern, | 249 SendRegistrationInfo(registration_id, pattern, |
249 ServiceWorkerRegistrationInfo::IS_DELETED); | 250 ServiceWorkerRegistrationInfo::IS_DELETED); |
250 } | 251 } |
251 | 252 |
252 } // namespace content | 253 } // namespace content |
OLD | NEW |