summaryrefslogtreecommitdiffstats
path: root/extensions/browser/service_worker_manager.h
blob: 2ba3ad10e1a1b82260d8ca07eb65a47c4bae616b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/macros.h"
#include "base/scoped_observer.h"
#include "extensions/browser/extension_registry_observer.h"

namespace content {
class BrowserContext;
}

namespace extensions {

// A helper class to manage extension service workers. Handles suspending
// them when the extension is unloaded and removing them when the extension is
// uninstalled.
class ServiceWorkerManager : public ExtensionRegistryObserver {
 public:
  explicit ServiceWorkerManager(content::BrowserContext* browser_context);
  ~ServiceWorkerManager() override;

 private:
  // ExtensionRegistryObserver:
  void OnExtensionUnloaded(content::BrowserContext* browser_context,
                           const Extension* extension,
                           UnloadedExtensionInfo::Reason reason) override;
  void OnExtensionUninstalled(content::BrowserContext* browser_context,
                              const Extension* extension,
                              extensions::UninstallReason reason) override;

  content::BrowserContext* browser_context_;

  ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
      registry_observer_;

  DISALLOW_COPY_AND_ASSIGN(ServiceWorkerManager);
};

}  // namespace extensions