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