 Chromium Code Reviews
 Chromium Code Reviews Issue 2693373003:
  PreloadCheck class for extension pre-install checks  (Closed)
    
  
    Issue 2693373003:
  PreloadCheck class for extension pre-install checks  (Closed) 
  | 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/strings/string16.h" | |
| 15 #include "extensions/common/constants.h" | |
| 
Devlin
2017/03/08 03:01:47
needed?
 
michaelpg
2017/03/09 01:53:30
Removed.
 | |
| 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 typedef std::unordered_set<Error, std::hash<int>> Errors; | |
| 
Devlin
2017/03/08 03:01:46
prefer using x = foo syntax in new code.
 
michaelpg
2017/03/09 01:53:30
TIL, done
 | |
| 37 | |
| 38 typedef base::OnceCallback<void(Errors)> ResultCallback; | |
| 39 | |
| 40 explicit PreloadCheck(const Extension* extension) : extension_(extension) {} | |
| 41 virtual ~PreloadCheck() {} | |
| 42 | |
| 43 // This function must be called on the UI thread. The callback also occurs on | |
| 44 // the UI thread. | |
| 45 virtual void Start(ResultCallback callback) = 0; | |
| 46 | |
| 47 // Subclasses that provide an error message should return |true|. | |
| 48 virtual bool GetErrorMessage(base::string16* error) const; | |
| 49 | |
| 50 const Extension* extension() { return extension_; } | |
| 51 | |
| 52 private: | |
| 53 // The extension to check. | |
| 54 const Extension* extension_; | |
| 
Devlin
2017/03/08 03:01:48
We should refcount this.
 
michaelpg
2017/03/09 01:53:30
Done.
 | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(PreloadCheck); | |
| 57 }; | |
| 58 | |
| 59 } // namespace extensions | |
| 60 | |
| 61 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_H_ | |
| OLD | NEW |