summaryrefslogtreecommitdiffstats
path: root/extensions/browser/uninstall_ping_sender.h
blob: a349d5c0e8c64f3558bebb20bdd8f3de9b88759b (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
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016 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.

#ifndef EXTENSIONS_BROWSER_UNINSTALL_PING_SENDER_H_
#define EXTENSIONS_BROWSER_UNINSTALL_PING_SENDER_H_

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

namespace content {
class BrowserContext;
}

namespace extensions {

// A class that watches the ExtensionRegistry for uninstall events, and
// uses the UpdateService to send uninstall pings.
class UninstallPingSender : public ExtensionRegistryObserver {
 public:
  enum FilterResult { SEND_PING, DO_NOT_SEND_PING };

  // A callback function that will be called each time an extension is
  // uninstalled, with the result used to determine if a ping should be
  // sent or not.
  using Filter = base::Callback<FilterResult(const Extension* extension,
                                             UninstallReason reason)>;

  UninstallPingSender(ExtensionRegistry* registry, const Filter& filter);
  ~UninstallPingSender() override;

 protected:
  // ExtensionRegistryObserver:
  void OnExtensionUninstalled(content::BrowserContext* browser_context,
                              const Extension* extension,
                              UninstallReason reason) override;

  // Callback for determining whether to send uninstall pings.
  Filter filter_;

  ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> observer_;

 private:
  DISALLOW_COPY_AND_ASSIGN(UninstallPingSender);
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_UNINSTALL_PING_SENDER_H_