Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/callback.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "chrome/browser/extensions/extension_service.h"
     14 
     15 class GPUFeatureChecker;
     16 
     17 namespace extensions {
     18 class Extension;
     19 
     20 // Validates the 'requirements' extension manifest field. This is an
     21 // asynchronous process that involves several threads, but the public interface
     22 // of this class (including constructor and destructor) must only be used on
     23 // the UI thread.
     24 class RequirementsChecker : public base::SupportsWeakPtr<RequirementsChecker> {
     25  public:
     26   RequirementsChecker();
     27   ~RequirementsChecker();
     28 
     29   // The vector passed to the callback are any localized errors describing
     30   // requirement violations. If this vector is non-empty, requirements checking
     31   // failed. This should only be called once. |callback| will always be invoked
     32   // asynchronously on the UI thread. |callback| will only be called once, and
     33   // will be reset after called.
     34   void Check(scoped_refptr<const Extension> extension,
     35       base::Callback<void(std::vector<std::string> requirement)> callback);
     36 
     37  private:
     38   // Callbacks for the GPUFeatureChecker.
     39   void SetWebGLAvailability(bool available);
     40 
     41   void MaybeRunCallback();
     42 
     43   std::vector<std::string> errors_;
     44 
     45   // Every requirement that needs to be resolved asynchronously will add to
     46   // this counter. When the counter is depleted, the callback will be run.
     47   int pending_requirement_checks_;
     48 
     49   scoped_refptr<GPUFeatureChecker> webgl_checker_;
     50 
     51   base::Callback<void(std::vector<std::string> requirement_errorss)> callback_;
     52 };
     53 
     54 }  // namespace extensions
     55 
     56 #endif  // CHROME_BROWSER_EXTENSIONS_REQUIREMENTS_CHECKER_H_
     57