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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/extensions/external_loader.h"
13 #include "extensions/browser/external_provider_interface.h"
14 #include "extensions/common/manifest.h"
19 class DictionaryValue
;
23 namespace extensions
{
25 // A specialization of the ExternalProvider that uses an instance of
26 // ExternalLoader to provide external extensions. This class can be seen as a
27 // bridge between the extension system and an ExternalLoader. Instances live
28 // their entire life on the UI thread.
29 class ExternalProviderImpl
: public ExternalProviderInterface
{
31 // The constructed provider will provide the extensions loaded from |loader|
32 // to |service|, that will deal with the installation. The location
33 // attributes of the provided extensions are also specified here:
34 // |crx_location|: extensions originating from crx files
35 // |download_location|: extensions originating from update URLs
36 // If either of the origins is not supported by this provider, then it should
37 // be initialized as Manifest::INVALID_LOCATION.
38 ExternalProviderImpl(VisitorInterface
* service
,
39 const scoped_refptr
<ExternalLoader
>& loader
,
41 Manifest::Location crx_location
,
42 Manifest::Location download_location
,
45 ~ExternalProviderImpl() override
;
47 // Populates a list with providers for all known sources.
48 static void CreateExternalProviders(
49 VisitorInterface
* service
,
51 ProviderCollection
* provider_list
);
53 // Sets underlying prefs and notifies provider. Only to be called by the
54 // owned ExternalLoader instance.
55 virtual void SetPrefs(base::DictionaryValue
* prefs
);
57 // ExternalProvider implementation:
58 void ServiceShutdown() override
;
59 void VisitRegisteredExtension() override
;
60 bool HasExtension(const std::string
& id
) const override
;
61 bool GetExtensionDetails(const std::string
& id
,
62 Manifest::Location
* location
,
63 scoped_ptr
<base::Version
>* version
) const override
;
65 bool IsReady() const override
;
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 static const char kMinProfileCreatedByVersion
[];
78 static const char kDoNotInstallForEnterprise
[];
80 void set_auto_acknowledge(bool auto_acknowledge
) {
81 auto_acknowledge_
= auto_acknowledge
;
84 void set_install_immediately(bool install_immediately
) {
85 install_immediately_
= install_immediately
;
89 bool HandleMinProfileVersion(const base::DictionaryValue
* extension
,
90 const std::string
& extension_id
,
91 std::set
<std::string
>* unsupported_extensions
);
93 bool HandleDoNotInstallForEnterprise(
94 const base::DictionaryValue
* extension
,
95 const std::string
& extension_id
,
96 std::set
<std::string
>* unsupported_extensions
);
98 // Location for external extensions that are provided by this provider from
100 const Manifest::Location crx_location_
;
102 // Location for external extensions that are provided by this provider from
104 const Manifest::Location download_location_
;
106 // Weak pointer to the object that consumes the external extensions.
107 // This is zeroed out by: ServiceShutdown()
108 VisitorInterface
* service_
; // weak
110 // Dictionary of the external extensions that are provided by this provider.
111 scoped_ptr
<base::DictionaryValue
> prefs_
;
113 // Indicates that the extensions provided by this provider are loaded
117 // The loader that loads the list of external extensions and reports them
119 scoped_refptr
<ExternalLoader
> loader_
;
121 // The profile that will be used to install external extensions.
124 // Creation flags to use for the extension. These flags will be used
125 // when calling Extension::Create() by the crx installer.
128 // Whether loaded extensions should be automatically acknowledged, so that
129 // the user doesn't see an alert about them.
130 bool auto_acknowledge_
;
132 // Whether the extensions from this provider should be installed immediately.
133 bool install_immediately_
;
135 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl
);
138 } // namespace extensions
140 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_