[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 5 | #include "components/component_updater/component_updater_service.h" |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 8 | #include <map> |
| 9 | #include <string> |
| 10 | #include <utility> |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | 44da56e | 2011-11-21 19:59:14 | [diff] [blame] | 13 | #include "base/bind.h" |
sorin | 395c2ac | 2014-09-16 21:31:07 | [diff] [blame] | 14 | #include "base/bind_helpers.h" |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 15 | #include "base/callback.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | 819adcc8 | 2014-09-10 22:24:53 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 18 | #include "base/logging.h" |
sorin | 5cb1f549 | 2014-09-23 04:07:44 | [diff] [blame] | 19 | #include "base/macros.h" |
[email protected] | 7226b33c | 2011-08-18 08:44:22 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 21 | #include "base/metrics/histogram_macros.h" |
[email protected] | f5d27e3 | 2014-01-31 06:48:53 | [diff] [blame] | 22 | #include "base/sequenced_task_runner.h" |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 23 | #include "base/single_thread_task_runner.h" |
| 24 | #include "base/thread_task_runner_handle.h" |
[email protected] | 8f5f2ea | 2013-10-31 09:39:10 | [diff] [blame] | 25 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 26 | #include "base/threading/thread_checker.h" |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 27 | #include "base/time/time.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 28 | #include "base/timer/timer.h" |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 29 | #include "components/component_updater/component_updater_service_internal.h" |
| 30 | #include "components/component_updater/timer.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 31 | #include "components/update_client/configurator.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 32 | #include "components/update_client/crx_update_item.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 33 | #include "components/update_client/update_client.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 34 | #include "components/update_client/utils.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 35 | #include "url/gurl.h" |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 36 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 37 | using CrxInstaller = update_client::CrxInstaller; |
| 38 | using UpdateClient = update_client::UpdateClient; |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 39 | |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 40 | namespace { |
| 41 | |
| 42 | enum UpdateType { |
| 43 | UPDATE_TYPE_MANUAL = 0, |
| 44 | UPDATE_TYPE_AUTOMATIC, |
| 45 | UPDATE_TYPE_COUNT, |
| 46 | }; |
| 47 | |
| 48 | } // namespace |
| 49 | |
[email protected] | 055981f | 2014-01-17 20:22:32 | [diff] [blame] | 50 | namespace component_updater { |
[email protected] | 3a0092d | 2013-12-18 03:04:35 | [diff] [blame] | 51 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 52 | CrxUpdateService::CrxUpdateService( |
| 53 | const scoped_refptr<Configurator>& config, |
| 54 | const scoped_refptr<UpdateClient>& update_client) |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 55 | : config_(config), |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 56 | update_client_(update_client), |
| 57 | blocking_task_runner_(config->GetSequencedTaskRunner()) { |
| 58 | AddObserver(this); |
[email protected] | 1ea21ad | 2013-09-02 04:20:39 | [diff] [blame] | 59 | } |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 60 | |
| 61 | CrxUpdateService::~CrxUpdateService() { |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 62 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 | |
| 64 | for (const auto item : ready_callbacks_) { |
| 65 | item.second.Run(); |
| 66 | } |
| 67 | |
| 68 | RemoveObserver(this); |
| 69 | |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 70 | Stop(); |
[email protected] | 1ea21ad | 2013-09-02 04:20:39 | [diff] [blame] | 71 | } |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 72 | |
[email protected] | d3268fe | 2014-04-25 02:14:23 | [diff] [blame] | 73 | void CrxUpdateService::AddObserver(Observer* observer) { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 74 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 75 | update_client_->AddObserver(observer); |
[email protected] | d3268fe | 2014-04-25 02:14:23 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void CrxUpdateService::RemoveObserver(Observer* observer) { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 79 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 80 | update_client_->RemoveObserver(observer); |
[email protected] | d3268fe | 2014-04-25 02:14:23 | [diff] [blame] | 81 | } |
| 82 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 83 | void CrxUpdateService::Start() { |
| 84 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 85 | VLOG(1) << "CrxUpdateService starting up. " |
| 86 | << "First update attempt will take place in " |
| 87 | << config_->InitialDelay() << " seconds. " |
| 88 | << "Next update attempt will take place in " |
| 89 | << config_->NextCheckDelay() << " seconds. "; |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 90 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 91 | timer_.Start( |
| 92 | base::TimeDelta::FromSeconds(config_->InitialDelay()), |
| 93 | base::TimeDelta::FromSeconds(config_->NextCheckDelay()), |
| 94 | base::Bind(base::IgnoreResult(&CrxUpdateService::CheckForUpdates), |
| 95 | base::Unretained(this))); |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 96 | } |
| 97 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 98 | // Stops the update loop. In flight operations will be completed. |
| 99 | void CrxUpdateService::Stop() { |
| 100 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | fb53e65 | 2014-04-30 11:27:19 | [diff] [blame] | 101 | VLOG(1) << "CrxUpdateService stopping"; |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 102 | timer_.Stop(); |
sorin | ecaad3e | 2015-11-13 19:15:52 | [diff] [blame] | 103 | update_client_->Stop(); |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // Adds a component to be checked for upgrades. If the component exists it |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 107 | // it will be replaced. |
| 108 | bool CrxUpdateService::RegisterComponent(const CrxComponent& component) { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 109 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 110 | if (component.pk_hash.empty() || !component.version.IsValid() || |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 111 | !component.installer) { |
| 112 | return false; |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 113 | } |
| 114 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 115 | // Update the registration data if the component has been registered before. |
| 116 | const std::string id(GetCrxComponentID(component)); |
| 117 | auto it = components_.find(id); |
| 118 | if (it != components_.end()) { |
| 119 | it->second = component; |
| 120 | return true; |
[email protected] | 10bc022 | 2014-06-11 13:44:38 | [diff] [blame] | 121 | } |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 122 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 123 | components_.insert(std::make_pair(id, component)); |
| 124 | components_order_.push_back(id); |
| 125 | |
| 126 | // Create an initial state for this component. The state is mutated in |
| 127 | // response to events from the UpdateClient instance. |
| 128 | CrxUpdateItem item; |
| 129 | item.id = id; |
| 130 | item.component = component; |
| 131 | const auto inserted = component_states_.insert(std::make_pair(id, item)); |
| 132 | DCHECK(inserted.second); |
| 133 | |
| 134 | // Start the timer if this is the first component registered. The first timer |
| 135 | // event occurs after an interval defined by the component update |
| 136 | // configurator. The subsequent timer events are repeated with a period |
| 137 | // defined by the same configurator. |
| 138 | if (components_.size() == 1) |
| 139 | Start(); |
| 140 | |
| 141 | return true; |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 142 | } |
| 143 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 144 | bool CrxUpdateService::UnregisterComponent(const std::string& id) { |
| 145 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 146 | auto it = components_.find(id); |
| 147 | if (it == components_.end()) |
| 148 | return false; |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 149 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 150 | DCHECK_EQ(id, it->first); |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 151 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 152 | // Delay the uninstall of the component if the component is being updated. |
| 153 | if (update_client_->IsUpdating(id)) { |
| 154 | components_pending_unregistration_.push_back(id); |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | return DoUnregisterComponent(it->second); |
| 159 | } |
| 160 | |
| 161 | bool CrxUpdateService::DoUnregisterComponent(const CrxComponent& component) { |
| 162 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 163 | |
| 164 | const auto id = GetCrxComponentID(component); |
| 165 | DCHECK(ready_callbacks_.find(id) == ready_callbacks_.end()); |
| 166 | |
| 167 | const bool result = component.installer->Uninstall(); |
| 168 | |
| 169 | const auto pos = |
| 170 | std::find(components_order_.begin(), components_order_.end(), id); |
| 171 | if (pos != components_order_.end()) |
| 172 | components_order_.erase(pos); |
| 173 | |
| 174 | components_.erase(id); |
| 175 | component_states_.erase(id); |
| 176 | |
| 177 | return result; |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | 68bf09e | 2014-06-03 00:10:56 | [diff] [blame] | 180 | std::vector<std::string> CrxUpdateService::GetComponentIDs() const { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 181 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 182 | std::vector<std::string> ids; |
| 183 | for (const auto& it : components_) |
| 184 | ids.push_back(it.first); |
| 185 | return ids; |
[email protected] | 68bf09e | 2014-06-03 00:10:56 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 188 | OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 189 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 190 | return *this; |
| 191 | } |
| 192 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 193 | const CrxComponent* CrxUpdateService::GetComponent( |
| 194 | const std::string& id) const { |
| 195 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 196 | const auto it(components_.find(id)); |
| 197 | return it != components_.end() ? &(it->second) : NULL; |
| 198 | } |
| 199 | |
| 200 | const CrxUpdateItem* CrxUpdateService::GetComponentState( |
| 201 | const std::string& id) const { |
| 202 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 | const auto it(component_states_.find(id)); |
| 204 | return it != component_states_.end() ? &it->second : NULL; |
| 205 | } |
| 206 | |
| 207 | void CrxUpdateService::MaybeThrottle(const std::string& id, |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 208 | const base::Closure& callback) { |
| 209 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 210 | auto it = components_.find(id); |
| 211 | if (it != components_.end()) { |
| 212 | DCHECK_EQ(it->first, id); |
| 213 | if (OnDemandUpdateWithCooldown(id)) { |
| 214 | ready_callbacks_.insert(std::make_pair(id, callback)); |
| 215 | return; |
| 216 | } |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 217 | } |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 218 | |
| 219 | callback.Run(); // Unblock the request if the request can't be throttled. |
| 220 | } |
| 221 | |
| 222 | bool CrxUpdateService::OnDemandUpdate(const std::string& id) { |
| 223 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 | |
| 225 | if (!GetComponent(id)) |
| 226 | return false; |
| 227 | |
| 228 | return OnDemandUpdateInternal(id); |
| 229 | } |
| 230 | |
| 231 | bool CrxUpdateService::OnDemandUpdateWithCooldown(const std::string& id) { |
| 232 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 233 | |
| 234 | DCHECK(GetComponent(id)); |
| 235 | |
| 236 | // Check if the request is too soon. |
| 237 | const auto component_state(GetComponentState(id)); |
| 238 | if (component_state) { |
| 239 | base::TimeDelta delta = base::Time::Now() - component_state->last_check; |
| 240 | if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| 241 | return false; |
| 242 | } |
| 243 | |
| 244 | return OnDemandUpdateInternal(id); |
| 245 | } |
| 246 | |
| 247 | bool CrxUpdateService::OnDemandUpdateInternal(const std::string& id) { |
| 248 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 249 | |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 250 | UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_MANUAL, |
| 251 | UPDATE_TYPE_COUNT); |
| 252 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 253 | update_client_->Install( |
| 254 | id, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 255 | base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
| 256 | base::TimeTicks::Now())); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 257 | |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | bool CrxUpdateService::CheckForUpdates() { |
| 262 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 263 | |
| 264 | UMA_HISTOGRAM_ENUMERATION("ComponentUpdater.Calls", UPDATE_TYPE_AUTOMATIC, |
| 265 | UPDATE_TYPE_COUNT); |
| 266 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 267 | std::vector<std::string> ids; |
| 268 | for (const auto id : components_order_) { |
| 269 | DCHECK(components_.find(id) != components_.end()); |
| 270 | ids.push_back(id); |
| 271 | } |
| 272 | |
| 273 | update_client_->Update( |
| 274 | ids, base::Bind(&CrxUpdateService::OnUpdate, base::Unretained(this)), |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 275 | base::Bind(&CrxUpdateService::OnUpdateComplete, base::Unretained(this), |
| 276 | base::TimeTicks::Now())); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 277 | |
| 278 | return true; |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | scoped_refptr<base::SequencedTaskRunner> |
| 282 | CrxUpdateService::GetSequencedTaskRunner() { |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 283 | DCHECK(thread_checker_.CalledOnValidThread()); |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 284 | return blocking_task_runner_; |
[email protected] | 78efe2e9 | 2014-08-08 15:53:22 | [diff] [blame] | 285 | } |
| 286 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 287 | bool CrxUpdateService::GetComponentDetails(const std::string& id, |
[email protected] | f392e37 | 2014-06-12 07:25:57 | [diff] [blame] | 288 | CrxUpdateItem* item) const { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 289 | DCHECK(thread_checker_.CalledOnValidThread()); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 290 | |
| 291 | // First, if this component is currently being updated, return its state from |
| 292 | // the update client. |
| 293 | if (update_client_->GetCrxUpdateState(id, item)) |
| 294 | return true; |
| 295 | |
| 296 | // Otherwise, return the last seen state of the component, if such a |
| 297 | // state exists. |
| 298 | const auto component_states_it = component_states_.find(id); |
| 299 | if (component_states_it != component_states_.end()) { |
| 300 | *item = component_states_it->second; |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | return false; |
[email protected] | 2e919ddd | 2013-08-21 05:05:17 | [diff] [blame] | 305 | } |
| 306 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 307 | void CrxUpdateService::OnUpdate(const std::vector<std::string>& ids, |
| 308 | std::vector<CrxComponent>* components) { |
| 309 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 310 | DCHECK(components->empty()); |
| 311 | |
| 312 | for (const auto& id : ids) { |
| 313 | const auto registered_component(GetComponent(id)); |
| 314 | if (registered_component) { |
| 315 | components->push_back(*registered_component); |
| 316 | } |
| 317 | } |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 318 | } |
| 319 | |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 320 | void CrxUpdateService::OnUpdateComplete(const base::TimeTicks& start_time, |
| 321 | int error) { |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 322 | DCHECK(thread_checker_.CalledOnValidThread()); |
| 323 | VLOG(1) << "Update completed with error " << error; |
| 324 | |
sorin | 85953dc | 2016-03-10 00:32:48 | [diff] [blame^] | 325 | UMA_HISTOGRAM_BOOLEAN("ComponentUpdater.UpdateCompleteResult", error != 0); |
| 326 | UMA_HISTOGRAM_LONG_TIMES_100("ComponentUpdater.UpdateCompleteTime", |
| 327 | base::TimeTicks::Now() - start_time); |
| 328 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 329 | for (const auto id : components_pending_unregistration_) { |
| 330 | if (!update_client_->IsUpdating(id)) { |
| 331 | const auto component = GetComponent(id); |
| 332 | if (component) |
| 333 | DoUnregisterComponent(*component); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void CrxUpdateService::OnEvent(Events event, const std::string& id) { |
[email protected] | ed6fb98 | 2014-07-23 16:56:52 | [diff] [blame] | 339 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 93e8e2c | 2014-01-04 12:29:23 | [diff] [blame] | 340 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 341 | // Unblock all throttles for the component. |
| 342 | if (event == Observer::Events::COMPONENT_UPDATED || |
| 343 | event == Observer::Events::COMPONENT_NOT_UPDATED) { |
| 344 | auto callbacks = ready_callbacks_.equal_range(id); |
| 345 | for (auto it = callbacks.first; it != callbacks.second; ++it) { |
| 346 | it->second.Run(); |
| 347 | } |
| 348 | ready_callbacks_.erase(id); |
| 349 | } |
| 350 | |
| 351 | CrxUpdateItem update_item; |
| 352 | if (!update_client_->GetCrxUpdateState(id, &update_item)) |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 353 | return; |
[email protected] | 93e8e2c | 2014-01-04 12:29:23 | [diff] [blame] | 354 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 355 | // Update the state of the item. |
| 356 | auto it = component_states_.find(id); |
| 357 | DCHECK(it != component_states_.end()); |
| 358 | it->second = update_item; |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 359 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 360 | // Update the component registration with the new version. |
| 361 | if (event == Observer::Events::COMPONENT_UPDATED) { |
| 362 | auto component(const_cast<CrxComponent*>(GetComponent(id))); |
| 363 | if (component) { |
| 364 | component->version = update_item.next_version; |
| 365 | component->fingerprint = update_item.next_fp; |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 366 | } |
| 367 | } |
[email protected] | 68bf09e | 2014-06-03 00:10:56 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | 00a77fa | 2013-11-02 04:18:46 | [diff] [blame] | 370 | /////////////////////////////////////////////////////////////////////////////// |
| 371 | |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 372 | // The component update factory. Using the component updater as a singleton |
| 373 | // is the job of the browser process. |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 374 | // TODO(sorin): consider making this a singleton. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 375 | scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( |
| 376 | const scoped_refptr<Configurator>& config) { |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 377 | DCHECK(config); |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 378 | auto update_client = update_client::UpdateClientFactory(config); |
| 379 | return scoped_ptr<ComponentUpdateService>( |
danakj | 4b041ab | 2015-12-04 20:12:27 | [diff] [blame] | 380 | new CrxUpdateService(config, std::move(update_client))); |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 381 | } |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 382 | |
[email protected] | 055981f | 2014-01-17 20:22:32 | [diff] [blame] | 383 | } // namespace component_updater |