[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 5 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6 | |
[email protected] | d31e19e | 2012-08-22 00:19:04 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 9 | #include "base/logging.h" |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 10 | #include "base/metrics/histogram.h" |
| 11 | #include "base/stl_util.h" |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 12 | #include "base/version.h" |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 13 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 15 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 16 | #include "extensions/browser/extension_registry.h" |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 17 | #include "extensions/common/constants.h" |
[email protected] | b52f8ca | 2013-11-28 08:25:22 | [diff] [blame] | 18 | #include "extensions/common/extension.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 19 | #include "url/gurl.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 20 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 21 | using content::BrowserThread; |
| 22 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 23 | namespace { |
| 24 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 25 | // Install predicate used by AddFromExternalUpdateUrl(). |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 26 | bool AlwaysInstall(const extensions::Extension* extension) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 27 | return true; |
| 28 | } |
| 29 | |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 30 | std::string GetVersionString(const base::Version& version) { |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 31 | return version.IsValid() ? version.GetString() : "invalid"; |
| 32 | } |
| 33 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 34 | } // namespace |
| 35 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 36 | namespace extensions { |
| 37 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 38 | PendingExtensionManager::PendingExtensionManager( |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 39 | content::BrowserContext* context) |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 40 | : context_(context) {} |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 41 | |
| 42 | PendingExtensionManager::~PendingExtensionManager() {} |
| 43 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 44 | const PendingExtensionInfo* PendingExtensionManager::GetById( |
| 45 | const std::string& id) const { |
| 46 | PendingExtensionList::const_iterator iter; |
| 47 | for (iter = pending_extension_list_.begin(); |
| 48 | iter != pending_extension_list_.end(); |
| 49 | ++iter) { |
| 50 | if (id == iter->id()) |
| 51 | return &(*iter); |
| 52 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 53 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 54 | return NULL; |
| 55 | } |
| 56 | |
| 57 | bool PendingExtensionManager::Remove(const std::string& id) { |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 58 | if (base::ContainsKey(expected_policy_reinstalls_, id)) { |
| 59 | base::TimeDelta latency = |
| 60 | base::TimeTicks::Now() - expected_policy_reinstalls_[id]; |
| 61 | UMA_HISTOGRAM_LONG_TIMES("Extensions.CorruptPolicyExtensionResolved", |
| 62 | latency); |
| 63 | expected_policy_reinstalls_.erase(id); |
| 64 | } |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 65 | PendingExtensionList::iterator iter; |
| 66 | for (iter = pending_extension_list_.begin(); |
| 67 | iter != pending_extension_list_.end(); |
| 68 | ++iter) { |
| 69 | if (id == iter->id()) { |
| 70 | pending_extension_list_.erase(iter); |
| 71 | return true; |
| 72 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | return false; |
| 76 | } |
| 77 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 78 | bool PendingExtensionManager::IsIdPending(const std::string& id) const { |
[email protected] | 870f557 | 2013-12-19 12:30:15 | [diff] [blame] | 79 | return GetById(id) != NULL; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | 9bd9a686 | 2012-11-29 09:24:22 | [diff] [blame] | 82 | bool PendingExtensionManager::HasPendingExtensions() const { |
| 83 | return !pending_extension_list_.empty(); |
| 84 | } |
| 85 | |
[email protected] | d31e19e | 2012-08-22 00:19:04 | [diff] [blame] | 86 | bool PendingExtensionManager::HasPendingExtensionFromSync() const { |
| 87 | PendingExtensionList::const_iterator iter; |
| 88 | for (iter = pending_extension_list_.begin(); |
| 89 | iter != pending_extension_list_.end(); |
| 90 | ++iter) { |
| 91 | if (iter->is_from_sync()) |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | return false; |
| 96 | } |
| 97 | |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 98 | void PendingExtensionManager::ExpectPolicyReinstallForCorruption( |
| 99 | const ExtensionId& id) { |
| 100 | expected_policy_reinstalls_[id] = base::TimeTicks::Now(); |
| 101 | UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptPolicyExtensionDetected", true); |
| 102 | } |
| 103 | |
| 104 | bool PendingExtensionManager::IsPolicyReinstallForCorruptionExpected( |
| 105 | const ExtensionId& id) const { |
| 106 | return base::ContainsKey(expected_policy_reinstalls_, id); |
| 107 | } |
| 108 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 109 | bool PendingExtensionManager::AddFromSync( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 110 | const std::string& id, |
| 111 | const GURL& update_url, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 112 | const base::Version& version, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 113 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 114 | bool remote_install) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 115 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 116 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 117 | if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 118 | id, ExtensionRegistry::EVERYTHING)) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 119 | LOG(ERROR) << "Trying to add pending extension " << id |
| 120 | << " which already exists"; |
| 121 | return false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 122 | } |
| 123 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 124 | // Make sure we don't ever try to install the CWS app, because even though |
| 125 | // it is listed as a syncable app (because its values need to be synced) it |
| 126 | // should already be installed on every instance. |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 127 | if (id == extensions::kWebStoreAppId) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 128 | NOTREACHED(); |
| 129 | return false; |
| 130 | } |
| 131 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 132 | static const bool kIsFromSync = true; |
| 133 | static const Manifest::Location kSyncLocation = Manifest::INTERNAL; |
| 134 | static const bool kMarkAcknowledged = false; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 135 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 136 | return AddExtensionImpl(id, |
| 137 | std::string(), |
| 138 | update_url, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 139 | version, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 140 | should_allow_install, |
| 141 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 142 | kSyncLocation, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 143 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 144 | kMarkAcknowledged, |
| 145 | remote_install); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 148 | bool PendingExtensionManager::AddFromExtensionImport( |
| 149 | const std::string& id, |
| 150 | const GURL& update_url, |
| 151 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { |
| 152 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 153 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 154 | if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 155 | id, ExtensionRegistry::EVERYTHING)) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 156 | LOG(ERROR) << "Trying to add pending extension " << id |
| 157 | << " which already exists"; |
| 158 | return false; |
| 159 | } |
| 160 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 161 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 162 | static const Manifest::Location kManifestLocation = Manifest::INTERNAL; |
| 163 | static const bool kMarkAcknowledged = false; |
| 164 | static const bool kRemoteInstall = false; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 165 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 166 | return AddExtensionImpl(id, |
| 167 | std::string(), |
| 168 | update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 169 | base::Version(), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 170 | should_allow_install, |
| 171 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 172 | kManifestLocation, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 173 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 174 | kMarkAcknowledged, |
| 175 | kRemoteInstall); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 176 | } |
| 177 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 178 | bool PendingExtensionManager::AddFromExternalUpdateUrl( |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 179 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 180 | const std::string& install_parameter, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 181 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 182 | Manifest::Location location, |
| 183 | int creation_flags, |
| 184 | bool mark_acknowledged) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 185 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 186 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 187 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 188 | static const bool kRemoteInstall = false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 189 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 190 | const Extension* extension = ExtensionRegistry::Get(context_) |
| 191 | ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 192 | if (extension && location == Manifest::GetHigherPriorityLocation( |
| 193 | location, extension->location())) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 194 | // If the new location has higher priority than the location of an existing |
| 195 | // extension, let the update process overwrite the existing extension. |
| 196 | } else { |
emaxx | 6699afb68 | 2016-10-10 21:22:13 | [diff] [blame^] | 197 | // Skip the installation if the extension was removed by the user and it's |
| 198 | // not specified to be force-installed through the policy. |
| 199 | if (!Manifest::IsPolicyLocation(location) && |
| 200 | ExtensionPrefs::Get(context_)->IsExternalExtensionUninstalled(id)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 201 | return false; |
emaxx | 6699afb68 | 2016-10-10 21:22:13 | [diff] [blame^] | 202 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 203 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 204 | if (extension) { |
| 205 | LOG(DFATAL) << "Trying to add extension " << id |
| 206 | << " by external update, but it is already installed."; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 207 | return false; |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 208 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 211 | return AddExtensionImpl(id, |
| 212 | install_parameter, |
| 213 | update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 214 | base::Version(), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 215 | &AlwaysInstall, |
| 216 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 217 | location, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 218 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 219 | mark_acknowledged, |
| 220 | kRemoteInstall); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 221 | } |
| 222 | |
thakis | 37be69c | 2015-08-19 03:26:57 | [diff] [blame] | 223 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 224 | bool PendingExtensionManager::AddFromExternalFile( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 225 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 226 | Manifest::Location install_source, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 227 | const base::Version& version, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 228 | int creation_flags, |
| 229 | bool mark_acknowledged) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 230 | // TODO(skerner): AddFromSync() checks to see if the extension is |
| 231 | // installed, but this method assumes that the caller already |
| 232 | // made sure it is not installed. Make all AddFrom*() methods |
| 233 | // consistent. |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 234 | const GURL& kUpdateUrl = GURL::EmptyGURL(); |
| 235 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 236 | static const bool kRemoteInstall = false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 237 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 238 | return AddExtensionImpl(id, |
| 239 | std::string(), |
| 240 | kUpdateUrl, |
| 241 | version, |
| 242 | &AlwaysInstall, |
| 243 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 244 | install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 245 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 246 | mark_acknowledged, |
| 247 | kRemoteInstall); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void PendingExtensionManager::GetPendingIdsForUpdateCheck( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 251 | std::list<std::string>* out_ids_for_update_check) const { |
| 252 | PendingExtensionList::const_iterator iter; |
| 253 | for (iter = pending_extension_list_.begin(); |
| 254 | iter != pending_extension_list_.end(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 255 | ++iter) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 256 | Manifest::Location install_source = iter->install_source(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 257 | |
| 258 | // Some install sources read a CRX from the filesystem. They can |
| 259 | // not be fetched from an update URL, so don't include them in the |
| 260 | // set of ids. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 261 | if (install_source == Manifest::EXTERNAL_PREF || |
binjin | 52eb4041 | 2015-08-18 06:29:30 | [diff] [blame] | 262 | install_source == Manifest::EXTERNAL_REGISTRY || |
| 263 | install_source == Manifest::EXTERNAL_POLICY) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 264 | continue; |
binjin | 52eb4041 | 2015-08-18 06:29:30 | [diff] [blame] | 265 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 266 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 267 | out_ids_for_update_check->push_back(iter->id()); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 268 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 271 | bool PendingExtensionManager::AddExtensionImpl( |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 272 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 273 | const std::string& install_parameter, |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 274 | const GURL& update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 275 | const base::Version& version, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 276 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 277 | bool is_from_sync, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 278 | Manifest::Location install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 279 | int creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 280 | bool mark_acknowledged, |
| 281 | bool remote_install) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 282 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 283 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 284 | PendingExtensionInfo info(id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 285 | install_parameter, |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 286 | update_url, |
| 287 | version, |
| 288 | should_allow_install, |
| 289 | is_from_sync, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 290 | install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 291 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 292 | mark_acknowledged, |
| 293 | remote_install); |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 294 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 295 | if (const PendingExtensionInfo* pending = GetById(id)) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 296 | // Bugs in this code will manifest as sporadic incorrect extension |
| 297 | // locations in situations where multiple install sources run at the |
| 298 | // same time. For example, on first login to a chrome os machine, an |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 299 | // extension may be requested by sync and the default extension set. |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 300 | // The following logging will help diagnose such issues. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 301 | VLOG(1) << "Extension id " << id |
| 302 | << " was entered for update more than once." |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 303 | << " old location: " << pending->install_source() |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 304 | << " new location: " << install_source |
| 305 | << " old version: " << GetVersionString(pending->version()) |
| 306 | << " new version: " << GetVersionString(version); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 307 | |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 308 | // Never override an existing extension with an older version. Only |
| 309 | // extensions from local CRX files have a known version; extensions from an |
| 310 | // update URL will get the latest version. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 311 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 312 | // If |pending| has the same or higher precedence than |info| then don't |
| 313 | // install |info| over |pending|. |
| 314 | if (pending->CompareTo(info) >= 0) |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 315 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 316 | |
| 317 | VLOG(1) << "Overwrite existing record."; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 318 | |
| 319 | std::replace(pending_extension_list_.begin(), |
| 320 | pending_extension_list_.end(), |
| 321 | *pending, |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 322 | info); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 323 | } else { |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 324 | pending_extension_list_.push_back(info); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 327 | return true; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void PendingExtensionManager::AddForTesting( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 331 | const PendingExtensionInfo& pending_extension_info) { |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 332 | pending_extension_list_.push_back(pending_extension_info); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 333 | } |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 334 | |
| 335 | } // namespace extensions |