Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / update_client / action_wait.cc
blob1e8f8059c5c59202db49bd7d5e95f504126152b2
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.
5 #include "components/update_client/action_wait.h"
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/thread_task_runner_handle.h"
12 #include "components/update_client/update_engine.h"
14 namespace update_client {
16 ActionWait::ActionWait(const base::TimeDelta& time_delta)
17 : time_delta_(time_delta) {
20 ActionWait::~ActionWait() {
21 DCHECK(thread_checker_.CalledOnValidThread());
24 void ActionWait::Run(UpdateContext* update_context, Callback callback) {
25 DCHECK(thread_checker_.CalledOnValidThread());
26 DCHECK(update_context);
28 ActionImpl::Run(update_context, callback);
30 const bool result = base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
31 FROM_HERE, base::Bind(&ActionWait::WaitComplete, base::Unretained(this)),
32 time_delta_);
34 if (!result) {
35 // Move all items pending updates to the |kNoUpdate| state then return the
36 // control flow to the update engine, as the updates in this context are
37 // completed with an error.
38 while (!update_context->queue.empty()) {
39 const auto item = FindUpdateItemById(update_context->queue.front());
40 if (!item) {
41 item->error_category = static_cast<int>(ErrorCategory::kServiceError);
42 item->error_code = static_cast<int>(ServiceError::ERROR_WAIT);
43 ChangeItemState(item, CrxUpdateItem::State::kNoUpdate);
44 } else {
45 NOTREACHED();
47 update_context->queue.pop();
49 callback.Run(static_cast<int>(ServiceError::ERROR_WAIT));
52 NotifyObservers(UpdateClient::Observer::Events::COMPONENT_WAIT,
53 update_context_->queue.front());
56 void ActionWait::WaitComplete() {
57 DCHECK(thread_checker_.CalledOnValidThread());
58 UpdateCrx();
61 } // namespace update_client