external_provider_impl.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 15class Profile; 16 17namespace base { 18class DictionaryValue; 19class Version; 20} 21 22namespace 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. 28class 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 76 void set_auto_acknowledge(bool auto_acknowledge) { 77 auto_acknowledge_ = auto_acknowledge; 78 } 79 80 private: 81 // Location for external extensions that are provided by this provider from 82 // local crx files. 83 const Manifest::Location crx_location_; 84 85 // Location for external extensions that are provided by this provider from 86 // update URLs. 87 const Manifest::Location download_location_; 88 89 // Weak pointer to the object that consumes the external extensions. 90 // This is zeroed out by: ServiceShutdown() 91 VisitorInterface* service_; // weak 92 93 // Dictionary of the external extensions that are provided by this provider. 94 scoped_ptr<base::DictionaryValue> prefs_; 95 96 // Indicates that the extensions provided by this provider are loaded 97 // entirely. 98 bool ready_; 99 100 // The loader that loads the list of external extensions and reports them 101 // via |SetPrefs|. 102 scoped_refptr<ExternalLoader> loader_; 103 104 // The profile that will be used to install external extensions. 105 Profile* profile_; 106 107 // Creation flags to use for the extension. These flags will be used 108 // when calling Extension::Create() by the crx installer. 109 int creation_flags_; 110 111 // Whether loaded extensions should be automatically acknowledged, so that 112 // the user doesn't see an alert about them. 113 bool auto_acknowledge_; 114 115 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl); 116}; 117 118} // namespace extensions 119 120#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ 121