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 "components/component_updater/component_updater_service.h" | 5 #include "components/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 return OnDemandUpdateInternal(id); | 228 return OnDemandUpdateInternal(id); |
229 } | 229 } |
230 | 230 |
231 bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) { | 231 bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) { |
232 DCHECK(thread_checker_.CalledOnValidThread()); | 232 DCHECK(thread_checker_.CalledOnValidThread()); |
233 | 233 |
234 DCHECK(GetComponent(id)); | 234 DCHECK(GetComponent(id)); |
235 | 235 |
236 // Check if the request is too soon. | 236 // Check if the request is too soon. |
237 const auto component_state(GetComponentState(id)); | 237 const auto* component_state(GetComponentState(id)); |
238 if (component_state) { | 238 if (component_state) { |
239 base::TimeDelta delta = base::Time::Now() - component_state->last_check; | 239 base::TimeDelta delta = base::Time::Now() - component_state->last_check; |
240 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 240 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
241 return false; | 241 return false; |
242 } | 242 } |
243 | 243 |
244 return OnDemandUpdateInternal(id); | 244 return OnDemandUpdateInternal(id); |
245 } | 245 } |
246 | 246 |
247 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { | 247 bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { |
(...skipping 14 matching lines...) Expand all Loading... |
262 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
263 | 263 |
264 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_AUTOMATIC, | 264 UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_AUTOMATIC, |
265 UPDATE_TYPE_COUNT); | 265 UPDATE_TYPE_COUNT); |
266 | 266 |
267 std::vector<std::string> secure_ids; // Requires HTTPS for update checks. | 267 std::vector<std::string> secure_ids; // Requires HTTPS for update checks. |
268 std::vector<std::string> unsecure_ids; // Can fallback to HTTP. | 268 std::vector<std::string> unsecure_ids; // Can fallback to HTTP. |
269 for (const auto id : components_order_) { | 269 for (const auto id : components_order_) { |
270 DCHECK(components_.find(id) != components_.end()); | 270 DCHECK(components_.find(id) != components_.end()); |
271 | 271 |
272 auto component(GetComponent(id)); | 272 auto* component(GetComponent(id)); |
273 if (!component || component->requires_network_encryption) | 273 if (!component || component->requires_network_encryption) |
274 secure_ids.push_back(id); | 274 secure_ids.push_back(id); |
275 else | 275 else |
276 unsecure_ids.push_back(id); | 276 unsecure_ids.push_back(id); |
277 } | 277 } |
278 | 278 |
279 if (!unsecure_ids.empty()) { | 279 if (!unsecure_ids.empty()) { |
280 update_client_->Update( | 280 update_client_->Update( |
281 unsecure_ids, | 281 unsecure_ids, |
282 base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), | 282 base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 return false; | 321 return false; |
322 } | 322 } |
323 | 323 |
324 void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids, | 324 void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids, |
325 std::vector<CrxComponent>* components) { | 325 std::vector<CrxComponent>* components) { |
326 DCHECK(thread_checker_.CalledOnValidThread()); | 326 DCHECK(thread_checker_.CalledOnValidThread()); |
327 DCHECK(components->empty()); | 327 DCHECK(components->empty()); |
328 | 328 |
329 for (const auto& id : ids) { | 329 for (const auto& id : ids) { |
330 const auto registered_component(GetComponent(id)); | 330 const auto* registered_component(GetComponent(id)); |
331 if (registered_component) { | 331 if (registered_component) { |
332 components->push_back(*registered_component); | 332 components->push_back(*registered_component); |
333 } | 333 } |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time, | 337 void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time, |
338 int error) { | 338 int error) { |
339 DCHECK(thread_checker_.CalledOnValidThread()); | 339 DCHECK(thread_checker_.CalledOnValidThread()); |
340 VLOG(1) << "Update completed with error " << error; | 340 VLOG(1) << "Update completed with error " << error; |
341 | 341 |
342 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", error != 0); | 342 UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", error != 0); |
343 UMA_HISTOGRAM_LONG_TIMES_100("ComponentUpdater.UpdateCompleteTime", | 343 UMA_HISTOGRAM_LONG_TIMES_100("ComponentUpdater.UpdateCompleteTime", |
344 base::TimeTicks::Now() - start_time); | 344 base::TimeTicks::Now() - start_time); |
345 | 345 |
346 for (const auto id : components_pending_unregistration_) { | 346 for (const auto id : components_pending_unregistration_) { |
347 if (!update_client_->IsUpdating(id)) { | 347 if (!update_client_->IsUpdating(id)) { |
348 const auto component = GetComponent(id); | 348 const auto* component = GetComponent(id); |
349 if (component) | 349 if (component) |
350 DoUnregisterComponent(*component); | 350 DoUnregisterComponent(*component); |
351 } | 351 } |
352 } | 352 } |
353 } | 353 } |
354 | 354 |
355 void CrxUpdateService::OnEvent(Events event, const std::string& id) { | 355 void CrxUpdateService::OnEvent(Events event, const std::string& id) { |
356 DCHECK(thread_checker_.CalledOnValidThread()); | 356 DCHECK(thread_checker_.CalledOnValidThread()); |
357 | 357 |
358 // Unblock all throttles for the component. | 358 // Unblock all throttles for the component. |
(...skipping 10 matching lines...) Expand all Loading... |
369 if (!update_client_->GetCrxUpdateState(id, &update_item)) | 369 if (!update_client_->GetCrxUpdateState(id, &update_item)) |
370 return; | 370 return; |
371 | 371 |
372 // Update the state of the item. | 372 // Update the state of the item. |
373 auto it = component_states_.find(id); | 373 auto it = component_states_.find(id); |
374 DCHECK(it != component_states_.end()); | 374 DCHECK(it != component_states_.end()); |
375 it->second = update_item; | 375 it->second = update_item; |
376 | 376 |
377 // Update the component registration with the new version. | 377 // Update the component registration with the new version. |
378 if (event == Observer::Events::COMPONENT_UPDATED) { | 378 if (event == Observer::Events::COMPONENT_UPDATED) { |
379 auto component(const_cast<CrxComponent*>(GetComponent(id))); | 379 auto* component(const_cast<CrxComponent*>(GetComponent(id))); |
380 if (component) { | 380 if (component) { |
381 component->version = update_item.next_version; | 381 component->version = update_item.next_version; |
382 component->fingerprint = update_item.next_fp; | 382 component->fingerprint = update_item.next_fp; |
383 } | 383 } |
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 /////////////////////////////////////////////////////////////////////////////// | 387 /////////////////////////////////////////////////////////////////////////////// |
388 | 388 |
389 // The component update factory. Using the component updater as a singleton | 389 // The component update factory. Using the component updater as a singleton |
390 // is the job of the browser process. | 390 // is the job of the browser process. |
391 // TODO(sorin): consider making this a singleton. | 391 // TODO(sorin): consider making this a singleton. |
392 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( | 392 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( |
393 const scoped_refptr<Configurator>& config) { | 393 const scoped_refptr<Configurator>& config) { |
394 DCHECK(config); | 394 DCHECK(config); |
395 auto update_client = update_client::UpdateClientFactory(config); | 395 auto update_client = update_client::UpdateClientFactory(config); |
396 return base::WrapUnique( | 396 return base::WrapUnique( |
397 new CrxUpdateService(config, std::move(update_client))); | 397 new CrxUpdateService(config, std::move(update_client))); |
398 } | 398 } |
399 | 399 |
400 } // namespace component_updater | 400 } // namespace component_updater |
OLD | NEW |