| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/update_client/update_engine.h" | 5 #include "components/update_client/update_engine.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "components/prefs/pref_service.h" |
| 13 #include "components/update_client/action_update_check.h" | 14 #include "components/update_client/action_update_check.h" |
| 14 #include "components/update_client/configurator.h" | 15 #include "components/update_client/configurator.h" |
| 15 #include "components/update_client/crx_update_item.h" | 16 #include "components/update_client/crx_update_item.h" |
| 17 #include "components/update_client/persisted_data.h" |
| 16 #include "components/update_client/update_checker.h" | 18 #include "components/update_client/update_checker.h" |
| 17 | 19 |
| 18 namespace update_client { | 20 namespace update_client { |
| 19 | 21 |
| 20 UpdateContext::UpdateContext( | 22 UpdateContext::UpdateContext( |
| 21 const scoped_refptr<Configurator>& config, | 23 const scoped_refptr<Configurator>& config, |
| 22 bool is_foreground, | 24 bool is_foreground, |
| 23 const std::vector<std::string>& ids, | 25 const std::vector<std::string>& ids, |
| 24 const UpdateClient::CrxDataCallback& crx_data_callback, | 26 const UpdateClient::CrxDataCallback& crx_data_callback, |
| 25 const UpdateEngine::NotifyObserversCallback& notify_observers_callback, | 27 const UpdateEngine::NotifyObserversCallback& notify_observers_callback, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 UpdateEngine::UpdateEngine( | 49 UpdateEngine::UpdateEngine( |
| 48 const scoped_refptr<Configurator>& config, | 50 const scoped_refptr<Configurator>& config, |
| 49 UpdateChecker::Factory update_checker_factory, | 51 UpdateChecker::Factory update_checker_factory, |
| 50 CrxDownloader::Factory crx_downloader_factory, | 52 CrxDownloader::Factory crx_downloader_factory, |
| 51 PingManager* ping_manager, | 53 PingManager* ping_manager, |
| 52 const NotifyObserversCallback& notify_observers_callback) | 54 const NotifyObserversCallback& notify_observers_callback) |
| 53 : config_(config), | 55 : config_(config), |
| 54 update_checker_factory_(update_checker_factory), | 56 update_checker_factory_(update_checker_factory), |
| 55 crx_downloader_factory_(crx_downloader_factory), | 57 crx_downloader_factory_(crx_downloader_factory), |
| 56 ping_manager_(ping_manager), | 58 ping_manager_(ping_manager), |
| 59 metadata_(new PersistedData(config->GetPrefService())), |
| 57 notify_observers_callback_(notify_observers_callback) { | 60 notify_observers_callback_(notify_observers_callback) { |
| 58 } | 61 } |
| 59 | 62 |
| 60 UpdateEngine::~UpdateEngine() { | 63 UpdateEngine::~UpdateEngine() { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 } | 65 } |
| 63 | 66 |
| 64 bool UpdateEngine::GetUpdateState(const std::string& id, | 67 bool UpdateEngine::GetUpdateState(const std::string& id, |
| 65 CrxUpdateItem* update_item) { | 68 CrxUpdateItem* update_item) { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); | 69 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 91 return; | 94 return; |
| 92 } | 95 } |
| 93 | 96 |
| 94 scoped_ptr<UpdateContext> update_context(new UpdateContext( | 97 scoped_ptr<UpdateContext> update_context(new UpdateContext( |
| 95 config_, is_foreground, ids, crx_data_callback, | 98 config_, is_foreground, ids, crx_data_callback, |
| 96 notify_observers_callback_, callback, update_checker_factory_, | 99 notify_observers_callback_, callback, update_checker_factory_, |
| 97 crx_downloader_factory_, ping_manager_)); | 100 crx_downloader_factory_, ping_manager_)); |
| 98 | 101 |
| 99 CrxUpdateItem update_item; | 102 CrxUpdateItem update_item; |
| 100 scoped_ptr<ActionUpdateCheck> update_check_action(new ActionUpdateCheck( | 103 scoped_ptr<ActionUpdateCheck> update_check_action(new ActionUpdateCheck( |
| 101 (*update_context->update_checker_factory)(config_), | 104 (*update_context->update_checker_factory)(config_, metadata_), |
| 102 config_->GetBrowserVersion(), config_->ExtraRequestParams())); | 105 config_->GetBrowserVersion(), config_->ExtraRequestParams())); |
| 103 | 106 |
| 104 update_context->current_action.reset(update_check_action.release()); | 107 update_context->current_action.reset(update_check_action.release()); |
| 105 update_contexts_.insert(update_context.get()); | 108 update_contexts_.insert(update_context.get()); |
| 106 | 109 |
| 107 update_context->current_action->Run( | 110 update_context->current_action->Run( |
| 108 update_context.get(), | 111 update_context.get(), |
| 109 base::Bind(&UpdateEngine::UpdateComplete, base::Unretained(this), | 112 base::Bind(&UpdateEngine::UpdateComplete, base::Unretained(this), |
| 110 update_context.get())); | 113 update_context.get())); |
| 111 | 114 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 142 | 145 |
| 143 const auto now(base::Time::Now()); | 146 const auto now(base::Time::Now()); |
| 144 | 147 |
| 145 // Throttle the calls in the interval (t - 1 day, t) to limit the effect of | 148 // Throttle the calls in the interval (t - 1 day, t) to limit the effect of |
| 146 // unset clocks or clock drift. | 149 // unset clocks or clock drift. |
| 147 return throttle_updates_until_ - base::TimeDelta::FromDays(1) < now && | 150 return throttle_updates_until_ - base::TimeDelta::FromDays(1) < now && |
| 148 now < throttle_updates_until_; | 151 now < throttle_updates_until_; |
| 149 } | 152 } |
| 150 | 153 |
| 151 } // namespace update_client | 154 } // namespace update_client |
| OLD | NEW |