Chromium Code Reviews| 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" | |
|
Aaron Boodman
2012/05/01 15:50:22
Thanks for fixing this
| |
| 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 "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/pending_extension_manager.h" | 10 #include "chrome/browser/extensions/pending_extension_info.h" |
| 9 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 10 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 11 | 13 |
| 12 using content::BrowserThread; | 14 using content::BrowserThread; |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // Install predicate used by AddFromExternalUpdateUrl(). | 18 // Install predicate used by AddFromExternalUpdateUrl(). |
| 17 bool AlwaysInstall(const Extension& extension) { | 19 bool AlwaysInstall(const Extension& extension) { |
| 18 return true; | 20 return true; |
| 19 } | 21 } |
| 20 | 22 |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 PendingExtensionManager::PendingExtensionManager( | 25 PendingExtensionManager::PendingExtensionManager( |
| 24 const ExtensionServiceInterface& service) | 26 const ExtensionServiceInterface& service) |
| 25 : service_(service) { | 27 : service_(service) { |
| 26 } | 28 } |
| 27 | 29 |
| 28 PendingExtensionManager::~PendingExtensionManager() {} | 30 PendingExtensionManager::~PendingExtensionManager() {} |
| 29 | 31 |
| 30 bool PendingExtensionManager::GetById( | 32 const PendingExtensionInfo* PendingExtensionManager::GetById( |
| 31 const std::string& id, | 33 const std::string& id) const { |
| 32 PendingExtensionInfo* out_pending_extension_info) const { | 34 std::list<PendingExtensionInfo>::const_iterator iter; |
| 35 for (iter = pending_extension_list_.begin(); | |
| 36 iter != pending_extension_list_.end(); | |
|
Aaron Boodman
2012/05/01 15:50:22
Nit: You should bring the typedef back that was in
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 37 ++iter) { | |
| 38 if (!id.compare(iter->id())) | |
|
Aaron Boodman
2012/05/01 15:50:22
Nit: We don't usually use compare() with strings.
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 39 return &(*iter); | |
| 40 } | |
| 33 | 41 |
| 34 PendingExtensionMap::const_iterator it = pending_extension_map_.find(id); | 42 return NULL; |
| 35 if (it != pending_extension_map_.end()) { | 43 } |
| 36 *out_pending_extension_info = it->second; | 44 |
| 37 return true; | 45 bool PendingExtensionManager::Remove(const std::string& id) { |
|
Aaron Boodman
2012/05/01 15:50:22
Same comments as GetById
mitchellwrosen
2012/05/11 05:45:03
Done.
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 46 std::list<PendingExtensionInfo>::iterator iter; | |
| 47 for (iter = pending_extension_list_.begin(); | |
| 48 iter != pending_extension_list_.end(); | |
| 49 ++iter) { | |
| 50 if (!id.compare(iter->id())) { | |
| 51 pending_extension_list_.erase(iter); | |
| 52 return true; | |
| 53 } | |
| 38 } | 54 } |
| 39 | 55 |
| 40 return false; | 56 return false; |
| 41 } | 57 } |
| 42 | 58 |
| 43 void PendingExtensionManager::Remove(const std::string& id) { | 59 bool PendingExtensionManager::IsIdPending(const std::string& id) const { |
| 44 pending_extension_map_.erase(id); | 60 std::list<PendingExtensionInfo>::const_iterator iter; |
| 45 } | 61 for (iter = pending_extension_list_.begin(); |
|
Aaron Boodman
2012/05/01 15:50:22
Same comments as GetById
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 62 iter != pending_extension_list_.end(); | |
| 63 ++iter) { | |
| 64 if (!id.compare(iter->id())) | |
| 65 return true; | |
| 66 } | |
| 46 | 67 |
| 47 bool PendingExtensionManager::IsIdPending(const std::string& id) const { | 68 return false; |
| 48 return ContainsKey(pending_extension_map_, id); | |
| 49 } | 69 } |
| 50 | 70 |
| 51 bool PendingExtensionManager::AddFromSync( | 71 bool PendingExtensionManager::AddFromSync( |
| 52 const std::string& id, | 72 const std::string& id, |
| 53 const GURL& update_url, | 73 const GURL& update_url, |
| 54 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 74 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 55 bool install_silently) { | 75 bool install_silently) { |
| 56 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 57 | 77 |
| 58 if (service_.GetInstalledExtension(id)) { | 78 if (service_.GetInstalledExtension(id)) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 kUpdateUrl, | 144 kUpdateUrl, |
| 125 &AlwaysInstall, | 145 &AlwaysInstall, |
| 126 kIsFromSync, | 146 kIsFromSync, |
| 127 kInstallSilently, | 147 kInstallSilently, |
| 128 install_source); | 148 install_source); |
| 129 | 149 |
| 130 return true; | 150 return true; |
| 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 std::list<PendingExtensionInfo>::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 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, | 175 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, |
| 156 bool is_from_sync, | 176 bool is_from_sync, |
| 157 bool install_silently, | 177 bool install_silently, |
| 158 Extension::Location install_source) { | 178 Extension::Location install_source) { |
| 159 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 179 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 160 | 180 |
| 161 // Will add a pending extension record unless this variable is set to false. | 181 // Will add a pending extension record unless this variable is set to false. |
| 162 bool should_add_pending_record = true; | 182 bool should_add_pending_record = true; |
| 163 | 183 |
| 164 if (ContainsKey(pending_extension_map_, id)) { | 184 std::list<PendingExtensionInfo>::iterator iter; |
| 165 // Bugs in this code will manifest as sporadic incorrect extension | 185 for (iter = pending_extension_list_.begin(); |
|
Aaron Boodman
2012/05/01 15:50:22
if (GetById(id)) ?
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 166 // locations in situations where multiple install sources run at the | 186 iter != pending_extension_list_.end(); |
| 167 // same time. For example, on first login to a chrome os machine, an | 187 ++iter) { |
| 168 // extension may be requested by sync and the default extension set. | 188 if (!id.compare(iter->id())) { |
| 169 // The following logging will help diagnose such issues. | 189 // Bugs in this code will manifest as sporadic incorrect extension |
| 170 VLOG(1) << "Extension id " << id | 190 // locations in situations where multiple install sources run at the |
| 171 << " was entered for update more than once." | 191 // same time. For example, on first login to a chrome os machine, an |
| 172 << " old location: " << pending_extension_map_[id].install_source() | 192 // extension may be requested by sync and the default extension set. |
| 173 << " new location: " << install_source; | 193 // The following logging will help diagnose such issues. |
| 194 VLOG(1) << "Extension id " << id | |
| 195 << " was entered for update more than once." | |
| 196 << " old location: " << iter->install_source() | |
| 197 << " new location: " << install_source; | |
| 174 | 198 |
| 175 Extension::Location higher_priority_location = | 199 Extension::Location higher_priority_location = |
| 176 Extension::GetHigherPriorityLocation( | 200 Extension::GetHigherPriorityLocation( |
| 177 install_source, pending_extension_map_[id].install_source()); | 201 install_source, iter->install_source()); |
| 178 | 202 |
| 179 if (higher_priority_location == install_source) { | 203 if (higher_priority_location == install_source) { |
| 180 VLOG(1) << "Overwrite existing record."; | 204 VLOG(1) << "Overwrite existing record."; |
| 181 | 205 |
| 182 } else { | 206 } else { |
| 183 VLOG(1) << "Keep existing record."; | 207 VLOG(1) << "Keep existing record."; |
| 184 should_add_pending_record = false; | 208 should_add_pending_record = false; |
| 209 } | |
| 210 | |
| 211 break; | |
| 185 } | 212 } |
| 186 } | 213 } |
| 187 | 214 |
| 188 if (should_add_pending_record) { | 215 if (should_add_pending_record) { |
| 189 pending_extension_map_[id] = PendingExtensionInfo( | 216 PendingExtensionInfo new_pending_record(id, |
| 190 update_url, | 217 update_url, |
| 191 should_allow_install, | 218 should_allow_install, |
| 192 is_from_sync, | 219 is_from_sync, |
| 193 install_silently, | 220 install_silently, |
| 194 install_source); | 221 install_source); |
| 222 | |
| 223 pending_extension_list_.push_back(new_pending_record); | |
| 195 return true; | 224 return true; |
| 196 } | 225 } |
| 226 | |
| 197 return false; | 227 return false; |
| 198 } | 228 } |
| 199 | 229 |
| 200 void PendingExtensionManager::AddForTesting( | 230 void PendingExtensionManager::AddForTesting( |
| 201 const std::string& id, | 231 const std::string& id, |
| 202 const PendingExtensionInfo& pending_extension_info) { | 232 const PendingExtensionInfo& pending_extension_info) { |
| 203 pending_extension_map_[id] = pending_extension_info; | 233 pending_extension_list_.push_back(pending_extension_info); |
| 204 } | 234 } |
| OLD | NEW |