ExtensionInstallDialogView: fix scrolling behavior on Views (Win,Linux)
[chromium-blink-merge.git] / components / update_client / action_update.h
blobca56c883ffa5277980765f4dfcd46c4bc8d4d43d
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_UPDATE_H_
6 #define COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "base/version.h"
16 #include "components/update_client/action.h"
17 #include "components/update_client/component_unpacker.h"
18 #include "components/update_client/crx_downloader.h"
19 #include "components/update_client/update_client.h"
20 #include "components/update_client/update_engine.h"
21 #include "url/gurl.h"
23 namespace update_client {
25 class UpdateChecker;
27 // Defines a template method design pattern for ActionUpdate. This class
28 // implements the common code for updating a single CRX using either
29 // a differential or a full update algorithm.
30 // TODO(sorin): further refactor this class to enforce that there is a 1:1
31 // relationship between one instance of this class and one CRX id. In other
32 // words, make the CRX id and its associated CrxUpdateItem data structure
33 // a member of this class instead of passing them around as function parameters.
34 class ActionUpdate : public Action, protected ActionImpl {
35 public:
36 ActionUpdate();
37 ~ActionUpdate() override;
39 // Action overrides.
40 void Run(UpdateContext* update_context, Callback callback) override;
42 private:
43 virtual bool IsBackgroundDownload(const CrxUpdateItem* item) = 0;
44 virtual std::vector<GURL> GetUrls(const CrxUpdateItem* item) = 0;
45 virtual void OnDownloadStart(CrxUpdateItem* item) = 0;
46 virtual void OnDownloadSuccess(
47 CrxUpdateItem* item,
48 const CrxDownloader::Result& download_result) = 0;
49 virtual void OnDownloadError(
50 CrxUpdateItem* item,
51 const CrxDownloader::Result& download_result) = 0;
52 virtual void OnInstallStart(CrxUpdateItem* item) = 0;
53 virtual void OnInstallSuccess(CrxUpdateItem* item) = 0;
54 virtual void OnInstallError(CrxUpdateItem* item,
55 ComponentUnpacker::Error error,
56 int extended_error) = 0;
58 // Called when progress is being made downloading a CRX. The progress may
59 // not monotonically increase due to how the CRX downloader switches between
60 // different downloaders and fallback urls.
61 void DownloadProgress(const std::string& id,
62 const CrxDownloader::Result& download_result);
64 // Called when the CRX package has been downloaded to a temporary location.
65 void DownloadComplete(const std::string& id,
66 const CrxDownloader::Result& download_result);
68 void Install(const std::string& id, const base::FilePath& crx_path);
70 // TODO(sorin): refactor the public interface of ComponentUnpacker so
71 // that these calls can run on the main thread.
72 void DoInstallOnBlockingTaskRunner(UpdateContext* update_context,
73 CrxUpdateItem* item,
74 const base::FilePath& crx_path);
76 void EndUnpackingOnBlockingTaskRunner(UpdateContext* update_context,
77 CrxUpdateItem* item,
78 const base::FilePath& crx_path,
79 ComponentUnpacker::Error error,
80 int extended_error);
82 void DoneInstalling(const std::string& id,
83 ComponentUnpacker::Error error,
84 int extended_error);
86 // Downloads updates for one CRX id only.
87 scoped_ptr<CrxDownloader> crx_downloader_;
89 // Unpacks one CRX.
90 scoped_refptr<ComponentUnpacker> unpacker_;
92 DISALLOW_COPY_AND_ASSIGN(ActionUpdate);
95 class ActionUpdateDiff : public ActionUpdate {
96 public:
97 static scoped_ptr<Action> Create();
99 private:
100 ActionUpdateDiff();
101 ~ActionUpdateDiff() override;
103 void TryUpdateFull();
105 // ActionUpdate overrides.
106 bool IsBackgroundDownload(const CrxUpdateItem* item) override;
107 std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
108 void OnDownloadStart(CrxUpdateItem* item) override;
109 void OnDownloadSuccess(CrxUpdateItem* item,
110 const CrxDownloader::Result& download_result) override;
111 void OnDownloadError(CrxUpdateItem* item,
112 const CrxDownloader::Result& download_result) override;
113 void OnInstallStart(CrxUpdateItem* item) override;
114 void OnInstallSuccess(CrxUpdateItem* item) override;
115 void OnInstallError(CrxUpdateItem* item,
116 ComponentUnpacker::Error error,
117 int extended_error) override;
119 DISALLOW_COPY_AND_ASSIGN(ActionUpdateDiff);
122 class ActionUpdateFull : ActionUpdate {
123 public:
124 static scoped_ptr<Action> Create();
126 private:
127 ActionUpdateFull();
128 ~ActionUpdateFull() override;
130 // ActionUpdate overrides.
131 bool IsBackgroundDownload(const CrxUpdateItem* item) override;
132 std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
133 void OnDownloadStart(CrxUpdateItem* item) override;
134 void OnDownloadSuccess(CrxUpdateItem* item,
135 const CrxDownloader::Result& download_result) override;
136 void OnDownloadError(CrxUpdateItem* item,
137 const CrxDownloader::Result& download_result) override;
138 void OnInstallStart(CrxUpdateItem* item) override;
139 void OnInstallSuccess(CrxUpdateItem* item) override;
140 void OnInstallError(CrxUpdateItem* item,
141 ComponentUnpacker::Error error,
142 int extended_error) override;
144 DISALLOW_COPY_AND_ASSIGN(ActionUpdateFull);
147 } // namespace update_client
149 #endif // COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_