| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/pending_extension_manager.h" | 5 #include "extensions/browser/pending_extension_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // should already be installed on every instance. | 102 // should already be installed on every instance. |
| 103 if (id == extension_misc::kWebStoreAppId) { | 103 if (id == extension_misc::kWebStoreAppId) { |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 | 107 |
| 108 const bool kIsFromSync = true; | 108 const bool kIsFromSync = true; |
| 109 const Manifest::Location kSyncLocation = Manifest::INTERNAL; | 109 const Manifest::Location kSyncLocation = Manifest::INTERNAL; |
| 110 const bool kMarkAcknowledged = false; | 110 const bool kMarkAcknowledged = false; |
| 111 | 111 |
| 112 return AddExtensionImpl(id, update_url, Version(), should_allow_install, | 112 return AddExtensionImpl(id, |
| 113 kIsFromSync, install_silently, kSyncLocation, | 113 std::string(), |
| 114 Extension::NO_FLAGS, kMarkAcknowledged); | 114 update_url, |
| 115 Version(), |
| 116 should_allow_install, |
| 117 kIsFromSync, |
| 118 install_silently, |
| 119 kSyncLocation, |
| 120 Extension::NO_FLAGS, |
| 121 kMarkAcknowledged); |
| 115 } | 122 } |
| 116 | 123 |
| 117 bool PendingExtensionManager::AddFromExtensionImport( | 124 bool PendingExtensionManager::AddFromExtensionImport( |
| 118 const std::string& id, | 125 const std::string& id, |
| 119 const GURL& update_url, | 126 const GURL& update_url, |
| 120 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { | 127 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { |
| 121 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 122 | 129 |
| 123 if (service_.GetInstalledExtension(id)) { | 130 if (service_.GetInstalledExtension(id)) { |
| 124 LOG(ERROR) << "Trying to add pending extension " << id | 131 LOG(ERROR) << "Trying to add pending extension " << id |
| 125 << " which already exists"; | 132 << " which already exists"; |
| 126 return false; | 133 return false; |
| 127 } | 134 } |
| 128 | 135 |
| 129 const bool kIsFromSync = false; | 136 const bool kIsFromSync = false; |
| 130 const bool kInstallSilently = true; | 137 const bool kInstallSilently = true; |
| 131 const Manifest::Location kManifestLocation = Manifest::INTERNAL; | 138 const Manifest::Location kManifestLocation = Manifest::INTERNAL; |
| 132 const bool kMarkAcknowledged = false; | 139 const bool kMarkAcknowledged = false; |
| 133 | 140 |
| 134 return AddExtensionImpl(id, update_url, Version(), should_allow_install, | 141 return AddExtensionImpl(id, |
| 135 kIsFromSync, kInstallSilently, kManifestLocation, | 142 std::string(), |
| 136 Extension::NO_FLAGS, kMarkAcknowledged); | 143 update_url, |
| 144 Version(), |
| 145 should_allow_install, |
| 146 kIsFromSync, |
| 147 kInstallSilently, |
| 148 kManifestLocation, |
| 149 Extension::NO_FLAGS, |
| 150 kMarkAcknowledged); |
| 137 } | 151 } |
| 138 | 152 |
| 139 bool PendingExtensionManager::AddFromExternalUpdateUrl( | 153 bool PendingExtensionManager::AddFromExternalUpdateUrl( |
| 140 const std::string& id, | 154 const std::string& id, |
| 155 const std::string& install_parameter, |
| 141 const GURL& update_url, | 156 const GURL& update_url, |
| 142 Manifest::Location location, | 157 Manifest::Location location, |
| 143 int creation_flags, | 158 int creation_flags, |
| 144 bool mark_acknowledged) { | 159 bool mark_acknowledged) { |
| 145 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 146 | 161 |
| 147 const bool kIsFromSync = false; | 162 const bool kIsFromSync = false; |
| 148 const bool kInstallSilently = true; | 163 const bool kInstallSilently = true; |
| 149 | 164 |
| 150 const Extension* extension = service_.GetInstalledExtension(id); | 165 const Extension* extension = service_.GetInstalledExtension(id); |
| 151 if (extension && | 166 if (extension && location == Manifest::GetHigherPriorityLocation( |
| 152 location == Manifest::GetHigherPriorityLocation(location, | 167 location, extension->location())) { |
| 153 extension->location())) { | |
| 154 // If the new location has higher priority than the location of an existing | 168 // If the new location has higher priority than the location of an existing |
| 155 // extension, let the update process overwrite the existing extension. | 169 // extension, let the update process overwrite the existing extension. |
| 156 } else { | 170 } else { |
| 157 if (service_.IsExternalExtensionUninstalled(id)) | 171 if (service_.IsExternalExtensionUninstalled(id)) |
| 158 return false; | 172 return false; |
| 159 | 173 |
| 160 if (extension) { | 174 if (extension) { |
| 161 LOG(DFATAL) << "Trying to add extension " << id | 175 LOG(DFATAL) << "Trying to add extension " << id |
| 162 << " by external update, but it is already installed."; | 176 << " by external update, but it is already installed."; |
| 163 return false; | 177 return false; |
| 164 } | 178 } |
| 165 } | 179 } |
| 166 | 180 |
| 167 return AddExtensionImpl(id, update_url, Version(), &AlwaysInstall, | 181 return AddExtensionImpl(id, |
| 168 kIsFromSync, kInstallSilently, | 182 install_parameter, |
| 169 location, creation_flags, mark_acknowledged); | 183 update_url, |
| 184 Version(), |
| 185 &AlwaysInstall, |
| 186 kIsFromSync, |
| 187 kInstallSilently, |
| 188 location, |
| 189 creation_flags, |
| 190 mark_acknowledged); |
| 170 } | 191 } |
| 171 | 192 |
| 172 | 193 |
| 173 bool PendingExtensionManager::AddFromExternalFile( | 194 bool PendingExtensionManager::AddFromExternalFile( |
| 174 const std::string& id, | 195 const std::string& id, |
| 175 Manifest::Location install_source, | 196 Manifest::Location install_source, |
| 176 const Version& version, | 197 const Version& version, |
| 177 int creation_flags, | 198 int creation_flags, |
| 178 bool mark_acknowledged) { | 199 bool mark_acknowledged) { |
| 179 // TODO(skerner): AddFromSync() checks to see if the extension is | 200 // TODO(skerner): AddFromSync() checks to see if the extension is |
| 180 // installed, but this method assumes that the caller already | 201 // installed, but this method assumes that the caller already |
| 181 // made sure it is not installed. Make all AddFrom*() methods | 202 // made sure it is not installed. Make all AddFrom*() methods |
| 182 // consistent. | 203 // consistent. |
| 183 GURL kUpdateUrl = GURL(); | 204 GURL kUpdateUrl = GURL(); |
| 184 bool kIsFromSync = false; | 205 bool kIsFromSync = false; |
| 185 bool kInstallSilently = true; | 206 bool kInstallSilently = true; |
| 186 | 207 |
| 187 return AddExtensionImpl( | 208 return AddExtensionImpl(id, |
| 188 id, | 209 std::string(), |
| 189 kUpdateUrl, | 210 kUpdateUrl, |
| 190 version, | 211 version, |
| 191 &AlwaysInstall, | 212 &AlwaysInstall, |
| 192 kIsFromSync, | 213 kIsFromSync, |
| 193 kInstallSilently, | 214 kInstallSilently, |
| 194 install_source, | 215 install_source, |
| 195 creation_flags, | 216 creation_flags, |
| 196 mark_acknowledged); | 217 mark_acknowledged); |
| 197 } | 218 } |
| 198 | 219 |
| 199 void PendingExtensionManager::GetPendingIdsForUpdateCheck( | 220 void PendingExtensionManager::GetPendingIdsForUpdateCheck( |
| 200 std::list<std::string>* out_ids_for_update_check) const { | 221 std::list<std::string>* out_ids_for_update_check) const { |
| 201 PendingExtensionList::const_iterator iter; | 222 PendingExtensionList::const_iterator iter; |
| 202 for (iter = pending_extension_list_.begin(); | 223 for (iter = pending_extension_list_.begin(); |
| 203 iter != pending_extension_list_.end(); | 224 iter != pending_extension_list_.end(); |
| 204 ++iter) { | 225 ++iter) { |
| 205 Manifest::Location install_source = iter->install_source(); | 226 Manifest::Location install_source = iter->install_source(); |
| 206 | 227 |
| 207 // Some install sources read a CRX from the filesystem. They can | 228 // Some install sources read a CRX from the filesystem. They can |
| 208 // not be fetched from an update URL, so don't include them in the | 229 // not be fetched from an update URL, so don't include them in the |
| 209 // set of ids. | 230 // set of ids. |
| 210 if (install_source == Manifest::EXTERNAL_PREF || | 231 if (install_source == Manifest::EXTERNAL_PREF || |
| 211 install_source == Manifest::EXTERNAL_REGISTRY) | 232 install_source == Manifest::EXTERNAL_REGISTRY) |
| 212 continue; | 233 continue; |
| 213 | 234 |
| 214 out_ids_for_update_check->push_back(iter->id()); | 235 out_ids_for_update_check->push_back(iter->id()); |
| 215 } | 236 } |
| 216 } | 237 } |
| 217 | 238 |
| 218 bool PendingExtensionManager::AddExtensionImpl( | 239 bool PendingExtensionManager::AddExtensionImpl( |
| 219 const std::string& id, | 240 const std::string& id, |
| 241 const std::string& install_parameter, |
| 220 const GURL& update_url, | 242 const GURL& update_url, |
| 221 const Version& version, | 243 const Version& version, |
| 222 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 244 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 223 bool is_from_sync, | 245 bool is_from_sync, |
| 224 bool install_silently, | 246 bool install_silently, |
| 225 Manifest::Location install_source, | 247 Manifest::Location install_source, |
| 226 int creation_flags, | 248 int creation_flags, |
| 227 bool mark_acknowledged) { | 249 bool mark_acknowledged) { |
| 228 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 229 | 251 |
| 230 PendingExtensionInfo info(id, | 252 PendingExtensionInfo info(id, |
| 253 install_parameter, |
| 231 update_url, | 254 update_url, |
| 232 version, | 255 version, |
| 233 should_allow_install, | 256 should_allow_install, |
| 234 is_from_sync, | 257 is_from_sync, |
| 235 install_silently, | 258 install_silently, |
| 236 install_source, | 259 install_source, |
| 237 creation_flags, | 260 creation_flags, |
| 238 mark_acknowledged); | 261 mark_acknowledged); |
| 239 | 262 |
| 240 if (const PendingExtensionInfo* pending = GetById(id)) { | 263 if (const PendingExtensionInfo* pending = GetById(id)) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 271 | 294 |
| 272 return true; | 295 return true; |
| 273 } | 296 } |
| 274 | 297 |
| 275 void PendingExtensionManager::AddForTesting( | 298 void PendingExtensionManager::AddForTesting( |
| 276 const PendingExtensionInfo& pending_extension_info) { | 299 const PendingExtensionInfo& pending_extension_info) { |
| 277 pending_extension_list_.push_back(pending_extension_info); | 300 pending_extension_list_.push_back(pending_extension_info); |
| 278 } | 301 } |
| 279 | 302 |
| 280 } // namespace extensions | 303 } // namespace extensions |
| OLD | NEW |