blob: 343c82e0b93a876d05bc88046e735526aefccbfc [file] [log] [blame]
[email protected]8e4560b62011-01-14 10:09:141// 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]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]8e4560b62011-01-14 10:09:1412#include "chrome/browser/extensions/external_extension_loader.h"
13
[email protected]8e4560b62011-01-14 10:09:1414class ExternalExtensionLoader;
15class Profile;
[email protected]8e4560b62011-01-14 10:09:1416class Version;
17
[email protected]f3a1c642011-07-12 19:15:0318namespace base {
19class DictionaryValue;
20class ValueSerializer;
21}
22
[email protected]8e4560b62011-01-14 10:09:1423// 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.
27class 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]1bf73cc2011-10-26 22:38:3141 Extension::Location download_location,
42 int creation_flags);
[email protected]8e4560b62011-01-14 10:09:1443
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]f3a1c642011-07-12 19:15:0354 void SetPrefs(base::DictionaryValue* prefs);
[email protected]8e4560b62011-01-14 10:09:1455
56 // ExternalExtensionProvider implementation:
[email protected]51a7a9d2011-09-27 17:21:4157 virtual void ServiceShutdown() OVERRIDE;
58 virtual void VisitRegisteredExtension() const OVERRIDE;
59 virtual bool HasExtension(const std::string& id) const OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:1460 virtual bool GetExtensionDetails(const std::string& id,
61 Extension::Location* location,
[email protected]51a7a9d2011-09-27 17:21:4162 scoped_ptr<Version>* version) const OVERRIDE;
[email protected]8e4560b62011-01-14 10:09:1463
[email protected]50067e52011-10-20 23:17:0764 virtual bool IsReady() const;
[email protected]8e4560b62011-01-14 10:09:1465
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]9d32ded072011-10-11 16:31:0571 static const char kSupportedLocales[];
[email protected]8e4560b62011-01-14 10:09:1472
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]8e4560b62011-01-14 10:09:1482 // 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]f3a1c642011-07-12 19:15:0387 scoped_ptr<base::DictionaryValue> prefs_;
[email protected]8e4560b62011-01-14 10:09:1488
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]1bf73cc2011-10-26 22:38:3197 // 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]8e4560b62011-01-14 10:09:14101 DISALLOW_COPY_AND_ASSIGN(ExternalExtensionProviderImpl);
102};
103
104#endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_EXTENSION_PROVIDER_IMPL_H_