blob: 5050d542ba58ac883f7432455438fab52d2d3516 [file] [log] [blame]
michaelpgc0145e62017-03-18 03:00:151// Copyright 2017 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.
4
5#ifndef EXTENSIONS_BROWSER_PRELOAD_CHECK_H_
6#define EXTENSIONS_BROWSER_PRELOAD_CHECK_H_
7
8#include <set>
9
10#include "base/callback.h"
11#include "base/macros.h"
12#include "base/memory/ref_counted.h"
13#include "base/strings/string16.h"
14
15namespace extensions {
16
17class Extension;
18
19// Encapsulates a possibly asynchronous operation to verify whether a
20// precondition holds for loading the given extension.
21class PreloadCheck {
22 public:
23 // These enumerators should only be referred to by name, so it is safe to
24 // insert or remove values as necessary.
25 enum Error {
26 NONE,
27 BLACKLISTED_ID,
28 BLACKLISTED_UNKNOWN,
29 DISALLOWED_BY_POLICY,
30 };
31
32 using Errors = std::set<Error>;
33 using ResultCallback = base::OnceCallback<void(Errors)>;
34
35 explicit PreloadCheck(scoped_refptr<const Extension> extension);
36 virtual ~PreloadCheck();
37
38 // This function must be called on the UI thread. The callback also occurs on
39 // the UI thread.
40 virtual void Start(ResultCallback callback) = 0;
41
42 // Subclasses may provide an error message.
43 virtual base::string16 GetErrorMessage() const;
44
45 const Extension* extension() { return extension_.get(); }
46
47 private:
48 // The extension to check.
49 scoped_refptr<const Extension> extension_;
50
51 DISALLOW_COPY_AND_ASSIGN(PreloadCheck);
52};
53
54} // namespace extensions
55
56#endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_H_