Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / updater / extension_updater.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/updater/extension_updater.h"
6
7 #include <algorithm>
8 #include <set>
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/rand_util.h"
16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_split.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/extensions/api/module/module.h"
21 #include "chrome/browser/extensions/crx_installer.h"
22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/updater/extension_downloader.h"
24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/pref_names.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h"
30 #include "crypto/sha2.h"
31 #include "extensions/browser/pending_extension_manager.h"
32 #include "extensions/browser/pref_names.h"
33 #include "extensions/common/constants.h"
34 #include "extensions/common/extension.h"
35 #include "extensions/common/extension_set.h"
36 #include "extensions/common/manifest.h"
37
38 using base::RandDouble;
39 using base::RandInt;
40 using base::Time;
41 using base::TimeDelta;
42 using content::BrowserThread;
43
44 typedef extensions::ExtensionDownloaderDelegate::Error Error;
45 typedef extensions::ExtensionDownloaderDelegate::PingResult PingResult;
46
47 namespace {
48
49 // Wait at least 5 minutes after browser startup before we do any checks. If you
50 // change this value, make sure to update comments where it is used.
51 const int kStartupWaitSeconds = 60 * 5;
52
53 // For sanity checking on update frequency - enforced in release mode only.
54 #ifdef NDEBUG
55 const int kMinUpdateFrequencySeconds = 30;
56 #endif
57 const int kMaxUpdateFrequencySeconds = 60 * 60 * 24 * 7;  // 7 days
58
59 // Require at least 5 seconds between consecutive non-succesful extension update
60 // checks.
61 const int kMinUpdateThrottleTime = 5;
62
63 // When we've computed a days value, we want to make sure we don't send a
64 // negative value (due to the system clock being set backwards, etc.), since -1
65 // is a special sentinel value that means "never pinged", and other negative
66 // values don't make sense.
67 int SanitizeDays(int days) {
68   if (days < 0)
69     return 0;
70   return days;
71 }
72
73 // Calculates the value to use for the ping days parameter.
74 int CalculatePingDays(const Time& last_ping_day) {
75   int days = extensions::ManifestFetchData::kNeverPinged;
76   if (!last_ping_day.is_null()) {
77     days = SanitizeDays((Time::Now() - last_ping_day).InDays());
78   }
79   return days;
80 }
81
82 int CalculateActivePingDays(const Time& last_active_ping_day,
83                             bool hasActiveBit) {
84   if (!hasActiveBit)
85     return 0;
86   if (last_active_ping_day.is_null())
87     return extensions::ManifestFetchData::kNeverPinged;
88   return SanitizeDays((Time::Now() - last_active_ping_day).InDays());
89 }
90
91 }  // namespace
92
93 namespace extensions {
94
95 ExtensionUpdater::CheckParams::CheckParams()
96     : install_immediately(false) {}
97
98 ExtensionUpdater::CheckParams::~CheckParams() {}
99
100 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile(
101     const std::string& i,
102     const base::FilePath& p,
103     bool file_ownership_passed,
104     const GURL& u,
105     const std::set<int>& request_ids)
106     : extension_id(i),
107       path(p),
108       file_ownership_passed(file_ownership_passed),
109       download_url(u),
110       request_ids(request_ids) {}
111
112 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile()
113     : path(), file_ownership_passed(true), download_url() {}
114
115 ExtensionUpdater::FetchedCRXFile::~FetchedCRXFile() {}
116
117 ExtensionUpdater::InProgressCheck::InProgressCheck()
118     : install_immediately(false) {}
119
120 ExtensionUpdater::InProgressCheck::~InProgressCheck() {}
121
122 struct ExtensionUpdater::ThrottleInfo {
123   ThrottleInfo()
124       : in_progress(true),
125         throttle_delay(kMinUpdateThrottleTime),
126         check_start(Time::Now()) {}
127
128   bool in_progress;
129   int throttle_delay;
130   Time check_start;
131 };
132
133 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service,
134                                    ExtensionPrefs* extension_prefs,
135                                    PrefService* prefs,
136                                    Profile* profile,
137                                    int frequency_seconds,
138                                    ExtensionCache* cache)
139     : alive_(false),
140       weak_ptr_factory_(this),
141       service_(service), frequency_seconds_(frequency_seconds),
142       will_check_soon_(false), extension_prefs_(extension_prefs),
143       prefs_(prefs), profile_(profile),
144       next_request_id_(0),
145       crx_install_is_running_(false),
146       extension_cache_(cache) {
147   DCHECK_GE(frequency_seconds_, 5);
148   DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds);
149 #ifdef NDEBUG
150   // In Release mode we enforce that update checks don't happen too often.
151   frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds);
152 #endif
153   frequency_seconds_ = std::min(frequency_seconds_, kMaxUpdateFrequencySeconds);
154
155   registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
156                  content::NotificationService::AllBrowserContextsAndSources());
157 }
158
159 ExtensionUpdater::~ExtensionUpdater() {
160   Stop();
161 }
162
163 // The overall goal here is to balance keeping clients up to date while
164 // avoiding a thundering herd against update servers.
165 TimeDelta ExtensionUpdater::DetermineFirstCheckDelay() {
166   DCHECK(alive_);
167   // If someone's testing with a quick frequency, just allow it.
168   if (frequency_seconds_ < kStartupWaitSeconds)
169     return TimeDelta::FromSeconds(frequency_seconds_);
170
171   // If we've never scheduled a check before, start at frequency_seconds_.
172   if (!prefs_->HasPrefPath(pref_names::kNextUpdateCheck))
173     return TimeDelta::FromSeconds(frequency_seconds_);
174
175   // If it's been a long time since our last actual check, we want to do one
176   // relatively soon.
177   Time now = Time::Now();
178   Time last = Time::FromInternalValue(prefs_->GetInt64(
179       pref_names::kLastUpdateCheck));
180   int days = (now - last).InDays();
181   if (days >= 30) {
182     // Wait 5-10 minutes.
183     return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds,
184                                           kStartupWaitSeconds * 2));
185   } else if (days >= 14) {
186     // Wait 10-20 minutes.
187     return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds * 2,
188                                           kStartupWaitSeconds * 4));
189   } else if (days >= 3) {
190     // Wait 20-40 minutes.
191     return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds * 4,
192                                           kStartupWaitSeconds * 8));
193   }
194
195   // Read the persisted next check time, and use that if it isn't too soon.
196   // Otherwise pick something random.
197   Time saved_next = Time::FromInternalValue(prefs_->GetInt64(
198       pref_names::kNextUpdateCheck));
199   Time earliest = now + TimeDelta::FromSeconds(kStartupWaitSeconds);
200   if (saved_next >= earliest) {
201     return saved_next - now;
202   } else {
203     return TimeDelta::FromSeconds(RandInt(kStartupWaitSeconds,
204                                           frequency_seconds_));
205   }
206 }
207
208 void ExtensionUpdater::Start() {
209   DCHECK(!alive_);
210   // If these are NULL, then that means we've been called after Stop()
211   // has been called.
212   DCHECK(service_);
213   DCHECK(extension_prefs_);
214   DCHECK(prefs_);
215   DCHECK(profile_);
216   DCHECK(!weak_ptr_factory_.HasWeakPtrs());
217   alive_ = true;
218   // Make sure our prefs are registered, then schedule the first check.
219   ScheduleNextCheck(DetermineFirstCheckDelay());
220 }
221
222 void ExtensionUpdater::Stop() {
223   weak_ptr_factory_.InvalidateWeakPtrs();
224   alive_ = false;
225   service_ = NULL;
226   extension_prefs_ = NULL;
227   prefs_ = NULL;
228   profile_ = NULL;
229   timer_.Stop();
230   will_check_soon_ = false;
231   downloader_.reset();
232 }
233
234 void ExtensionUpdater::ScheduleNextCheck(const TimeDelta& target_delay) {
235   DCHECK(alive_);
236   DCHECK(!timer_.IsRunning());
237   DCHECK(target_delay >= TimeDelta::FromSeconds(1));
238
239   // Add +/- 10% random jitter.
240   double delay_ms = target_delay.InMillisecondsF();
241   double jitter_factor = (RandDouble() * .2) - 0.1;
242   delay_ms += delay_ms * jitter_factor;
243   TimeDelta actual_delay = TimeDelta::FromMilliseconds(
244       static_cast<int64>(delay_ms));
245
246   // Save the time of next check.
247   Time next = Time::Now() + actual_delay;
248   prefs_->SetInt64(pref_names::kNextUpdateCheck, next.ToInternalValue());
249
250   timer_.Start(FROM_HERE, actual_delay, this, &ExtensionUpdater::TimerFired);
251 }
252
253 void ExtensionUpdater::TimerFired() {
254   DCHECK(alive_);
255   CheckNow(default_params_);
256
257   // If the user has overridden the update frequency, don't bother reporting
258   // this.
259   if (frequency_seconds_ == extensions::kDefaultUpdateFrequencySeconds) {
260     Time last = Time::FromInternalValue(prefs_->GetInt64(
261         pref_names::kLastUpdateCheck));
262     if (last.ToInternalValue() != 0) {
263       // Use counts rather than time so we can use minutes rather than millis.
264       UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.UpdateCheckGap",
265           (Time::Now() - last).InMinutes(),
266           TimeDelta::FromSeconds(kStartupWaitSeconds).InMinutes(),
267           TimeDelta::FromDays(40).InMinutes(),
268           50);  // 50 buckets seems to be the default.
269     }
270   }
271
272   // Save the last check time, and schedule the next check.
273   int64 now = Time::Now().ToInternalValue();
274   prefs_->SetInt64(pref_names::kLastUpdateCheck, now);
275   ScheduleNextCheck(TimeDelta::FromSeconds(frequency_seconds_));
276 }
277
278 void ExtensionUpdater::CheckSoon() {
279   DCHECK(alive_);
280   if (will_check_soon_)
281     return;
282   if (BrowserThread::PostTask(
283           BrowserThread::UI, FROM_HERE,
284           base::Bind(&ExtensionUpdater::DoCheckSoon,
285                      weak_ptr_factory_.GetWeakPtr()))) {
286     will_check_soon_ = true;
287   } else {
288     NOTREACHED();
289   }
290 }
291
292 bool ExtensionUpdater::WillCheckSoon() const {
293   return will_check_soon_;
294 }
295
296 void ExtensionUpdater::DoCheckSoon() {
297   DCHECK(will_check_soon_);
298   CheckNow(default_params_);
299   will_check_soon_ = false;
300 }
301
302 void ExtensionUpdater::AddToDownloader(
303     const ExtensionSet* extensions,
304     const std::list<std::string>& pending_ids,
305     int request_id) {
306   InProgressCheck& request = requests_in_progress_[request_id];
307   for (ExtensionSet::const_iterator extension_iter = extensions->begin();
308        extension_iter != extensions->end(); ++extension_iter) {
309     const Extension& extension = *extension_iter->get();
310     if (!Manifest::IsAutoUpdateableLocation(extension.location())) {
311       VLOG(2) << "Extension " << extension.id() << " is not auto updateable";
312       continue;
313     }
314     // An extension might be overwritten by policy, and have its update url
315     // changed. Make sure existing extensions aren't fetched again, if a
316     // pending fetch for an extension with the same id already exists.
317     std::list<std::string>::const_iterator pending_id_iter = std::find(
318         pending_ids.begin(), pending_ids.end(), extension.id());
319     if (pending_id_iter == pending_ids.end()) {
320       if (downloader_->AddExtension(extension, request_id))
321         request.in_progress_ids_.push_back(extension.id());
322     }
323   }
324 }
325
326 void ExtensionUpdater::CheckNow(const CheckParams& params) {
327   int request_id = next_request_id_++;
328
329   VLOG(2) << "Starting update check " << request_id;
330   if (params.ids.empty())
331     NotifyStarted();
332
333   DCHECK(alive_);
334
335   InProgressCheck& request = requests_in_progress_[request_id];
336   request.callback = params.callback;
337   request.install_immediately = params.install_immediately;
338
339   if (!downloader_.get()) {
340     downloader_.reset(
341         new ExtensionDownloader(this, profile_->GetRequestContext()));
342   }
343
344   // Add fetch records for extensions that should be fetched by an update URL.
345   // These extensions are not yet installed. They come from group policy
346   // and external install sources.
347   const PendingExtensionManager* pending_extension_manager =
348       service_->pending_extension_manager();
349
350   std::list<std::string> pending_ids;
351
352   if (params.ids.empty()) {
353     // If no extension ids are specified, check for updates for all extensions.
354     pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids);
355
356     std::list<std::string>::const_iterator iter;
357     for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) {
358       const PendingExtensionInfo* info = pending_extension_manager->GetById(
359           *iter);
360       if (!Manifest::IsAutoUpdateableLocation(info->install_source())) {
361         VLOG(2) << "Extension " << *iter << " is not auto updateable";
362         continue;
363       }
364       if (downloader_->AddPendingExtension(*iter, info->update_url(),
365                                            request_id))
366         request.in_progress_ids_.push_back(*iter);
367     }
368
369     AddToDownloader(service_->extensions(), pending_ids, request_id);
370     AddToDownloader(service_->disabled_extensions(), pending_ids, request_id);
371   } else {
372     for (std::list<std::string>::const_iterator it = params.ids.begin();
373          it != params.ids.end(); ++it) {
374       const Extension* extension = service_->GetExtensionById(*it, true);
375       DCHECK(extension);
376       if (downloader_->AddExtension(*extension, request_id))
377         request.in_progress_ids_.push_back(extension->id());
378     }
379   }
380
381   // StartAllPending() might call OnExtensionDownloadFailed/Finished before
382   // it returns, which would cause NotifyIfFinished to incorrectly try to
383   // send out a notification. So check before we call StartAllPending if any
384   // extensions are going to be updated, and use that to figure out if
385   // NotifyIfFinished should be called.
386   bool noChecks = request.in_progress_ids_.empty();
387
388   // StartAllPending() will call OnExtensionDownloadFailed or
389   // OnExtensionDownloadFinished for each extension that was checked.
390   downloader_->StartAllPending(extension_cache_);
391
392   if (noChecks)
393     NotifyIfFinished(request_id);
394 }
395
396 bool ExtensionUpdater::CheckExtensionSoon(const std::string& extension_id,
397                                           const FinishedCallback& callback) {
398   bool have_throttle_info = ContainsKey(throttle_info_, extension_id);
399   ThrottleInfo& info = throttle_info_[extension_id];
400   if (have_throttle_info) {
401     // We already had a ThrottleInfo object for this extension, check if the
402     // update check request should be allowed.
403
404     // If another check is in progress, don't start a new check.
405     if (info.in_progress)
406       return false;
407
408     Time now = Time::Now();
409     Time last = info.check_start;
410     // If somehow time moved back, we don't want to infinitely keep throttling.
411     if (now < last) {
412       last = now;
413       info.check_start = now;
414     }
415     Time earliest = last + TimeDelta::FromSeconds(info.throttle_delay);
416     // If check is too soon, throttle.
417     if (now < earliest)
418       return false;
419
420     // TODO(mek): Somehow increase time between allowing checks when checks
421     // are repeatedly throttled and don't result in updates being installed.
422
423     // It's okay to start a check, update values.
424     info.check_start = now;
425     info.in_progress = true;
426   }
427
428   CheckParams params;
429   params.ids.push_back(extension_id);
430   params.callback = base::Bind(&ExtensionUpdater::ExtensionCheckFinished,
431                                weak_ptr_factory_.GetWeakPtr(),
432                                extension_id, callback);
433   CheckNow(params);
434   return true;
435 }
436
437 void ExtensionUpdater::ExtensionCheckFinished(
438     const std::string& extension_id,
439     const FinishedCallback& callback) {
440   std::map<std::string, ThrottleInfo>::iterator it =
441       throttle_info_.find(extension_id);
442   if (it != throttle_info_.end()) {
443     it->second.in_progress = false;
444   }
445   callback.Run();
446 }
447
448 void ExtensionUpdater::OnExtensionDownloadFailed(
449     const std::string& id,
450     Error error,
451     const PingResult& ping,
452     const std::set<int>& request_ids) {
453   DCHECK(alive_);
454   UpdatePingData(id, ping);
455   bool install_immediately = false;
456   for (std::set<int>::const_iterator it = request_ids.begin();
457        it != request_ids.end(); ++it) {
458     InProgressCheck& request = requests_in_progress_[*it];
459     install_immediately |= request.install_immediately;
460     request.in_progress_ids_.remove(id);
461     NotifyIfFinished(*it);
462   }
463
464   // This method is called if no updates were found. However a previous update
465   // check might have queued an update for this extension already. If a
466   // current update check has |install_immediately| set the previously
467   // queued update should be installed now.
468   if (install_immediately && service_->GetPendingExtensionUpdate(id))
469     service_->FinishDelayedInstallation(id);
470 }
471
472 void ExtensionUpdater::OnExtensionDownloadFinished(
473     const std::string& id,
474     const base::FilePath& path,
475     bool file_ownership_passed,
476     const GURL& download_url,
477     const std::string& version,
478     const PingResult& ping,
479     const std::set<int>& request_ids) {
480   DCHECK(alive_);
481   UpdatePingData(id, ping);
482
483   VLOG(2) << download_url << " written to " << path.value();
484
485   FetchedCRXFile fetched(id, path, file_ownership_passed, download_url,
486                          request_ids);
487   fetched_crx_files_.push(fetched);
488
489   // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after
490   // starting the crx installer.
491   MaybeInstallCRXFile();
492 }
493
494 bool ExtensionUpdater::GetPingDataForExtension(
495     const std::string& id,
496     ManifestFetchData::PingData* ping_data) {
497   DCHECK(alive_);
498   ping_data->rollcall_days = CalculatePingDays(
499       extension_prefs_->LastPingDay(id));
500   ping_data->is_enabled = service_->IsExtensionEnabled(id);
501   ping_data->active_days =
502       CalculateActivePingDays(extension_prefs_->LastActivePingDay(id),
503                               extension_prefs_->GetActiveBit(id));
504   return true;
505 }
506
507 std::string ExtensionUpdater::GetUpdateUrlData(const std::string& id) {
508   DCHECK(alive_);
509   return extension::GetUpdateURLData(extension_prefs_, id);
510 }
511
512 bool ExtensionUpdater::IsExtensionPending(const std::string& id) {
513   DCHECK(alive_);
514   return service_->pending_extension_manager()->IsIdPending(id);
515 }
516
517 bool ExtensionUpdater::GetExtensionExistingVersion(const std::string& id,
518                                                    std::string* version) {
519   DCHECK(alive_);
520   const Extension* extension = service_->GetExtensionById(id, true);
521   if (!extension)
522     return false;
523   const Extension* update = service_->GetPendingExtensionUpdate(id);
524   if (update)
525     *version = update->VersionString();
526   else
527     *version = extension->VersionString();
528   return true;
529 }
530
531 void ExtensionUpdater::UpdatePingData(const std::string& id,
532                                       const PingResult& ping_result) {
533   DCHECK(alive_);
534   if (ping_result.did_ping)
535     extension_prefs_->SetLastPingDay(id, ping_result.day_start);
536   if (extension_prefs_->GetActiveBit(id)) {
537     extension_prefs_->SetActiveBit(id, false);
538     extension_prefs_->SetLastActivePingDay(id, ping_result.day_start);
539   }
540 }
541
542 void ExtensionUpdater::MaybeInstallCRXFile() {
543   if (crx_install_is_running_ || fetched_crx_files_.empty())
544     return;
545
546   std::set<int> request_ids;
547
548   while (!fetched_crx_files_.empty() && !crx_install_is_running_) {
549     const FetchedCRXFile& crx_file = fetched_crx_files_.top();
550
551     VLOG(2) << "updating " << crx_file.extension_id
552             << " with " << crx_file.path.value();
553
554     // The ExtensionService is now responsible for cleaning up the temp file
555     // at |crx_file.path|.
556     CrxInstaller* installer = NULL;
557     if (service_->UpdateExtension(crx_file.extension_id,
558                                   crx_file.path,
559                                   crx_file.file_ownership_passed,
560                                   crx_file.download_url,
561                                   &installer)) {
562       crx_install_is_running_ = true;
563       current_crx_file_ = crx_file;
564
565       for (std::set<int>::const_iterator it = crx_file.request_ids.begin();
566           it != crx_file.request_ids.end(); ++it) {
567         InProgressCheck& request = requests_in_progress_[*it];
568         if (request.install_immediately) {
569           installer->set_install_wait_for_idle(false);
570           break;
571         }
572       }
573
574       // Source parameter ensures that we only see the completion event for the
575       // the installer we started.
576       registrar_.Add(this,
577                      chrome::NOTIFICATION_CRX_INSTALLER_DONE,
578                      content::Source<CrxInstaller>(installer));
579     } else {
580       for (std::set<int>::const_iterator it = crx_file.request_ids.begin();
581            it != crx_file.request_ids.end(); ++it) {
582         InProgressCheck& request = requests_in_progress_[*it];
583         request.in_progress_ids_.remove(crx_file.extension_id);
584       }
585       request_ids.insert(crx_file.request_ids.begin(),
586                          crx_file.request_ids.end());
587     }
588     fetched_crx_files_.pop();
589   }
590
591   for (std::set<int>::const_iterator it = request_ids.begin();
592        it != request_ids.end(); ++it) {
593     NotifyIfFinished(*it);
594   }
595 }
596
597 void ExtensionUpdater::Observe(int type,
598                                const content::NotificationSource& source,
599                                const content::NotificationDetails& details) {
600   switch (type) {
601     case chrome::NOTIFICATION_CRX_INSTALLER_DONE: {
602       // No need to listen for CRX_INSTALLER_DONE anymore.
603       registrar_.Remove(this,
604                         chrome::NOTIFICATION_CRX_INSTALLER_DONE,
605                         source);
606       crx_install_is_running_ = false;
607
608       const FetchedCRXFile& crx_file = current_crx_file_;
609       for (std::set<int>::const_iterator it = crx_file.request_ids.begin();
610           it != crx_file.request_ids.end(); ++it) {
611         InProgressCheck& request = requests_in_progress_[*it];
612         request.in_progress_ids_.remove(crx_file.extension_id);
613         NotifyIfFinished(*it);
614       }
615
616       // If any files are available to update, start one.
617       MaybeInstallCRXFile();
618       break;
619     }
620     case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
621       const Extension* extension =
622           content::Details<const InstalledExtensionInfo>(details)->extension;
623       if (extension)
624         throttle_info_.erase(extension->id());
625       break;
626     }
627     default:
628       NOTREACHED();
629   }
630 }
631
632 void ExtensionUpdater::NotifyStarted() {
633   content::NotificationService::current()->Notify(
634       chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED,
635       content::Source<Profile>(profile_),
636       content::NotificationService::NoDetails());
637 }
638
639 void ExtensionUpdater::NotifyIfFinished(int request_id) {
640   DCHECK(ContainsKey(requests_in_progress_, request_id));
641   const InProgressCheck& request = requests_in_progress_[request_id];
642   if (request.in_progress_ids_.empty()) {
643     VLOG(2) << "Finished update check " << request_id;
644     if (!request.callback.is_null())
645       request.callback.Run();
646     requests_in_progress_.erase(request_id);
647   }
648 }
649
650 }  // namespace extensions