Home | History | Annotate | Download | only in extensions
      1 // Copyright 2013 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_EXTENSION_INSTALLER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALLER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/memory/weak_ptr.h"
     12 #include "base/strings/string16.h"
     13 #include "chrome/browser/extensions/extension_service.h"
     14 #include "chrome/browser/extensions/requirements_checker.h"
     15 #include "extensions/common/extension.h"
     16 
     17 class Profile;
     18 
     19 namespace content {
     20 class WebContents;
     21 }
     22 
     23 namespace extensions {
     24 
     25 
     26 // Holds common methods and data of extension installers.
     27 class ExtensionInstaller {
     28  public:
     29   typedef base::Callback<void(std::vector<std::string>)> RequirementsCallback;
     30 
     31   explicit ExtensionInstaller(Profile* profile);
     32   ~ExtensionInstaller();
     33 
     34   // Called on the UI thread to start the requirements check on the extension
     35   void CheckRequirements(const RequirementsCallback& callback);
     36 
     37   // Checks the management policy if the extension can be installed.
     38   base::string16 CheckManagementPolicy();
     39 
     40   Profile* profile() const {
     41     return profile_;
     42   }
     43 
     44   void set_extension(const Extension* extension) {
     45     extension_ = extension;
     46   }
     47 
     48   scoped_refptr<const Extension> extension() {
     49     return extension_;
     50   }
     51 
     52  private:
     53   scoped_ptr<RequirementsChecker> requirements_checker_;
     54 
     55   // The Profile where the extension is being installed in.
     56   Profile* profile_;
     57 
     58   // The extension we're installing. We either pass it off to ExtensionService
     59   // on success, or drop the reference on failure.
     60   scoped_refptr<const Extension> extension_;
     61 
     62   base::WeakPtrFactory<ExtensionInstaller> weak_ptr_factory_;
     63 
     64   DISALLOW_COPY_AND_ASSIGN(ExtensionInstaller);
     65 };
     66 
     67 }  // namespace extensions
     68 
     69 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALLER_H_
     70