Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: components/update_client/action_update.h

Issue 2835803002: Refactor the UpdateEngine and its actions in the component updater. (Closed)
Patch Set: feedback up to #6 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/update_client/action.cc ('k') | components/update_client/action_update.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #ifndef COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_
6 #define COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.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"
22
23 namespace base {
24 class FilePath;
25 }
26
27 namespace update_client {
28
29 enum class UnpackError;
30
31 // Defines a template method design pattern for ActionUpdate. This class
32 // implements the common code for updating a single CRX using either
33 // a differential or a full update algorithm.
34 // TODO(sorin): further refactor this class to enforce that there is a 1:1
35 // relationship between one instance of this class and one CRX id. In other
36 // words, make the CRX id and its associated CrxUpdateItem data structure
37 // a member of this class instead of passing them around as function parameters.
38 class ActionUpdate : public Action, protected ActionImpl {
39 public:
40 ActionUpdate();
41 ~ActionUpdate() override;
42
43 // Action overrides.
44 void Run(UpdateContext* update_context, Callback callback) override;
45
46 private:
47 virtual bool IsBackgroundDownload(const CrxUpdateItem* item) = 0;
48 virtual std::vector<GURL> GetUrls(const CrxUpdateItem* item) = 0;
49 virtual std::string GetHash(const CrxUpdateItem* item) = 0;
50 virtual void OnDownloadStart(CrxUpdateItem* item) = 0;
51 virtual void OnDownloadSuccess(
52 CrxUpdateItem* item,
53 const CrxDownloader::Result& download_result) = 0;
54 virtual void OnDownloadError(
55 CrxUpdateItem* item,
56 const CrxDownloader::Result& download_result) = 0;
57 virtual void OnInstallStart(CrxUpdateItem* item) = 0;
58 virtual void OnInstallSuccess(CrxUpdateItem* item) = 0;
59 virtual void OnInstallError(CrxUpdateItem* item,
60 ErrorCategory error_category,
61 int error,
62 int extended_error) = 0;
63
64 void StartDownload(CrxUpdateItem* item);
65 void DownloadComplete(const std::string& id,
66 const CrxDownloader::Result& download_result);
67
68 // Called when progress is being made downloading a CRX. The progress may
69 // not monotonically increase due to how the CRX downloader switches between
70 // different downloaders and fallback urls.
71 void DownloadProgress(const std::string& id,
72 const CrxDownloader::Result& download_result);
73
74 void StartInstall(CrxUpdateItem* item, const base::FilePath& crx_path);
75 void InstallComplete(const std::string& id,
76 ErrorCategory error_category,
77 int error,
78 int extended_error);
79
80 void StartUnpackOnBlockingTaskRunner(CrxUpdateItem* item,
81 const base::FilePath& crx_path);
82 void UnpackCompleteOnBlockingTaskRunner(
83 CrxUpdateItem* item,
84 const base::FilePath& crx_path,
85 const ComponentUnpacker::Result& result);
86
87 void StartInstallOnBlockingTaskRunner(CrxUpdateItem* item,
88 const base::FilePath& crx_path,
89 const base::FilePath& unpack_path);
90 void InstallCompleteOnBlockingTaskRunner(CrxUpdateItem* item,
91 const base::FilePath& crx_path,
92 ErrorCategory error_category,
93 int error,
94 int extended_error);
95
96 CrxInstaller::Result DoInstall(CrxUpdateItem* item,
97 const base::FilePath& crx_path,
98 const base::FilePath& unpack_path);
99
100 // Downloads updates for one CRX id only.
101 std::unique_ptr<CrxDownloader> crx_downloader_;
102
103 // Unpacks one CRX.
104 scoped_refptr<ComponentUnpacker> unpacker_;
105
106 DISALLOW_COPY_AND_ASSIGN(ActionUpdate);
107 };
108
109 class ActionUpdateDiff : public ActionUpdate {
110 public:
111 static std::unique_ptr<Action> Create();
112
113 private:
114 ActionUpdateDiff();
115 ~ActionUpdateDiff() override;
116
117 void TryUpdateFull();
118
119 // ActionUpdate overrides.
120 bool IsBackgroundDownload(const CrxUpdateItem* item) override;
121 std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
122 std::string GetHash(const CrxUpdateItem* item) override;
123 void OnDownloadStart(CrxUpdateItem* item) override;
124 void OnDownloadSuccess(CrxUpdateItem* item,
125 const CrxDownloader::Result& download_result) override;
126 void OnDownloadError(CrxUpdateItem* item,
127 const CrxDownloader::Result& download_result) override;
128 void OnInstallStart(CrxUpdateItem* item) override;
129 void OnInstallSuccess(CrxUpdateItem* item) override;
130 void OnInstallError(CrxUpdateItem* item,
131 ErrorCategory error_category,
132 int error,
133 int extended_error) override;
134
135 DISALLOW_COPY_AND_ASSIGN(ActionUpdateDiff);
136 };
137
138 class ActionUpdateFull : public ActionUpdate {
139 public:
140 static std::unique_ptr<Action> Create();
141
142 private:
143 ActionUpdateFull();
144 ~ActionUpdateFull() override;
145
146 // ActionUpdate overrides.
147 bool IsBackgroundDownload(const CrxUpdateItem* item) override;
148 std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
149 std::string GetHash(const CrxUpdateItem* item) override;
150 void OnDownloadStart(CrxUpdateItem* item) override;
151 void OnDownloadSuccess(CrxUpdateItem* item,
152 const CrxDownloader::Result& download_result) override;
153 void OnDownloadError(CrxUpdateItem* item,
154 const CrxDownloader::Result& download_result) override;
155 void OnInstallStart(CrxUpdateItem* item) override;
156 void OnInstallSuccess(CrxUpdateItem* item) override;
157 void OnInstallError(CrxUpdateItem* item,
158 ErrorCategory error_category,
159 int error,
160 int extended_error) override;
161
162 DISALLOW_COPY_AND_ASSIGN(ActionUpdateFull);
163 };
164
165 } // namespace update_client
166
167 #endif // COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_
OLDNEW
« no previous file with comments | « components/update_client/action.cc ('k') | components/update_client/action_update.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698