| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/update_client/action_wait.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 #include "components/update_client/update_client_errors.h" | |
| 13 #include "components/update_client/update_engine.h" | |
| 14 | |
| 15 namespace update_client { | |
| 16 | |
| 17 ActionWait::ActionWait(const base::TimeDelta& time_delta) | |
| 18 : time_delta_(time_delta) { | |
| 19 } | |
| 20 | |
| 21 ActionWait::~ActionWait() { | |
| 22 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 23 } | |
| 24 | |
| 25 void ActionWait::Run(UpdateContext* update_context, Callback callback) { | |
| 26 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 27 DCHECK(update_context); | |
| 28 | |
| 29 ActionImpl::Run(update_context, callback); | |
| 30 | |
| 31 const bool result = base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 32 FROM_HERE, base::Bind(&ActionWait::WaitComplete, base::Unretained(this)), | |
| 33 time_delta_); | |
| 34 | |
| 35 if (!result) { | |
| 36 // Move all items pending updates to the |kNoUpdate| state then return the | |
| 37 // control flow to the update engine, as the updates in this context are | |
| 38 // completed with an error. | |
| 39 while (!update_context->queue.empty()) { | |
| 40 auto* item = FindUpdateItemById(update_context->queue.front()); | |
| 41 DCHECK(item); | |
| 42 item->error_category = static_cast<int>(ErrorCategory::kServiceError); | |
| 43 item->error_code = static_cast<int>(ServiceError::SERVICE_WAIT_FAILED); | |
| 44 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate); | |
| 45 update_context->queue.pop(); | |
| 46 } | |
| 47 callback.Run(Error::SERVICE_ERROR); | |
| 48 } | |
| 49 | |
| 50 NotifyObservers(UpdateClient::Observer::Events::COMPONENT_WAIT, | |
| 51 update_context_->queue.front()); | |
| 52 } | |
| 53 | |
| 54 void ActionWait::WaitComplete() { | |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 56 UpdateCrx(); | |
| 57 } | |
| 58 | |
| 59 } // namespace update_client | |
| OLD | NEW |