Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_context_watcher.h
bloba6d8d0a7b8a5e95cb4cd194a79075ee208563767
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "content/browser/service_worker/service_worker_context_observer.h"
13 #include "content/browser/service_worker/service_worker_info.h"
15 namespace content {
17 class ServiceWorkerContextWrapper;
19 // Used to monitor the status change of the ServiceWorker registrations and
20 // versions in the ServiceWorkerContext from UI thread.
21 class ServiceWorkerContextWatcher
22 : public ServiceWorkerContextObserver,
23 public base::RefCountedThreadSafe<ServiceWorkerContextWatcher> {
24 public:
25 typedef base::Callback<void(
26 const std::vector<ServiceWorkerRegistrationInfo>&)>
27 WorkerRegistrationUpdatedCallback;
28 typedef base::Callback<void(const std::vector<ServiceWorkerVersionInfo>&)>
29 WorkerVersionUpdatedCallback;
30 typedef base::Callback<void(int64 /* registration_id */,
31 int64 /* version_id */,
32 const ErrorInfo&)> WorkerErrorReportedCallback;
34 ServiceWorkerContextWatcher(
35 scoped_refptr<ServiceWorkerContextWrapper> context,
36 const WorkerRegistrationUpdatedCallback& registration_callback,
37 const WorkerVersionUpdatedCallback& version_callback,
38 const WorkerErrorReportedCallback& error_callback);
39 void Start();
40 void Stop();
42 private:
43 friend class base::RefCountedThreadSafe<ServiceWorkerContextWatcher>;
44 ~ServiceWorkerContextWatcher() override;
46 void GetStoredRegistrationsOnIOThread();
47 void OnStoredRegistrationsOnIOThread(
48 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations);
49 void StopOnIOThread();
51 void StoreRegistrationInfo(
52 const ServiceWorkerRegistrationInfo& registration,
53 base::ScopedPtrHashMap<int64, ServiceWorkerRegistrationInfo>* info_map);
54 void StoreVersionInfo(const ServiceWorkerVersionInfo& version);
56 void SendRegistrationInfo(
57 int64 registration_id,
58 const GURL& pattern,
59 ServiceWorkerRegistrationInfo::DeleteFlag delete_flag);
60 void SendVersionInfo(const ServiceWorkerVersionInfo& version);
62 // ServiceWorkerContextObserver implements
63 void OnNewLiveRegistration(int64 registration_id,
64 const GURL& pattern) override;
65 void OnNewLiveVersion(int64 version_id,
66 int64 registration_id,
67 const GURL& script_url) override;
68 void OnRunningStateChanged(
69 int64 version_id,
70 content::ServiceWorkerVersion::RunningStatus running_status) override;
71 void OnVersionStateChanged(
72 int64 version_id,
73 content::ServiceWorkerVersion::Status status) override;
74 void OnMainScriptHttpResponseInfoSet(
75 int64 version_id,
76 base::Time script_response_time,
77 base::Time script_last_modified) override;
78 void OnErrorReported(int64 version_id,
79 int process_id,
80 int thread_id,
81 const ErrorInfo& info) override;
82 void OnReportConsoleMessage(int64 version_id,
83 int process_id,
84 int thread_id,
85 const ConsoleMessage& message) override;
86 void OnRegistrationStored(int64 registration_id,
87 const GURL& pattern) override;
88 void OnRegistrationDeleted(int64 registration_id,
89 const GURL& pattern) override;
91 base::ScopedPtrHashMap<int64, ServiceWorkerVersionInfo> version_info_map_;
92 scoped_refptr<ServiceWorkerContextWrapper> context_;
93 WorkerRegistrationUpdatedCallback registration_callback_;
94 WorkerVersionUpdatedCallback version_callback_;
95 WorkerErrorReportedCallback error_callback_;
98 } // namespace content
100 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_