blob: e75cbd1824d569b259a1adb45c1eff6df6268d23 [file] [log] [blame]
[email protected]a12ce8b22012-01-17 18:40:531// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8e4560b62011-01-14 10:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5df038b2012-07-16 19:03:275#ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
[email protected]8e4560b62011-01-14 10:09:147
[email protected]c51225632011-11-11 21:40:378#include <string>
9
[email protected]5df038b2012-07-16 19:03:2710#include "chrome/browser/extensions/external_provider_interface.h"
[email protected]8e4560b62011-01-14 10:09:1411
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]5df038b2012-07-16 19:03:2713#include "chrome/browser/extensions/external_loader.h"
[email protected]8e4560b62011-01-14 10:09:1414
[email protected]8e4560b62011-01-14 10:09:1415class Profile;
[email protected]8e4560b62011-01-14 10:09:1416class Version;
17
[email protected]f3a1c642011-07-12 19:15:0318namespace base {
19class DictionaryValue;
[email protected]f3a1c642011-07-12 19:15:0320}
21
[email protected]1c321ee2012-05-21 03:02:3422namespace extensions {
23class Extension;
[email protected]5df038b2012-07-16 19:03:2724class ExternalLoader;
[email protected]1c321ee2012-05-21 03:02:3425
[email protected]5df038b2012-07-16 19:03:2726// 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.
30class ExternalProviderImpl : public ExternalProviderInterface {
[email protected]8e4560b62011-01-14 10:09:1431 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]5df038b2012-07-16 19:03:2739 ExternalProviderImpl(VisitorInterface* service,
40 ExternalLoader* loader,
41 Extension::Location crx_location,
42 Extension::Location download_location,
43 int creation_flags);
[email protected]8e4560b62011-01-14 10:09:1444
[email protected]5df038b2012-07-16 19:03:2745 virtual ~ExternalProviderImpl();
[email protected]8e4560b62011-01-14 10:09:1446
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]5df038b2012-07-16 19:03:2754 // owned ExternalLoader instance.
[email protected]937cf9d2012-08-30 03:51:5555 virtual void SetPrefs(base::DictionaryValue* prefs);
[email protected]8e4560b62011-01-14 10:09:1456
[email protected]5df038b2012-07-16 19:03:2757 // ExternalProvider implementation:
[email protected]51a7a9d2011-09-27 17:21:4158 virtual void ServiceShutdown() OVERRIDE;
[email protected]d190cef2011-11-09 02:09:2459 virtual void VisitRegisteredExtension() OVERRIDE;
[email protected]51a7a9d2011-09-27 17:21:4160 virtual bool HasExtension(const std::string& id) const OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:1461 virtual bool GetExtensionDetails(const std::string& id,
[email protected]5df038b2012-07-16 19:03:2762 Extension::Location* location,
[email protected]51a7a9d2011-09-27 17:21:4163 scoped_ptr<Version>* version) const OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:1464
[email protected]1cc91fe2011-11-21 14:48:4365 virtual bool IsReady() const OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:1466
[email protected]8e4560b62011-01-14 10:09:1467 static const char kExternalCrx[];
68 static const char kExternalVersion[];
69 static const char kExternalUpdateUrl[];
[email protected]9d32ded072011-10-11 16:31:0570 static const char kSupportedLocales[];
[email protected]f121003b2012-05-04 21:57:4771 static const char kIsBookmarkApp[];
[email protected]7425d7df2012-11-28 14:35:4272 static const char kIsFromWebstore[];
[email protected]8e4560b62011-01-14 10:09:1473
[email protected]47fc70c2011-12-06 07:29:5174 void set_auto_acknowledge(bool auto_acknowledge) {
75 auto_acknowledge_ = auto_acknowledge;
76 }
77
[email protected]8e4560b62011-01-14 10:09:1478 private:
79 // Location for external extensions that are provided by this provider from
80 // local crx files.
[email protected]5df038b2012-07-16 19:03:2781 const Extension::Location crx_location_;
[email protected]8e4560b62011-01-14 10:09:1482
83 // Location for external extensions that are provided by this provider from
84 // update URLs.
[email protected]5df038b2012-07-16 19:03:2785 const Extension::Location download_location_;
[email protected]8e4560b62011-01-14 10:09:1486
[email protected]8e4560b62011-01-14 10:09:1487 // 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]f3a1c642011-07-12 19:15:0392 scoped_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:1493
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]5df038b2012-07-16 19:03:27100 scoped_refptr<ExternalLoader> loader_;
[email protected]8e4560b62011-01-14 10:09:14101
[email protected]1bf73cc2011-10-26 22:38:31102 // 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]47fc70c2011-12-06 07:29:51106 // 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]5df038b2012-07-16 19:03:27110 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl);
[email protected]8e4560b62011-01-14 10:09:14111};
112
[email protected]5df038b2012-07-16 19:03:27113} // namespace extensions
114
115#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_