blob: 8c92a231cd9c13773cde0a83724b18b1c2ed0c78 [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,
michaelpga8ea0372017-04-06 20:41:3530 WEBGL_NOT_SUPPORTED,
31 WINDOW_SHAPE_NOT_SUPPORTED,
michaelpgc0145e62017-03-18 03:00:1532 };
33
34 using Errors = std::set<Error>;
Istiaque Ahmed400c83a2017-10-11 02:39:3535 using ResultCallback = base::OnceCallback<void(const Errors&)>;
michaelpgc0145e62017-03-18 03:00:1536
37 explicit PreloadCheck(scoped_refptr<const Extension> extension);
38 virtual ~PreloadCheck();
39
40 // This function must be called on the UI thread. The callback also occurs on
41 // the UI thread.
42 virtual void Start(ResultCallback callback) = 0;
43
44 // Subclasses may provide an error message.
45 virtual base::string16 GetErrorMessage() const;
46
47 const Extension* extension() { return extension_.get(); }
48
49 private:
50 // The extension to check.
51 scoped_refptr<const Extension> extension_;
52
53 DISALLOW_COPY_AND_ASSIGN(PreloadCheck);
54};
55
56} // namespace extensions
57
58#endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_H_