| 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "content/browser/service_worker/service_worker_context_observer.h" | 12 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 13 #include "content/browser/service_worker/service_worker_info.h" | 13 #include "content/browser/service_worker/service_worker_info.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 class ServiceWorkerContextWrapper; | 17 class ServiceWorkerContextWrapper; |
| 18 | 18 |
| 19 // Used to monitor the status change of the ServiceWorker registrations and | 19 // Used to monitor the status change of the ServiceWorker registrations and |
| 20 // versions in the ServiceWorkerContext from UI thread. | 20 // versions in the ServiceWorkerContext from UI thread. |
| 21 class ServiceWorkerContextWatcher | 21 class ServiceWorkerContextWatcher |
| 22 : public ServiceWorkerContextObserver, | 22 : public ServiceWorkerContextObserver, |
| 23 public base::RefCountedThreadSafe<ServiceWorkerContextWatcher> { | 23 public base::RefCountedThreadSafe<ServiceWorkerContextWatcher> { |
| 24 public: | 24 public: |
| 25 typedef base::Callback<void( | 25 typedef base::Callback<void( |
| 26 const std::vector<ServiceWorkerRegistrationInfo>&)> | 26 const std::vector<ServiceWorkerRegistrationInfo>&)> |
| 27 WorkerRegistrationUpdatedCallback; | 27 WorkerRegistrationUpdatedCallback; |
| 28 typedef base::Callback<void(const std::vector<ServiceWorkerVersionInfo>&)> | 28 typedef base::Callback<void(const std::vector<ServiceWorkerVersionInfo>&)> |
| 29 WorkerVersionUpdatedCallback; | 29 WorkerVersionUpdatedCallback; |
| 30 typedef base::Callback<void(int64 /* registration_id */, |
| 31 int64 /* version_id */, |
| 32 const ErrorInfo&)> WorkerErrorReportedCallback; |
| 33 |
| 30 ServiceWorkerContextWatcher( | 34 ServiceWorkerContextWatcher( |
| 31 scoped_refptr<ServiceWorkerContextWrapper> context, | 35 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 32 const WorkerRegistrationUpdatedCallback& registration_callback, | 36 const WorkerRegistrationUpdatedCallback& registration_callback, |
| 33 const WorkerVersionUpdatedCallback& version_callback); | 37 const WorkerVersionUpdatedCallback& version_callback, |
| 38 const WorkerErrorReportedCallback& error_callback); |
| 34 void Start(); | 39 void Start(); |
| 35 void Stop(); | 40 void Stop(); |
| 36 | 41 |
| 37 private: | 42 private: |
| 38 friend class base::RefCountedThreadSafe<ServiceWorkerContextWatcher>; | 43 friend class base::RefCountedThreadSafe<ServiceWorkerContextWatcher>; |
| 39 ~ServiceWorkerContextWatcher() override; | 44 ~ServiceWorkerContextWatcher() override; |
| 40 | 45 |
| 41 void GetStoredRegistrationsOnIOThread(); | 46 void GetStoredRegistrationsOnIOThread(); |
| 42 void OnStoredRegistrationsOnIOThread( | 47 void OnStoredRegistrationsOnIOThread( |
| 43 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations); | 48 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 const GURL& pattern) override; | 64 const GURL& pattern) override; |
| 60 void OnNewLiveVersion(int64 version_id, | 65 void OnNewLiveVersion(int64 version_id, |
| 61 int64 registration_id, | 66 int64 registration_id, |
| 62 const GURL& script_url) override; | 67 const GURL& script_url) override; |
| 63 void OnRunningStateChanged( | 68 void OnRunningStateChanged( |
| 64 int64 version_id, | 69 int64 version_id, |
| 65 content::ServiceWorkerVersion::RunningStatus running_status) override; | 70 content::ServiceWorkerVersion::RunningStatus running_status) override; |
| 66 void OnVersionStateChanged( | 71 void OnVersionStateChanged( |
| 67 int64 version_id, | 72 int64 version_id, |
| 68 content::ServiceWorkerVersion::Status status) override; | 73 content::ServiceWorkerVersion::Status status) override; |
| 74 void OnErrorReported(int64 version_id, |
| 75 int process_id, |
| 76 int thread_id, |
| 77 const ErrorInfo& info) override; |
| 69 void OnRegistrationStored(int64 registration_id, | 78 void OnRegistrationStored(int64 registration_id, |
| 70 const GURL& pattern) override; | 79 const GURL& pattern) override; |
| 71 void OnRegistrationDeleted(int64 registration_id, | 80 void OnRegistrationDeleted(int64 registration_id, |
| 72 const GURL& pattern) override; | 81 const GURL& pattern) override; |
| 73 | 82 |
| 74 base::ScopedPtrHashMap<int64, ServiceWorkerVersionInfo> version_info_map_; | 83 base::ScopedPtrHashMap<int64, ServiceWorkerVersionInfo> version_info_map_; |
| 75 scoped_refptr<ServiceWorkerContextWrapper> context_; | 84 scoped_refptr<ServiceWorkerContextWrapper> context_; |
| 76 WorkerRegistrationUpdatedCallback registration_callback_; | 85 WorkerRegistrationUpdatedCallback registration_callback_; |
| 77 WorkerVersionUpdatedCallback version_callback_; | 86 WorkerVersionUpdatedCallback version_callback_; |
| 87 WorkerErrorReportedCallback error_callback_; |
| 78 }; | 88 }; |
| 79 | 89 |
| 80 } // namespace content | 90 } // namespace content |
| 81 | 91 |
| 82 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ | 92 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_ |
| OLD | NEW |