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_EXTERNAL_PROVIDER_IMPL_H_
      6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "chrome/browser/extensions/external_loader.h"
     12 #include "extensions/browser/external_provider_interface.h"
     13 #include "extensions/common/manifest.h"
     14 
     15 class Profile;
     16 
     17 namespace base {
     18 class DictionaryValue;
     19 class Version;
     20 }
     21 
     22 namespace extensions {
     23 
     24 // A specialization of the ExternalProvider that uses an instance of
     25 // ExternalLoader to provide external extensions. This class can be seen as a
     26 // bridge between the extension system and an ExternalLoader. Instances live
     27 // their entire life on the UI thread.
     28 class ExternalProviderImpl : public ExternalProviderInterface {
     29  public:
     30   // The constructed provider will provide the extensions loaded from |loader|
     31   // to |service|, that will deal with the installation. The location
     32   // attributes of the provided extensions are also specified here:
     33   // |crx_location|: extensions originating from crx files
     34   // |download_location|: extensions originating from update URLs
     35   // If either of the origins is not supported by this provider, then it should
     36   // be initialized as Manifest::INVALID_LOCATION.
     37   ExternalProviderImpl(VisitorInterface* service,
     38                        const scoped_refptr<ExternalLoader>& loader,
     39                        Profile* profile,
     40                        Manifest::Location crx_location,
     41                        Manifest::Location download_location,
     42                        int creation_flags);
     43 
     44   virtual ~ExternalProviderImpl();
     45 
     46   // Populates a list with providers for all known sources.
     47   static void CreateExternalProviders(
     48       VisitorInterface* service,
     49       Profile* profile,
     50       ProviderCollection* provider_list);
     51 
     52   // Sets underlying prefs and notifies provider. Only to be called by the
     53   // owned ExternalLoader instance.
     54   virtual void SetPrefs(base::DictionaryValue* prefs);
     55 
     56   // ExternalProvider implementation:
     57   virtual void ServiceShutdown() OVERRIDE;
     58   virtual void VisitRegisteredExtension() OVERRIDE;
     59   virtual bool HasExtension(const std::string& id) const OVERRIDE;
     60   virtual bool GetExtensionDetails(
     61       const std::string& id,
     62       Manifest::Location* location,
     63       scoped_ptr<base::Version>* version) const OVERRIDE;
     64 
     65   virtual bool IsReady() const OVERRIDE;
     66 
     67   static const char kExternalCrx[];
     68   static const char kExternalVersion[];
     69   static const char kExternalUpdateUrl[];
     70   static const char kInstallParam[];
     71   static const char kIsBookmarkApp[];
     72   static const char kIsFromWebstore[];
     73   static const char kKeepIfPresent[];
     74   static const char kSupportedLocales[];
     75   static const char kWasInstalledByOem[];
     76   static const char kMayBeUntrusted[];
     77 
     78   void set_auto_acknowledge(bool auto_acknowledge) {
     79     auto_acknowledge_ = auto_acknowledge;
     80   }
     81 
     82  private:
     83   // Location for external extensions that are provided by this provider from
     84   // local crx files.
     85   const Manifest::Location crx_location_;
     86 
     87   // Location for external extensions that are provided by this provider from
     88   // update URLs.
     89   const Manifest::Location download_location_;
     90 
     91   // Weak pointer to the object that consumes the external extensions.
     92   // This is zeroed out by: ServiceShutdown()
     93   VisitorInterface* service_;  // weak
     94 
     95   // Dictionary of the external extensions that are provided by this provider.
     96   scoped_ptr<base::DictionaryValue> prefs_;
     97 
     98   // Indicates that the extensions provided by this provider are loaded
     99   // entirely.
    100   bool ready_;
    101 
    102   // The loader that loads the list of external extensions and reports them
    103   // via |SetPrefs|.
    104   scoped_refptr<ExternalLoader> loader_;
    105 
    106   // The profile that will be used to install external extensions.
    107   Profile* profile_;
    108 
    109   // Creation flags to use for the extension.  These flags will be used
    110   // when calling Extension::Create() by the crx installer.
    111   int creation_flags_;
    112 
    113   // Whether loaded extensions should be automatically acknowledged, so that
    114   // the user doesn't see an alert about them.
    115   bool auto_acknowledge_;
    116 
    117   DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl);
    118 };
    119 
    120 }  // namespace extensions
    121 
    122 #endif  // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
    123