| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| 6 |
| 5 #include "base/logging.h" | 7 #include "base/logging.h" |
| 6 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 7 #include "base/version.h" | 9 #include "base/version.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/pending_extension_manager.h" | 11 #include "chrome/browser/extensions/pending_extension_info.h" |
| 10 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 12 | 14 |
| 13 using content::BrowserThread; | 15 using content::BrowserThread; |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Install predicate used by AddFromExternalUpdateUrl(). | 19 // Install predicate used by AddFromExternalUpdateUrl(). |
| 18 bool AlwaysInstall(const Extension& extension) { | 20 bool AlwaysInstall(const Extension& extension) { |
| 19 return true; | 21 return true; |
| 20 } | 22 } |
| 21 | 23 |
| 22 } // namespace | 24 } // namespace |
| 23 | 25 |
| 24 PendingExtensionManager::PendingExtensionManager( | 26 PendingExtensionManager::PendingExtensionManager( |
| 25 const ExtensionServiceInterface& service) | 27 const ExtensionServiceInterface& service) |
| 26 : service_(service) { | 28 : service_(service) { |
| 27 } | 29 } |
| 28 | 30 |
| 29 PendingExtensionManager::~PendingExtensionManager() {} | 31 PendingExtensionManager::~PendingExtensionManager() {} |
| 30 | 32 |
| 31 bool PendingExtensionManager::GetById( | 33 const PendingExtensionInfo* PendingExtensionManager::GetById( |
| 32 const std::string& id, | 34 const std::string& id) const { |
| 33 PendingExtensionInfo* out_pending_extension_info) const { | 35 PendingExtensionList::const_iterator iter; |
| 36 for (iter = pending_extension_list_.begin(); |
| 37 iter != pending_extension_list_.end(); |
| 38 ++iter) { |
| 39 if (id == iter->id()) |
| 40 return &(*iter); |
| 41 } |
| 34 | 42 |
| 35 PendingExtensionMap::const_iterator it = pending_extension_map_.find(id); | 43 return NULL; |
| 36 if (it != pending_extension_map_.end()) { | 44 } |
| 37 *out_pending_extension_info = it->second; | 45 |
| 38 return true; | 46 bool PendingExtensionManager::Remove(const std::string& id) { |
| 47 PendingExtensionList::iterator iter; |
| 48 for (iter = pending_extension_list_.begin(); |
| 49 iter != pending_extension_list_.end(); |
| 50 ++iter) { |
| 51 if (id == iter->id()) { |
| 52 pending_extension_list_.erase(iter); |
| 53 return true; |
| 54 } |
| 39 } | 55 } |
| 40 | 56 |
| 41 return false; | 57 return false; |
| 42 } | 58 } |
| 43 | 59 |
| 44 void PendingExtensionManager::Remove(const std::string& id) { | 60 bool PendingExtensionManager::IsIdPending(const std::string& id) const { |
| 45 pending_extension_map_.erase(id); | 61 PendingExtensionList::const_iterator iter; |
| 46 } | 62 for (iter = pending_extension_list_.begin(); |
| 63 iter != pending_extension_list_.end(); |
| 64 ++iter) { |
| 65 if (id == iter->id()) |
| 66 return true; |
| 67 } |
| 47 | 68 |
| 48 bool PendingExtensionManager::IsIdPending(const std::string& id) const { | 69 return false; |
| 49 return ContainsKey(pending_extension_map_, id); | |
| 50 } | 70 } |
| 51 | 71 |
| 52 bool PendingExtensionManager::AddFromSync( | 72 bool PendingExtensionManager::AddFromSync( |
| 53 const std::string& id, | 73 const std::string& id, |
| 54 const GURL& update_url, | 74 const GURL& update_url, |
| 55 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 75 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 56 bool install_silently) { | 76 bool install_silently) { |
| 57 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 78 |
| 59 if (service_.GetInstalledExtension(id)) { | 79 if (service_.GetInstalledExtension(id)) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 id, | 144 id, |
| 125 kUpdateUrl, | 145 kUpdateUrl, |
| 126 version, | 146 version, |
| 127 &AlwaysInstall, | 147 &AlwaysInstall, |
| 128 kIsFromSync, | 148 kIsFromSync, |
| 129 kInstallSilently, | 149 kInstallSilently, |
| 130 install_source); | 150 install_source); |
| 131 } | 151 } |
| 132 | 152 |
| 133 void PendingExtensionManager::GetPendingIdsForUpdateCheck( | 153 void PendingExtensionManager::GetPendingIdsForUpdateCheck( |
| 134 std::set<std::string>* out_ids_for_update_check) const { | 154 std::list<std::string>* out_ids_for_update_check) const { |
| 135 PendingExtensionMap::const_iterator iter; | 155 PendingExtensionList::const_iterator iter; |
| 136 for (iter = pending_extension_map_.begin(); | 156 for (iter = pending_extension_list_.begin(); |
| 137 iter != pending_extension_map_.end(); | 157 iter != pending_extension_list_.end(); |
| 138 ++iter) { | 158 ++iter) { |
| 139 Extension::Location install_source = iter->second.install_source(); | 159 Extension::Location install_source = iter->install_source(); |
| 140 | 160 |
| 141 // Some install sources read a CRX from the filesystem. They can | 161 // Some install sources read a CRX from the filesystem. They can |
| 142 // not be fetched from an update URL, so don't include them in the | 162 // not be fetched from an update URL, so don't include them in the |
| 143 // set of ids. | 163 // set of ids. |
| 144 if (install_source == Extension::EXTERNAL_PREF || | 164 if (install_source == Extension::EXTERNAL_PREF || |
| 145 install_source == Extension::EXTERNAL_REGISTRY) | 165 install_source == Extension::EXTERNAL_REGISTRY) |
| 146 continue; | 166 continue; |
| 147 | 167 |
| 148 out_ids_for_update_check->insert(iter->first); | 168 out_ids_for_update_check->push_back(iter->id()); |
| 149 } | 169 } |
| 150 } | 170 } |
| 151 | 171 |
| 152 bool PendingExtensionManager::AddExtensionImpl( | 172 bool PendingExtensionManager::AddExtensionImpl( |
| 153 const std::string& id, | 173 const std::string& id, |
| 154 const GURL& update_url, | 174 const GURL& update_url, |
| 155 const Version& version, | 175 const Version& version, |
| 156 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 176 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 157 bool is_from_sync, | 177 bool is_from_sync, |
| 158 bool install_silently, | 178 bool install_silently, |
| 159 Extension::Location install_source) { | 179 Extension::Location install_source) { |
| 160 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 | 181 |
| 162 PendingExtensionInfo pending; | 182 if (const PendingExtensionInfo* pending = GetById(id)) { |
| 163 if (GetById(id, &pending)) { | |
| 164 // Bugs in this code will manifest as sporadic incorrect extension | 183 // Bugs in this code will manifest as sporadic incorrect extension |
| 165 // locations in situations where multiple install sources run at the | 184 // locations in situations where multiple install sources run at the |
| 166 // same time. For example, on first login to a chrome os machine, an | 185 // same time. For example, on first login to a chrome os machine, an |
| 167 // extension may be requested by sync and the default extension set. | 186 // extension may be requested by sync and the default extension set. |
| 168 // The following logging will help diagnose such issues. | 187 // The following logging will help diagnose such issues. |
| 169 VLOG(1) << "Extension id " << id | 188 VLOG(1) << "Extension id " << id |
| 170 << " was entered for update more than once." | 189 << " was entered for update more than once." |
| 171 << " old location: " << pending.install_source() | 190 << " old location: " << pending->install_source() |
| 172 << " new location: " << install_source; | 191 << " new location: " << install_source; |
| 173 | 192 |
| 174 // Never override an existing extension with an older version. Only | 193 // Never override an existing extension with an older version. Only |
| 175 // extensions from local CRX files have a known version; extensions from an | 194 // extensions from local CRX files have a known version; extensions from an |
| 176 // update URL will get the latest version. | 195 // update URL will get the latest version. |
| 177 if (version.IsValid() && | 196 if (version.IsValid() && |
| 178 pending.version().IsValid() && | 197 pending->version().IsValid() && |
| 179 pending.version().CompareTo(version) == 1) { | 198 pending->version().CompareTo(version) == 1) { |
| 180 VLOG(1) << "Keep existing record (has a newer version)."; | 199 VLOG(1) << "Keep existing record (has a newer version)."; |
| 181 return false; | 200 return false; |
| 182 } | 201 } |
| 183 | 202 |
| 184 Extension::Location higher_priority_location = | 203 Extension::Location higher_priority_location = |
| 185 Extension::GetHigherPriorityLocation( | 204 Extension::GetHigherPriorityLocation( |
| 186 install_source, pending.install_source()); | 205 install_source, pending->install_source()); |
| 187 | 206 |
| 188 if (higher_priority_location != install_source) { | 207 if (higher_priority_location != install_source) { |
| 189 VLOG(1) << "Keep existing record (has a higher priority location)."; | 208 VLOG(1) << "Keep existing record (has a higher priority location)."; |
| 190 return false; | 209 return false; |
| 191 } | 210 } |
| 192 | 211 |
| 193 VLOG(1) << "Overwrite existing record."; | 212 VLOG(1) << "Overwrite existing record."; |
| 194 } | 213 } |
| 195 | 214 |
| 196 pending_extension_map_[id] = PendingExtensionInfo( | 215 pending_extension_list_.push_back( |
| 197 update_url, | 216 PendingExtensionInfo(id, |
| 198 version, | 217 update_url, |
| 199 should_allow_install, | 218 version, |
| 200 is_from_sync, | 219 should_allow_install, |
| 201 install_silently, | 220 is_from_sync, |
| 202 install_source); | 221 install_silently, |
| 222 install_source)); |
| 203 return true; | 223 return true; |
| 204 } | 224 } |
| 205 | 225 |
| 206 void PendingExtensionManager::AddForTesting( | 226 void PendingExtensionManager::AddForTesting( |
| 207 const std::string& id, | |
| 208 const PendingExtensionInfo& pending_extension_info) { | 227 const PendingExtensionInfo& pending_extension_info) { |
| 209 pending_extension_map_[id] = pending_extension_info; | 228 pending_extension_list_.push_back(pending_extension_info); |
| 210 } | 229 } |
| OLD | NEW |