Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_context_watcher.h
blob9e7fb5383733f540b1211256d58c3fd127c8f8bb
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, scoped_ptr<ServiceWorkerRegistrationInfo>>*
54 info_map);
55 void StoreVersionInfo(const ServiceWorkerVersionInfo& version);
57 void SendRegistrationInfo(
58 int64 registration_id,
59 const GURL& pattern,
60 ServiceWorkerRegistrationInfo::DeleteFlag delete_flag);
61 void SendVersionInfo(const ServiceWorkerVersionInfo& version);
63 // ServiceWorkerContextObserver implements
64 void OnNewLiveRegistration(int64 registration_id,
65 const GURL& pattern) override;
66 void OnNewLiveVersion(int64 version_id,
67 int64 registration_id,
68 const GURL& script_url) override;
69 void OnRunningStateChanged(
70 int64 version_id,
71 content::ServiceWorkerVersion::RunningStatus running_status) override;
72 void OnVersionStateChanged(
73 int64 version_id,
74 content::ServiceWorkerVersion::Status status) override;
75 void OnMainScriptHttpResponseInfoSet(
76 int64 version_id,
77 base::Time script_response_time,
78 base::Time script_last_modified) override;
79 void OnErrorReported(int64 version_id,
80 int process_id,
81 int thread_id,
82 const ErrorInfo& info) override;
83 void OnReportConsoleMessage(int64 version_id,
84 int process_id,
85 int thread_id,
86 const ConsoleMessage& message) override;
87 void OnControlleeAdded(int64 version_id,
88 const std::string& uuid,
89 int process_id,
90 int route_id,
91 ServiceWorkerProviderType type) override;
92 void OnControlleeRemoved(int64 version_id, const std::string& uuid) override;
93 void OnRegistrationStored(int64 registration_id,
94 const GURL& pattern) override;
95 void OnRegistrationDeleted(int64 registration_id,
96 const GURL& pattern) override;
98 base::ScopedPtrHashMap<int64, scoped_ptr<ServiceWorkerVersionInfo>>
99 version_info_map_;
100 scoped_refptr<ServiceWorkerContextWrapper> context_;
101 WorkerRegistrationUpdatedCallback registration_callback_;
102 WorkerVersionUpdatedCallback version_callback_;
103 WorkerErrorReportedCallback error_callback_;
106 } // namespace content
108 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_WATCHER_H_