blob: 6812f4ed1f469b41ad6f45d09dc987783908a461 [file] [log] [blame]
[email protected]9060d8b02012-01-13 02:14:301// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b2907fd2011-03-25 16:43:372// 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_PENDING_EXTENSION_MANAGER_H_
6#define CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_
7#pragma once
8
[email protected]51a3bf8b2012-06-08 22:53:069#include <list>
[email protected]b2907fd2011-03-25 16:43:3710#include <string>
[email protected]51a3bf8b2012-06-08 22:53:0611#include <utility>
[email protected]b2907fd2011-03-25 16:43:3712
13#include "chrome/browser/extensions/pending_extension_info.h"
14#include "chrome/common/extensions/extension.h"
15
[email protected]2859946f2011-04-04 18:18:0616class ExtensionServiceInterface;
[email protected]b2907fd2011-03-25 16:43:3717class GURL;
[email protected]42a08162012-03-16 18:09:1118class PendingExtensionManager;
[email protected]e3987852012-05-04 10:06:3019class Version;
[email protected]42a08162012-03-16 18:09:1120
21namespace extensions {
22class ExtensionUpdaterTest;
23void SetupPendingExtensionManagerForTest(
24 int count, const GURL& update_url,
25 PendingExtensionManager* pending_extension_manager);
26}
[email protected]b2907fd2011-03-25 16:43:3727
28// Class PendingExtensionManager manages the set of extensions which are
[email protected]75764512011-12-19 19:54:2829// being installed or updated. In general, installation and updates take
[email protected]b2907fd2011-03-25 16:43:3730// time, because they involve downloading, unpacking, and installing.
31// This class allows us to avoid race cases where multiple sources install
32// the same extension.
33// The extensions service creates an instance of this class, and manages
34// its lifetime. This class should only be used from the UI thread.
35class PendingExtensionManager {
36 public:
[email protected]b2907fd2011-03-25 16:43:3737 // |service| is a reference to the ExtensionService whose pending
38 // extensions we are managing. The service creates an instance of
39 // this class on construction, and destroys it on destruction.
40 // The service remains valid over the entire lifetime of this class.
[email protected]2859946f2011-04-04 18:18:0641 explicit PendingExtensionManager(const ExtensionServiceInterface& service);
[email protected]b2907fd2011-03-25 16:43:3742 ~PendingExtensionManager();
43
44 // TODO(skerner): Many of these methods can be private once code in
45 // ExtensionService is moved into methods of this class.
46
[email protected]51a3bf8b2012-06-08 22:53:0647 // Remove extension with id |id| from the set of pending extensions. Returns
48 // true if such an extension was found and removed, false otherwise.
49 bool Remove(const std::string& id);
[email protected]b2907fd2011-03-25 16:43:3750
[email protected]51a3bf8b2012-06-08 22:53:0651 // Get the information for a pending extension. Returns a pointer to the
52 // pending extension with id |id|, or NULL if there is no such extension.
53 const PendingExtensionInfo* GetById(const std::string& id) const;
[email protected]b2907fd2011-03-25 16:43:3754
55 // Is |id| in the set of pending extensions?
56 bool IsIdPending(const std::string& id) const;
57
[email protected]b2907fd2011-03-25 16:43:3758 // Adds an extension in a pending state; the extension with the
59 // given info will be installed on the next auto-update cycle.
[email protected]145a317b2011-04-12 16:03:4660 // Return true if the extension was added. Will return false
61 // if the extension is pending from another source which overrides
62 // sync installs (such as a policy extension) or if the extension
63 // is already installed.
[email protected]b2907fd2011-03-25 16:43:3764 //
65 // TODO(akalin): Replace |install_silently| with a list of
66 // pre-enabled permissions.
[email protected]145a317b2011-04-12 16:03:4667 bool AddFromSync(
[email protected]b2907fd2011-03-25 16:43:3768 const std::string& id,
69 const GURL& update_url,
70 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
[email protected]6cc7dbae2011-04-29 21:18:3371 bool install_silently);
[email protected]b2907fd2011-03-25 16:43:3772
73 // Given an extension id and an update URL, schedule the extension
74 // to be fetched, installed, and activated.
[email protected]9060d8b02012-01-13 02:14:3075 bool AddFromExternalUpdateUrl(const std::string& id,
[email protected]b2907fd2011-03-25 16:43:3776 const GURL& update_url,
[email protected]1c321ee52012-05-21 03:02:3477 extensions::Extension::Location location);
[email protected]b2907fd2011-03-25 16:43:3778
[email protected]b2907fd2011-03-25 16:43:3779 // Add a pending extension record for an external CRX file.
[email protected]9060d8b02012-01-13 02:14:3080 // Return true if the CRX should be installed, false if an existing
81 // pending record overrides it.
82 bool AddFromExternalFile(
[email protected]b2907fd2011-03-25 16:43:3783 const std::string& id,
[email protected]1c321ee52012-05-21 03:02:3484 extensions::Extension::Location location,
[email protected]e3987852012-05-04 10:06:3085 const Version& version);
[email protected]b2907fd2011-03-25 16:43:3786
[email protected]51a3bf8b2012-06-08 22:53:0687 // Get the list of pending IDs that should be installed from an update URL.
[email protected]9060d8b02012-01-13 02:14:3088 // Pending extensions that will be installed from local files will not be
89 // included in the set.
90 void GetPendingIdsForUpdateCheck(
[email protected]51a3bf8b2012-06-08 22:53:0691 std::list<std::string>* out_ids_for_update_check) const;
[email protected]9060d8b02012-01-13 02:14:3092
[email protected]b2907fd2011-03-25 16:43:3793 private:
[email protected]51a3bf8b2012-06-08 22:53:0694 typedef std::list<PendingExtensionInfo> PendingExtensionList;
[email protected]9060d8b02012-01-13 02:14:3095
[email protected]b2907fd2011-03-25 16:43:3796 // Assumes an extension with id |id| is not already installed.
[email protected]145a317b2011-04-12 16:03:4697 // Return true if the extension was added.
98 bool AddExtensionImpl(
[email protected]b2907fd2011-03-25 16:43:3799 const std::string& id,
100 const GURL& update_url,
[email protected]e3987852012-05-04 10:06:30101 const Version& version,
[email protected]b2907fd2011-03-25 16:43:37102 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
103 bool is_from_sync,
104 bool install_silently,
[email protected]1c321ee52012-05-21 03:02:34105 extensions::Extension::Location install_source);
[email protected]b2907fd2011-03-25 16:43:37106
107 // Add a pending extension record directly. Used for unit tests that need
108 // to set an inital state. Use friendship to allow the tests to call this
109 // method.
[email protected]51a3bf8b2012-06-08 22:53:06110 void AddForTesting(const PendingExtensionInfo& pending_extension_info);
[email protected]b2907fd2011-03-25 16:43:37111
112 // Reference to the extension service whose pending extensions this class is
113 // managing. Because this class is a member of |service_|, it is created
114 // and destroyed with |service_|. We only use methods from the interface
[email protected]2859946f2011-04-04 18:18:06115 // ExtensionServiceInterface.
116 const ExtensionServiceInterface& service_;
[email protected]b2907fd2011-03-25 16:43:37117
[email protected]51a3bf8b2012-06-08 22:53:06118 PendingExtensionList pending_extension_list_;
[email protected]b2907fd2011-03-25 16:43:37119
120 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
121 UpdatePendingExtensionAlreadyInstalled);
[email protected]42a08162012-03-16 18:09:11122 friend class extensions::ExtensionUpdaterTest;
123 friend void extensions::SetupPendingExtensionManagerForTest(
[email protected]b2907fd2011-03-25 16:43:37124 int count, const GURL& update_url,
125 PendingExtensionManager* pending_extension_manager);
126
127 DISALLOW_COPY_AND_ASSIGN(PendingExtensionManager);
128};
129
130#endif // CHROME_BROWSER_EXTENSIONS_PENDING_EXTENSION_MANAGER_H_