Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 <memory> | |
| 9 #include <unordered_set> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/strings/string16.h" | |
| 16 #include "extensions/common/extension.h" | |
| 17 | |
| 18 namespace extensions { | |
| 19 | |
| 20 // Encapsulates a possibly asynchronous operation to verify whether a | |
| 21 // precondition holds for loading the given extension. | |
| 22 class PreloadCheck { | |
| 23 public: | |
| 24 // These enumerators should only be referred to by name, so it is safe to | |
| 25 // insert or remove values as necessary. | |
| 26 enum Error { | |
| 27 NONE, | |
| 28 BLACKLISTED_ID, | |
| 29 BLACKLISTED_UNKNOWN, | |
| 30 DISALLOWED_BY_POLICY, | |
| 31 }; | |
| 32 | |
| 33 // TODO(michaelpg): Remove std::hash<int> template argument once std::hash | |
| 34 // directly supports enums. | |
| 35 // See http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148 | |
| 36 using Errors = std::unordered_set<Error, std::hash<int>>; | |
|
Devlin
2017/03/14 01:44:34
Any reason to use unordered_set here? Seems like
michaelpg
2017/03/14 21:58:30
/shrug/ std::set sgtm
| |
| 37 using ResultCallback = base::OnceCallback<void(Errors)>; | |
| 38 | |
| 39 explicit PreloadCheck(scoped_refptr<const Extension> extension); | |
| 40 virtual ~PreloadCheck(); | |
| 41 | |
| 42 // This function must be called on the UI thread. The callback also occurs on | |
| 43 // the UI thread. | |
| 44 virtual void Start(ResultCallback callback) = 0; | |
| 45 | |
| 46 // Subclasses may provide an error message. | |
| 47 virtual base::string16 GetErrorMessage() const; | |
| 48 | |
| 49 const Extension* extension() { return extension_.get(); } | |
| 50 | |
| 51 private: | |
| 52 // The extension to check. | |
| 53 scoped_refptr<const Extension> extension_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(PreloadCheck); | |
| 56 }; | |
| 57 | |
| 58 } // namespace extensions | |
| 59 | |
| 60 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_H_ | |
| OLD | NEW |