[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1 | // Copyright (c) 2011 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_EXTENSION_PROVIDER_IMPL_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_IMPL_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "chrome/browser/extensions/external_extension_provider_interface.h" |
| 10 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 12 | #include "chrome/browser/extensions/external_extension_loader.h" |
| 13 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 14 | class ExternalExtensionLoader; |
| 15 | class Profile; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 16 | class Version; |
| 17 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 18 | namespace base { |
| 19 | class DictionaryValue; |
| 20 | class ValueSerializer; |
| 21 | } |
| 22 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 23 | // A specialization of the ExternalExtensionProvider that uses an instance |
| 24 | // of ExternalExtensionLoader to provide external extensions. This class |
| 25 | // can be seen as a bridge between the extension system and an |
| 26 | // ExternalExtensionLoader. Instances live their entire life on the UI thread. |
| 27 | class ExternalExtensionProviderImpl |
| 28 | : public ExternalExtensionProviderInterface { |
| 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 Extensions::INVALID. |
| 37 | ExternalExtensionProviderImpl( |
| 38 | VisitorInterface* service, |
| 39 | ExternalExtensionLoader* loader, |
| 40 | Extension::Location crx_location, |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame^] | 41 | Extension::Location download_location, |
| 42 | int creation_flags); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 43 | |
| 44 | virtual ~ExternalExtensionProviderImpl(); |
| 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 ExternalExtensionLoader instance. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 54 | void SetPrefs(base::DictionaryValue* prefs); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 55 | |
| 56 | // ExternalExtensionProvider implementation: |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 57 | virtual void ServiceShutdown() OVERRIDE; |
| 58 | virtual void VisitRegisteredExtension() const OVERRIDE; |
| 59 | virtual bool HasExtension(const std::string& id) const OVERRIDE; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 60 | virtual bool GetExtensionDetails(const std::string& id, |
| 61 | Extension::Location* location, |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 62 | scoped_ptr<Version>* version) const OVERRIDE; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 63 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 64 | virtual bool IsReady() const; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 65 | |
| 66 | static const char kLocation[]; |
| 67 | static const char kState[]; |
| 68 | static const char kExternalCrx[]; |
| 69 | static const char kExternalVersion[]; |
| 70 | static const char kExternalUpdateUrl[]; |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 71 | static const char kSupportedLocales[]; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | // Location for external extensions that are provided by this provider from |
| 75 | // local crx files. |
| 76 | const Extension::Location crx_location_; |
| 77 | |
| 78 | // Location for external extensions that are provided by this provider from |
| 79 | // update URLs. |
| 80 | const Extension::Location download_location_; |
| 81 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 82 | // Weak pointer to the object that consumes the external extensions. |
| 83 | // This is zeroed out by: ServiceShutdown() |
| 84 | VisitorInterface* service_; // weak |
| 85 | |
| 86 | // Dictionary of the external extensions that are provided by this provider. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 87 | scoped_ptr<base::DictionaryValue> prefs_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 88 | |
| 89 | // Indicates that the extensions provided by this provider are loaded |
| 90 | // entirely. |
| 91 | bool ready_; |
| 92 | |
| 93 | // The loader that loads the list of external extensions and reports them |
| 94 | // via |SetPrefs|. |
| 95 | scoped_refptr<ExternalExtensionLoader> loader_; |
| 96 | |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame^] | 97 | // Creation flags to use for the extension. These flags will be used |
| 98 | // when calling Extenion::Create() by the crx installer. |
| 99 | int creation_flags_; |
| 100 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(ExternalExtensionProviderImpl); |
| 102 | }; |
| 103 | |
| 104 | #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_IMPL_H_ |