michaelpg | c0145e6 | 2017-03-18 03:00:15 | [diff] [blame] | 1 | // 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 | |
| 15 | namespace extensions { |
| 16 | |
| 17 | class Extension; |
| 18 | |
| 19 | // Encapsulates a possibly asynchronous operation to verify whether a |
| 20 | // precondition holds for loading the given extension. |
| 21 | class 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, |
michaelpg | a8ea037 | 2017-04-06 20:41:35 | [diff] [blame^] | 30 | NPAPI_NOT_SUPPORTED, |
| 31 | WEBGL_NOT_SUPPORTED, |
| 32 | WINDOW_SHAPE_NOT_SUPPORTED, |
michaelpg | c0145e6 | 2017-03-18 03:00:15 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | using Errors = std::set<Error>; |
| 36 | using ResultCallback = base::OnceCallback<void(Errors)>; |
| 37 | |
| 38 | explicit PreloadCheck(scoped_refptr<const Extension> extension); |
| 39 | virtual ~PreloadCheck(); |
| 40 | |
| 41 | // This function must be called on the UI thread. The callback also occurs on |
| 42 | // the UI thread. |
| 43 | virtual void Start(ResultCallback callback) = 0; |
| 44 | |
| 45 | // Subclasses may provide an error message. |
| 46 | virtual base::string16 GetErrorMessage() const; |
| 47 | |
| 48 | const Extension* extension() { return extension_.get(); } |
| 49 | |
| 50 | private: |
| 51 | // The extension to check. |
| 52 | scoped_refptr<const Extension> extension_; |
| 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(PreloadCheck); |
| 55 | }; |
| 56 | |
| 57 | } // namespace extensions |
| 58 | |
| 59 | #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_H_ |