Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/extensions/pending_extension_manager.cc

Issue 9595001: Apps on NTP should be in order of installation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: A few fixes per comments made Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "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 std::find_if(pending_extension_list_.begin(),
Aaron Boodman 2012/04/09 17:02:14 I know Dmitry suggested std::find in a previous re
Dmitry Polukhin 2012/04/10 08:57:26 Actually you can use std::find directly you just n
mitchellwrosen 2012/04/13 22:20:18 I went back and changed them all to explicit itera
36 pending_extension_list_.end(),
37 IsId(id));
33 38
34 PendingExtensionMap::const_iterator it = pending_extension_map_.find(id); 39 if (iter != pending_extension_list_.end()) {
35 if (it != pending_extension_map_.end()) { 40 return &(*iter);
36 *out_pending_extension_info = it->second; 41 }
42
43 return NULL;
44 }
45
46 bool PendingExtensionManager::Remove(const std::string& id) {
47 std::list<PendingExtensionInfo>::iterator iter =
48 std::find_if(pending_extension_list_.begin(),
49 pending_extension_list_.end(),
50 IsId(id));
51
52 if (iter != pending_extension_list_.end()) {
53 pending_extension_list_.erase(iter);
37 return true; 54 return true;
38 } 55 }
39 56
40 return false; 57 return false;
41 } 58 }
42 59
43 void PendingExtensionManager::Remove(const std::string& id) { 60 bool PendingExtensionManager::IsIdPending(const std::string& id) const {
44 pending_extension_map_.erase(id); 61 std::list<PendingExtensionInfo>::const_iterator iter =
45 } 62 std::find_if(pending_extension_list_.begin(),
63 pending_extension_list_.end(),
64 IsId(id));
46 65
47 bool PendingExtensionManager::IsIdPending(const std::string& id) const { 66 return iter != pending_extension_list_.end();
48 return ContainsKey(pending_extension_map_, id);
49 } 67 }
50 68
51 bool PendingExtensionManager::AddFromSync( 69 bool PendingExtensionManager::AddFromSync(
52 const std::string& id, 70 const std::string& id,
53 const GURL& update_url, 71 const GURL& update_url,
54 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, 72 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
55 bool install_silently) { 73 bool install_silently) {
56 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 74 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 75
58 if (service_.GetInstalledExtension(id)) { 76 if (service_.GetInstalledExtension(id)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 kUpdateUrl, 142 kUpdateUrl,
125 &AlwaysInstall, 143 &AlwaysInstall,
126 kIsFromSync, 144 kIsFromSync,
127 kInstallSilently, 145 kInstallSilently,
128 install_source); 146 install_source);
129 147
130 return true; 148 return true;
131 } 149 }
132 150
133 void PendingExtensionManager::GetPendingIdsForUpdateCheck( 151 void PendingExtensionManager::GetPendingIdsForUpdateCheck(
134 std::set<std::string>* out_ids_for_update_check) const { 152 std::list<std::string>* out_ids_for_update_check) const {
135 PendingExtensionMap::const_iterator iter; 153 std::list<PendingExtensionInfo>::const_iterator iter;
136 for (iter = pending_extension_map_.begin(); 154 for (iter = pending_extension_list_.begin();
137 iter != pending_extension_map_.end(); 155 iter != pending_extension_list_.end();
138 ++iter) { 156 ++iter) {
139 Extension::Location install_source = iter->second.install_source(); 157 Extension::Location install_source = iter->install_source();
140 158
141 // Some install sources read a CRX from the filesystem. They can 159 // 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 160 // not be fetched from an update URL, so don't include them in the
143 // set of ids. 161 // set of ids.
144 if (install_source == Extension::EXTERNAL_PREF || 162 if (install_source == Extension::EXTERNAL_PREF ||
145 install_source == Extension::EXTERNAL_REGISTRY) 163 install_source == Extension::EXTERNAL_REGISTRY)
146 continue; 164 continue;
147 165
148 out_ids_for_update_check->insert(iter->first); 166 out_ids_for_update_check->push_back(iter->id());
149 } 167 }
150 } 168 }
151 169
152 bool PendingExtensionManager::AddExtensionImpl( 170 bool PendingExtensionManager::AddExtensionImpl(
153 const std::string& id, 171 const std::string& id,
154 const GURL& update_url, 172 const GURL& update_url,
155 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install, 173 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install,
156 bool is_from_sync, 174 bool is_from_sync,
157 bool install_silently, 175 bool install_silently,
158 Extension::Location install_source) { 176 Extension::Location install_source) {
159 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 177 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
160 178
161 // Will add a pending extension record unless this variable is set to false. 179 // Will add a pending extension record unless this variable is set to false.
162 bool should_add_pending_record = true; 180 bool should_add_pending_record = true;
163 181
164 if (ContainsKey(pending_extension_map_, id)) { 182 std::list<PendingExtensionInfo>::iterator iter =
183 std::find_if(pending_extension_list_.begin(),
184 pending_extension_list_.end(),
185 IsId(id));
186
187 if (iter != pending_extension_list_.end()) {
165 // Bugs in this code will manifest as sporadic incorrect extension 188 // Bugs in this code will manifest as sporadic incorrect extension
166 // locations in situations where multiple install sources run at the 189 // locations in situations where multiple install sources run at the
167 // same time. For example, on first login to a chrome os machine, an 190 // same time. For example, on first login to a chrome os machine, an
168 // extension may be requested by sync and the default extension set. 191 // extension may be requested by sync and the default extension set.
169 // The following logging will help diagnose such issues. 192 // The following logging will help diagnose such issues.
170 VLOG(1) << "Extension id " << id 193 VLOG(1) << "Extension id " << id
171 << " was entered for update more than once." 194 << " was entered for update more than once."
172 << " old location: " << pending_extension_map_[id].install_source() 195 << " old location: " << iter->install_source()
173 << " new location: " << install_source; 196 << " new location: " << install_source;
174 197
175 Extension::Location higher_priority_location = 198 Extension::Location higher_priority_location =
176 Extension::GetHigherPriorityLocation( 199 Extension::GetHigherPriorityLocation(
177 install_source, pending_extension_map_[id].install_source()); 200 install_source, iter->install_source());
178 201
179 if (higher_priority_location == install_source) { 202 if (higher_priority_location == install_source) {
180 VLOG(1) << "Overwrite existing record."; 203 VLOG(1) << "Overwrite existing record.";
181 204
182 } else { 205 } else {
183 VLOG(1) << "Keep existing record."; 206 VLOG(1) << "Keep existing record.";
184 should_add_pending_record = false; 207 should_add_pending_record = false;
185 } 208 }
186 } 209 }
187 210
188 if (should_add_pending_record) { 211 if (should_add_pending_record) {
189 pending_extension_map_[id] = PendingExtensionInfo( 212 PendingExtensionInfo new_pending_record(id,
190 update_url, 213 update_url,
191 should_allow_install, 214 should_allow_install,
192 is_from_sync, 215 is_from_sync,
193 install_silently, 216 install_silently,
194 install_source); 217 install_source);
218
219 pending_extension_list_.push_back(new_pending_record);
195 return true; 220 return true;
196 } 221 }
197 return false; 222 return false;
198 } 223 }
199 224
200 void PendingExtensionManager::AddForTesting( 225 void PendingExtensionManager::AddForTesting(
201 const std::string& id, 226 const std::string& id,
202 const PendingExtensionInfo& pending_extension_info) { 227 const PendingExtensionInfo& pending_extension_info) {
203 pending_extension_map_[id] = pending_extension_info; 228 pending_extension_list_.push_back(pending_extension_info);
204 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698