[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" |
asvitkine | f5d4ee56 | 2016-11-07 18:57:08 | [diff] [blame] | 10 | #include "base/metrics/histogram_macros.h" |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 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) { |
Jan Wilken Dörrie | ade7922 | 2019-06-06 19:01:12 | [diff] [blame] | 58 | if (base::Contains(expected_policy_reinstalls_, id)) { |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 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 | |
Devlin Cronin | 2b3acda | 2019-05-30 19:11:37 | [diff] [blame] | 98 | bool PendingExtensionManager::HasHighPriorityPendingExtension() const { |
| 99 | return std::find_if( |
| 100 | pending_extension_list_.begin(), pending_extension_list_.end(), |
| 101 | [](const PendingExtensionInfo& info) { |
| 102 | return info.install_source() == |
| 103 | Manifest::EXTERNAL_POLICY_DOWNLOAD || |
| 104 | info.install_source() == Manifest::EXTERNAL_COMPONENT; |
| 105 | }) != pending_extension_list_.end(); |
Oleg Davydov | 6541a64f | 2019-04-17 13:17:33 | [diff] [blame] | 106 | } |
| 107 | |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 108 | void PendingExtensionManager::ExpectPolicyReinstallForCorruption( |
| 109 | const ExtensionId& id) { |
Jan Wilken Dörrie | ade7922 | 2019-06-06 19:01:12 | [diff] [blame] | 110 | if (base::Contains(expected_policy_reinstalls_, id)) |
Sergey Poromov | 6d05035 | 2018-11-27 18:57:02 | [diff] [blame] | 111 | return; |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 112 | expected_policy_reinstalls_[id] = base::TimeTicks::Now(); |
Sergey Poromov | 6d05035 | 2018-11-27 18:57:02 | [diff] [blame] | 113 | UMA_HISTOGRAM_BOOLEAN("Extensions.CorruptPolicyExtensionDetected2", true); |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool PendingExtensionManager::IsPolicyReinstallForCorruptionExpected( |
| 117 | const ExtensionId& id) const { |
Jan Wilken Dörrie | ade7922 | 2019-06-06 19:01:12 | [diff] [blame] | 118 | return base::Contains(expected_policy_reinstalls_, id); |
asargent | 56282ab7 | 2016-09-09 16:58:03 | [diff] [blame] | 119 | } |
| 120 | |
lazyboy | 77214d3c | 2017-04-04 16:46:12 | [diff] [blame] | 121 | bool PendingExtensionManager::HasAnyPolicyReinstallForCorruption() const { |
| 122 | return !expected_policy_reinstalls_.empty(); |
| 123 | } |
| 124 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 125 | bool PendingExtensionManager::AddFromSync( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 126 | const std::string& id, |
| 127 | const GURL& update_url, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 128 | const base::Version& version, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 129 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 130 | bool remote_install) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 131 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 133 | if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 134 | id, ExtensionRegistry::EVERYTHING)) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 135 | LOG(ERROR) << "Trying to add pending extension " << id |
| 136 | << " which already exists"; |
| 137 | return false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 140 | // Make sure we don't ever try to install the CWS app, because even though |
| 141 | // it is listed as a syncable app (because its values need to be synced) it |
| 142 | // should already be installed on every instance. |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 143 | if (id == extensions::kWebStoreAppId) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 144 | NOTREACHED(); |
| 145 | return false; |
| 146 | } |
| 147 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 148 | static const bool kIsFromSync = true; |
| 149 | static const Manifest::Location kSyncLocation = Manifest::INTERNAL; |
| 150 | static const bool kMarkAcknowledged = false; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 151 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 152 | return AddExtensionImpl(id, |
| 153 | std::string(), |
| 154 | update_url, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 155 | version, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 156 | should_allow_install, |
| 157 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 158 | kSyncLocation, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 159 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 160 | kMarkAcknowledged, |
| 161 | remote_install); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 164 | bool PendingExtensionManager::AddFromExtensionImport( |
| 165 | const std::string& id, |
| 166 | const GURL& update_url, |
| 167 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { |
| 168 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 169 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 170 | if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 171 | id, ExtensionRegistry::EVERYTHING)) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 172 | LOG(ERROR) << "Trying to add pending extension " << id |
| 173 | << " which already exists"; |
| 174 | return false; |
| 175 | } |
| 176 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 177 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 178 | static const Manifest::Location kManifestLocation = Manifest::INTERNAL; |
| 179 | static const bool kMarkAcknowledged = false; |
| 180 | static const bool kRemoteInstall = false; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 181 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 182 | return AddExtensionImpl(id, |
| 183 | std::string(), |
| 184 | update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 185 | base::Version(), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 186 | should_allow_install, |
| 187 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 188 | kManifestLocation, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 189 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 190 | kMarkAcknowledged, |
| 191 | kRemoteInstall); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 194 | bool PendingExtensionManager::AddFromExternalUpdateUrl( |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 195 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 196 | const std::string& install_parameter, |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 197 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 198 | Manifest::Location location, |
| 199 | int creation_flags, |
| 200 | bool mark_acknowledged) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 201 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 202 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 203 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 204 | static const bool kRemoteInstall = false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 205 | |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 206 | const Extension* extension = ExtensionRegistry::Get(context_) |
| 207 | ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 208 | if (extension && location == Manifest::GetHigherPriorityLocation( |
| 209 | location, extension->location())) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 210 | // If the new location has higher priority than the location of an existing |
| 211 | // extension, let the update process overwrite the existing extension. |
| 212 | } else { |
emaxx | 6699afb68 | 2016-10-10 21:22:13 | [diff] [blame] | 213 | // Skip the installation if the extension was removed by the user and it's |
| 214 | // not specified to be force-installed through the policy. |
| 215 | if (!Manifest::IsPolicyLocation(location) && |
| 216 | ExtensionPrefs::Get(context_)->IsExternalExtensionUninstalled(id)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 217 | return false; |
emaxx | 6699afb68 | 2016-10-10 21:22:13 | [diff] [blame] | 218 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 219 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 220 | if (extension) { |
| 221 | LOG(DFATAL) << "Trying to add extension " << id |
| 222 | << " by external update, but it is already installed."; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 223 | return false; |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 224 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 227 | return AddExtensionImpl(id, |
| 228 | install_parameter, |
| 229 | update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 230 | base::Version(), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 231 | &AlwaysInstall, |
| 232 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 233 | location, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 234 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 235 | mark_acknowledged, |
| 236 | kRemoteInstall); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 237 | } |
| 238 | |
thakis | 37be69c | 2015-08-19 03:26:57 | [diff] [blame] | 239 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 240 | bool PendingExtensionManager::AddFromExternalFile( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 241 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 242 | Manifest::Location install_source, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 243 | const base::Version& version, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 244 | int creation_flags, |
| 245 | bool mark_acknowledged) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 246 | // TODO(skerner): AddFromSync() checks to see if the extension is |
| 247 | // installed, but this method assumes that the caller already |
| 248 | // made sure it is not installed. Make all AddFrom*() methods |
| 249 | // consistent. |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 250 | const GURL& kUpdateUrl = GURL::EmptyGURL(); |
| 251 | static const bool kIsFromSync = false; |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 252 | static const bool kRemoteInstall = false; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 253 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 254 | return AddExtensionImpl(id, |
| 255 | std::string(), |
| 256 | kUpdateUrl, |
| 257 | version, |
| 258 | &AlwaysInstall, |
| 259 | kIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 260 | install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 261 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 262 | mark_acknowledged, |
| 263 | kRemoteInstall); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void PendingExtensionManager::GetPendingIdsForUpdateCheck( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 267 | std::list<std::string>* out_ids_for_update_check) const { |
| 268 | PendingExtensionList::const_iterator iter; |
| 269 | for (iter = pending_extension_list_.begin(); |
| 270 | iter != pending_extension_list_.end(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 271 | ++iter) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 272 | Manifest::Location install_source = iter->install_source(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 273 | |
| 274 | // Some install sources read a CRX from the filesystem. They can |
| 275 | // not be fetched from an update URL, so don't include them in the |
| 276 | // set of ids. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 277 | if (install_source == Manifest::EXTERNAL_PREF || |
binjin | 52eb4041 | 2015-08-18 06:29:30 | [diff] [blame] | 278 | install_source == Manifest::EXTERNAL_REGISTRY || |
| 279 | install_source == Manifest::EXTERNAL_POLICY) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 280 | continue; |
binjin | 52eb4041 | 2015-08-18 06:29:30 | [diff] [blame] | 281 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 282 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 283 | out_ids_for_update_check->push_back(iter->id()); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 284 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 285 | } |
| 286 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 287 | bool PendingExtensionManager::AddExtensionImpl( |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 288 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 289 | const std::string& install_parameter, |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 290 | const GURL& update_url, |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 291 | const base::Version& version, |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 292 | PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 293 | bool is_from_sync, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 294 | Manifest::Location install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 295 | int creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 296 | bool mark_acknowledged, |
| 297 | bool remote_install) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 298 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 299 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 300 | PendingExtensionInfo info(id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 301 | install_parameter, |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 302 | update_url, |
| 303 | version, |
| 304 | should_allow_install, |
| 305 | is_from_sync, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 306 | install_source, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 307 | creation_flags, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 308 | mark_acknowledged, |
| 309 | remote_install); |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 310 | |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 311 | if (const PendingExtensionInfo* pending = GetById(id)) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 312 | // Bugs in this code will manifest as sporadic incorrect extension |
| 313 | // locations in situations where multiple install sources run at the |
| 314 | // same time. For example, on first login to a chrome os machine, an |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 315 | // extension may be requested by sync and the default extension set. |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 316 | // The following logging will help diagnose such issues. |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 317 | VLOG(1) << "Extension id " << id |
| 318 | << " was entered for update more than once." |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 319 | << " old location: " << pending->install_source() |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 320 | << " new location: " << install_source |
| 321 | << " old version: " << GetVersionString(pending->version()) |
| 322 | << " new version: " << GetVersionString(version); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 323 | |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 324 | // Never override an existing extension with an older version. Only |
| 325 | // extensions from local CRX files have a known version; extensions from an |
| 326 | // update URL will get the latest version. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 327 | |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 328 | // If |pending| has the same or higher precedence than |info| then don't |
| 329 | // install |info| over |pending|. |
| 330 | if (pending->CompareTo(info) >= 0) |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 331 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 332 | |
| 333 | VLOG(1) << "Overwrite existing record."; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 334 | |
| 335 | std::replace(pending_extension_list_.begin(), |
| 336 | pending_extension_list_.end(), |
| 337 | *pending, |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 338 | info); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 339 | } else { |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 340 | pending_extension_list_.push_back(info); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 343 | return true; |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void PendingExtensionManager::AddForTesting( |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 347 | const PendingExtensionInfo& pending_extension_info) { |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 348 | pending_extension_list_.push_back(pending_extension_info); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 349 | } |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 350 | |
| 351 | } // namespace extensions |