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 #ifndef COMPONENTS_UPDATE_CLIENT_ACTION_H_
6 #define COMPONENTS_UPDATE_CLIENT_ACTION_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/update_client/crx_update_item.h"
14 #include "components/update_client/update_client.h"
16 namespace update_client
{
22 // Any update can be broken down as a sequence of discrete steps, such as
23 // checking for updates, downloading patches, updating, and waiting between
24 // successive updates. An action is the smallest unit of work executed by
27 // Defines an abstract interface for a unit of work, executed by the
28 // update engine as part of an update.
31 enum class ErrorCategory
{
36 kServiceError
, // Runtime errors which occur in the service itself.
39 enum class ServiceError
{
43 using Callback
= base::Callback
<void(int error
)>;
46 // Runs the code encapsulated by the action. When an action completes, it can
47 // chain up and transfer the execution flow to another action or it can
48 // invoke the |callback| when this function has completed and there is nothing
50 virtual void Run(UpdateContext
* update_context
, Callback callback
) = 0;
53 // Provides a reusable implementation of common functions needed by actions.
59 void Run(UpdateContext
* update_context
, Action::Callback callback
);
61 // Changes the current state of the |item| to the new state |to|.
62 void ChangeItemState(CrxUpdateItem
* item
, CrxUpdateItem::State to
);
64 // Changes the state of all items in |update_context_|. Returns the count
65 // of items affected by the call.
66 size_t ChangeAllItemsState(CrxUpdateItem::State from
,
67 CrxUpdateItem::State to
);
69 // Returns the item associated with the component |id| or nullptr in case
71 CrxUpdateItem
* FindUpdateItemById(const std::string
& id
) const;
73 void NotifyObservers(UpdateClient::Observer::Events event
,
74 const std::string
& id
);
76 // Updates the CRX at the front of the CRX queue in this update context.
79 // Completes updating the CRX at the front of the queue, and initiates
80 // the update for the next CRX in the queue, if the queue is not empty.
81 void UpdateCrxComplete(CrxUpdateItem
* item
);
83 // Called when the updates for all CRXs have finished and the execution
84 // flow must return back to the update engine.
85 void UpdateComplete(int error
);
87 base::ThreadChecker thread_checker_
;
89 UpdateContext
* update_context_
; // Not owned by this class.
90 Action::Callback callback_
;
93 DISALLOW_COPY_AND_ASSIGN(ActionImpl
);
96 } // namespace update_client
98 #endif // COMPONENTS_UPDATE_CLIENT_ACTION_H_