Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / external_provider_impl.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/external_loader.h"
12 #include "extensions/browser/external_provider_interface.h"
13 #include "extensions/common/manifest.h"
14
15 class Profile;
16
17 namespace base {
18 class DictionaryValue;
19 class Version;
20 }
21
22 namespace extensions {
23
24 // A specialization of the ExternalProvider that uses an instance of
25 // ExternalLoader to provide external extensions. This class can be seen as a
26 // bridge between the extension system and an ExternalLoader. Instances live
27 // their entire life on the UI thread.
28 class ExternalProviderImpl : public ExternalProviderInterface {
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 Manifest::INVALID_LOCATION.
37   ExternalProviderImpl(VisitorInterface* service,
38                        const scoped_refptr<ExternalLoader>& loader,
39                        Profile* profile,
40                        Manifest::Location crx_location,
41                        Manifest::Location download_location,
42                        int creation_flags);
43
44   virtual ~ExternalProviderImpl();
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 ExternalLoader instance.
54   virtual void SetPrefs(base::DictionaryValue* prefs);
55
56   // ExternalProvider implementation:
57   virtual void ServiceShutdown() OVERRIDE;
58   virtual void VisitRegisteredExtension() OVERRIDE;
59   virtual bool HasExtension(const std::string& id) const OVERRIDE;
60   virtual bool GetExtensionDetails(
61       const std::string& id,
62       Manifest::Location* location,
63       scoped_ptr<base::Version>* version) const OVERRIDE;
64
65   virtual bool IsReady() const OVERRIDE;
66
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
77   void set_auto_acknowledge(bool auto_acknowledge) {
78     auto_acknowledge_ = auto_acknowledge;
79   }
80
81  private:
82   // Location for external extensions that are provided by this provider from
83   // local crx files.
84   const Manifest::Location crx_location_;
85
86   // Location for external extensions that are provided by this provider from
87   // update URLs.
88   const Manifest::Location download_location_;
89
90   // Weak pointer to the object that consumes the external extensions.
91   // This is zeroed out by: ServiceShutdown()
92   VisitorInterface* service_;  // weak
93
94   // Dictionary of the external extensions that are provided by this provider.
95   scoped_ptr<base::DictionaryValue> prefs_;
96
97   // Indicates that the extensions provided by this provider are loaded
98   // entirely.
99   bool ready_;
100
101   // The loader that loads the list of external extensions and reports them
102   // via |SetPrefs|.
103   scoped_refptr<ExternalLoader> loader_;
104
105   // The profile that will be used to install external extensions.
106   Profile* profile_;
107
108   // Creation flags to use for the extension.  These flags will be used
109   // when calling Extension::Create() by the crx installer.
110   int creation_flags_;
111
112   // Whether loaded extensions should be automatically acknowledged, so that
113   // the user doesn't see an alert about them.
114   bool auto_acknowledge_;
115
116   DISALLOW_COPY_AND_ASSIGN(ExternalProviderImpl);
117 };
118
119 }  // namespace extensions
120
121 #endif  // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_