File: action_update.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (167 lines) | stat: -rw-r--r-- 6,449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_
#define COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "base/version.h"
#include "components/update_client/action.h"
#include "components/update_client/component_unpacker.h"
#include "components/update_client/crx_downloader.h"
#include "components/update_client/update_client.h"
#include "components/update_client/update_engine.h"
#include "url/gurl.h"

namespace base {
class FilePath;
}

namespace update_client {

enum class UnpackError;

// Defines a template method design pattern for ActionUpdate. This class
// implements the common code for updating a single CRX using either
// a differential or a full update algorithm.
// TODO(sorin): further refactor this class to enforce that there is a 1:1
// relationship between one instance of this class and one CRX id. In other
// words, make the CRX id and its associated CrxUpdateItem data structure
// a member of this class instead of passing them around as function parameters.
class ActionUpdate : public Action, protected ActionImpl {
 public:
  ActionUpdate();
  ~ActionUpdate() override;

  // Action overrides.
  void Run(UpdateContext* update_context, Callback callback) override;

 private:
  virtual bool IsBackgroundDownload(const CrxUpdateItem* item) = 0;
  virtual std::vector<GURL> GetUrls(const CrxUpdateItem* item) = 0;
  virtual std::string GetHash(const CrxUpdateItem* item) = 0;
  virtual void OnDownloadStart(CrxUpdateItem* item) = 0;
  virtual void OnDownloadSuccess(
      CrxUpdateItem* item,
      const CrxDownloader::Result& download_result) = 0;
  virtual void OnDownloadError(
      CrxUpdateItem* item,
      const CrxDownloader::Result& download_result) = 0;
  virtual void OnInstallStart(CrxUpdateItem* item) = 0;
  virtual void OnInstallSuccess(CrxUpdateItem* item) = 0;
  virtual void OnInstallError(CrxUpdateItem* item,
                              ErrorCategory error_category,
                              int error,
                              int extended_error) = 0;

  void StartDownload(CrxUpdateItem* item);
  void DownloadComplete(const std::string& id,
                        const CrxDownloader::Result& download_result);

  // Called when progress is being made downloading a CRX. The progress may
  // not monotonically increase due to how the CRX downloader switches between
  // different downloaders and fallback urls.
  void DownloadProgress(const std::string& id,
                        const CrxDownloader::Result& download_result);

  void StartInstall(CrxUpdateItem* item, const base::FilePath& crx_path);
  void InstallComplete(const std::string& id,
                       ErrorCategory error_category,
                       int error,
                       int extended_error);

  void StartUnpackOnBlockingTaskRunner(CrxUpdateItem* item,
                                       const base::FilePath& crx_path);
  void UnpackCompleteOnBlockingTaskRunner(
      CrxUpdateItem* item,
      const base::FilePath& crx_path,
      const ComponentUnpacker::Result& result);

  void StartInstallOnBlockingTaskRunner(CrxUpdateItem* item,
                                        const base::FilePath& crx_path,
                                        const base::FilePath& unpack_path);
  void InstallCompleteOnBlockingTaskRunner(CrxUpdateItem* item,
                                           const base::FilePath& crx_path,
                                           ErrorCategory error_category,
                                           int error,
                                           int extended_error);

  CrxInstaller::Result DoInstall(CrxUpdateItem* item,
                                 const base::FilePath& crx_path,
                                 const base::FilePath& unpack_path);

  // Downloads updates for one CRX id only.
  std::unique_ptr<CrxDownloader> crx_downloader_;

  // Unpacks one CRX.
  scoped_refptr<ComponentUnpacker> unpacker_;

  DISALLOW_COPY_AND_ASSIGN(ActionUpdate);
};

class ActionUpdateDiff : public ActionUpdate {
 public:
  static std::unique_ptr<Action> Create();

 private:
  ActionUpdateDiff();
  ~ActionUpdateDiff() override;

  void TryUpdateFull();

  // ActionUpdate overrides.
  bool IsBackgroundDownload(const CrxUpdateItem* item) override;
  std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
  std::string GetHash(const CrxUpdateItem* item) override;
  void OnDownloadStart(CrxUpdateItem* item) override;
  void OnDownloadSuccess(CrxUpdateItem* item,
                         const CrxDownloader::Result& download_result) override;
  void OnDownloadError(CrxUpdateItem* item,
                       const CrxDownloader::Result& download_result) override;
  void OnInstallStart(CrxUpdateItem* item) override;
  void OnInstallSuccess(CrxUpdateItem* item) override;
  void OnInstallError(CrxUpdateItem* item,
                      ErrorCategory error_category,
                      int error,
                      int extended_error) override;

  DISALLOW_COPY_AND_ASSIGN(ActionUpdateDiff);
};

class ActionUpdateFull : public ActionUpdate {
 public:
  static std::unique_ptr<Action> Create();

 private:
  ActionUpdateFull();
  ~ActionUpdateFull() override;

  // ActionUpdate overrides.
  bool IsBackgroundDownload(const CrxUpdateItem* item) override;
  std::vector<GURL> GetUrls(const CrxUpdateItem* item) override;
  std::string GetHash(const CrxUpdateItem* item) override;
  void OnDownloadStart(CrxUpdateItem* item) override;
  void OnDownloadSuccess(CrxUpdateItem* item,
                         const CrxDownloader::Result& download_result) override;
  void OnDownloadError(CrxUpdateItem* item,
                       const CrxDownloader::Result& download_result) override;
  void OnInstallStart(CrxUpdateItem* item) override;
  void OnInstallSuccess(CrxUpdateItem* item) override;
  void OnInstallError(CrxUpdateItem* item,
                      ErrorCategory error_category,
                      int error,
                      int extended_error) override;

  DISALLOW_COPY_AND_ASSIGN(ActionUpdateFull);
};

}  // namespace update_client

#endif  // COMPONENTS_UPDATE_CLIENT_ACTION_UPDATE_H_