| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/pending_extension_manager.h" | 5 #include "chrome/browser/extensions/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" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
| 14 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 using content::BrowserThread; | 18 using content::BrowserThread; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Install predicate used by AddFromExternalUpdateUrl(). | 22 // Install predicate used by AddFromExternalUpdateUrl(). |
| 22 bool AlwaysInstall(const extensions::Extension* extension) { | 23 bool AlwaysInstall(const extensions::Extension* extension) { |
| 23 return true; | 24 return true; |
| 24 } | 25 } |
| 25 | 26 |
| 26 std::string GetVersionString(const Version& version) { | 27 std::string GetVersionString(const Version& version) { |
| 27 return version.IsValid() ? version.GetString() : "invalid"; | 28 return version.IsValid() ? version.GetString() : "invalid"; |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 namespace extensions { | 33 namespace extensions { |
| 33 | 34 |
| 34 PendingExtensionManager::PendingExtensionManager( | 35 PendingExtensionManager::PendingExtensionManager( |
| 35 const ExtensionServiceInterface& service, | |
| 36 content::BrowserContext* context) | 36 content::BrowserContext* context) |
| 37 : service_(service), context_(context) {} | 37 : context_(context) {} |
| 38 | 38 |
| 39 PendingExtensionManager::~PendingExtensionManager() {} | 39 PendingExtensionManager::~PendingExtensionManager() {} |
| 40 | 40 |
| 41 const PendingExtensionInfo* PendingExtensionManager::GetById( | 41 const PendingExtensionInfo* PendingExtensionManager::GetById( |
| 42 const std::string& id) const { | 42 const std::string& id) const { |
| 43 PendingExtensionList::const_iterator iter; | 43 PendingExtensionList::const_iterator iter; |
| 44 for (iter = pending_extension_list_.begin(); | 44 for (iter = pending_extension_list_.begin(); |
| 45 iter != pending_extension_list_.end(); | 45 iter != pending_extension_list_.end(); |
| 46 ++iter) { | 46 ++iter) { |
| 47 if (id == iter->id()) | 47 if (id == iter->id()) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool PendingExtensionManager::AddFromSync( | 88 bool PendingExtensionManager::AddFromSync( |
| 89 const std::string& id, | 89 const std::string& id, |
| 90 const GURL& update_url, | 90 const GURL& update_url, |
| 91 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 91 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 92 bool install_silently, | 92 bool install_silently, |
| 93 bool remote_install) { | 93 bool remote_install) { |
| 94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 95 | 95 |
| 96 if (service_.GetInstalledExtension(id)) { | 96 if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 97 id, ExtensionRegistry::EVERYTHING)) { |
| 97 LOG(ERROR) << "Trying to add pending extension " << id | 98 LOG(ERROR) << "Trying to add pending extension " << id |
| 98 << " which already exists"; | 99 << " which already exists"; |
| 99 return false; | 100 return false; |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Make sure we don't ever try to install the CWS app, because even though | 103 // Make sure we don't ever try to install the CWS app, because even though |
| 103 // it is listed as a syncable app (because its values need to be synced) it | 104 // it is listed as a syncable app (because its values need to be synced) it |
| 104 // should already be installed on every instance. | 105 // should already be installed on every instance. |
| 105 if (id == extension_misc::kWebStoreAppId) { | 106 if (id == extension_misc::kWebStoreAppId) { |
| 106 NOTREACHED(); | 107 NOTREACHED(); |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 | 110 |
| 110 const bool kIsFromSync = true; | 111 static const bool kIsFromSync = true; |
| 111 const Manifest::Location kSyncLocation = Manifest::INTERNAL; | 112 static const Manifest::Location kSyncLocation = Manifest::INTERNAL; |
| 112 const bool kMarkAcknowledged = false; | 113 static const bool kMarkAcknowledged = false; |
| 113 | 114 |
| 114 return AddExtensionImpl(id, | 115 return AddExtensionImpl(id, |
| 115 std::string(), | 116 std::string(), |
| 116 update_url, | 117 update_url, |
| 117 Version(), | 118 Version(), |
| 118 should_allow_install, | 119 should_allow_install, |
| 119 kIsFromSync, | 120 kIsFromSync, |
| 120 install_silently, | 121 install_silently, |
| 121 kSyncLocation, | 122 kSyncLocation, |
| 122 Extension::NO_FLAGS, | 123 Extension::NO_FLAGS, |
| 123 kMarkAcknowledged, | 124 kMarkAcknowledged, |
| 124 remote_install); | 125 remote_install); |
| 125 } | 126 } |
| 126 | 127 |
| 127 bool PendingExtensionManager::AddFromExtensionImport( | 128 bool PendingExtensionManager::AddFromExtensionImport( |
| 128 const std::string& id, | 129 const std::string& id, |
| 129 const GURL& update_url, | 130 const GURL& update_url, |
| 130 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { | 131 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install) { |
| 131 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 132 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | 133 |
| 133 if (service_.GetInstalledExtension(id)) { | 134 if (ExtensionRegistry::Get(context_)->GetExtensionById( |
| 135 id, ExtensionRegistry::EVERYTHING)) { |
| 134 LOG(ERROR) << "Trying to add pending extension " << id | 136 LOG(ERROR) << "Trying to add pending extension " << id |
| 135 << " which already exists"; | 137 << " which already exists"; |
| 136 return false; | 138 return false; |
| 137 } | 139 } |
| 138 | 140 |
| 139 const bool kIsFromSync = false; | 141 static const bool kIsFromSync = false; |
| 140 const bool kInstallSilently = true; | 142 static const bool kInstallSilently = true; |
| 141 const Manifest::Location kManifestLocation = Manifest::INTERNAL; | 143 static const Manifest::Location kManifestLocation = Manifest::INTERNAL; |
| 142 const bool kMarkAcknowledged = false; | 144 static const bool kMarkAcknowledged = false; |
| 143 const bool kRemoteInstall = false; | 145 static const bool kRemoteInstall = false; |
| 144 | 146 |
| 145 return AddExtensionImpl(id, | 147 return AddExtensionImpl(id, |
| 146 std::string(), | 148 std::string(), |
| 147 update_url, | 149 update_url, |
| 148 Version(), | 150 Version(), |
| 149 should_allow_install, | 151 should_allow_install, |
| 150 kIsFromSync, | 152 kIsFromSync, |
| 151 kInstallSilently, | 153 kInstallSilently, |
| 152 kManifestLocation, | 154 kManifestLocation, |
| 153 Extension::NO_FLAGS, | 155 Extension::NO_FLAGS, |
| 154 kMarkAcknowledged, | 156 kMarkAcknowledged, |
| 155 kRemoteInstall); | 157 kRemoteInstall); |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool PendingExtensionManager::AddFromExternalUpdateUrl( | 160 bool PendingExtensionManager::AddFromExternalUpdateUrl( |
| 159 const std::string& id, | 161 const std::string& id, |
| 160 const std::string& install_parameter, | 162 const std::string& install_parameter, |
| 161 const GURL& update_url, | 163 const GURL& update_url, |
| 162 Manifest::Location location, | 164 Manifest::Location location, |
| 163 int creation_flags, | 165 int creation_flags, |
| 164 bool mark_acknowledged) { | 166 bool mark_acknowledged) { |
| 165 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 | 168 |
| 167 const bool kIsFromSync = false; | 169 static const bool kIsFromSync = false; |
| 168 const bool kInstallSilently = true; | 170 static const bool kInstallSilently = true; |
| 169 const bool kRemoteInstall = false; | 171 static const bool kRemoteInstall = false; |
| 170 | 172 |
| 171 const Extension* extension = service_.GetInstalledExtension(id); | 173 const Extension* extension = ExtensionRegistry::Get(context_) |
| 174 ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
| 172 if (extension && location == Manifest::GetHigherPriorityLocation( | 175 if (extension && location == Manifest::GetHigherPriorityLocation( |
| 173 location, extension->location())) { | 176 location, extension->location())) { |
| 174 // If the new location has higher priority than the location of an existing | 177 // If the new location has higher priority than the location of an existing |
| 175 // extension, let the update process overwrite the existing extension. | 178 // extension, let the update process overwrite the existing extension. |
| 176 } else { | 179 } else { |
| 177 if (ExtensionPrefs::Get(context_)->IsExternalExtensionUninstalled(id)) | 180 if (ExtensionPrefs::Get(context_)->IsExternalExtensionUninstalled(id)) |
| 178 return false; | 181 return false; |
| 179 | 182 |
| 180 if (extension) { | 183 if (extension) { |
| 181 LOG(DFATAL) << "Trying to add extension " << id | 184 LOG(DFATAL) << "Trying to add extension " << id |
| (...skipping 19 matching lines...) Expand all Loading... |
| 201 bool PendingExtensionManager::AddFromExternalFile( | 204 bool PendingExtensionManager::AddFromExternalFile( |
| 202 const std::string& id, | 205 const std::string& id, |
| 203 Manifest::Location install_source, | 206 Manifest::Location install_source, |
| 204 const Version& version, | 207 const Version& version, |
| 205 int creation_flags, | 208 int creation_flags, |
| 206 bool mark_acknowledged) { | 209 bool mark_acknowledged) { |
| 207 // TODO(skerner): AddFromSync() checks to see if the extension is | 210 // TODO(skerner): AddFromSync() checks to see if the extension is |
| 208 // installed, but this method assumes that the caller already | 211 // installed, but this method assumes that the caller already |
| 209 // made sure it is not installed. Make all AddFrom*() methods | 212 // made sure it is not installed. Make all AddFrom*() methods |
| 210 // consistent. | 213 // consistent. |
| 211 GURL kUpdateUrl = GURL(); | 214 const GURL& kUpdateUrl = GURL::EmptyGURL(); |
| 212 const bool kIsFromSync = false; | 215 static const bool kIsFromSync = false; |
| 213 const bool kInstallSilently = true; | 216 static const bool kInstallSilently = true; |
| 214 const bool kRemoteInstall = false; | 217 static const bool kRemoteInstall = false; |
| 215 | 218 |
| 216 return AddExtensionImpl(id, | 219 return AddExtensionImpl(id, |
| 217 std::string(), | 220 std::string(), |
| 218 kUpdateUrl, | 221 kUpdateUrl, |
| 219 version, | 222 version, |
| 220 &AlwaysInstall, | 223 &AlwaysInstall, |
| 221 kIsFromSync, | 224 kIsFromSync, |
| 222 kInstallSilently, | 225 kInstallSilently, |
| 223 install_source, | 226 install_source, |
| 224 creation_flags, | 227 creation_flags, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 308 |
| 306 return true; | 309 return true; |
| 307 } | 310 } |
| 308 | 311 |
| 309 void PendingExtensionManager::AddForTesting( | 312 void PendingExtensionManager::AddForTesting( |
| 310 const PendingExtensionInfo& pending_extension_info) { | 313 const PendingExtensionInfo& pending_extension_info) { |
| 311 pending_extension_list_.push_back(pending_extension_info); | 314 pending_extension_list_.push_back(pending_extension_info); |
| 312 } | 315 } |
| 313 | 316 |
| 314 } // namespace extensions | 317 } // namespace extensions |
| OLD | NEW |