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

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

Issue 897873002: Make ComponentInstaller refcounted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@2015_01_19_component_installer
Patch Set: fix Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ 5 #ifndef COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_
6 #define COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ 6 #define COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 30
31 class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> { 31 class DeltaUpdateOp : public base::RefCountedThreadSafe<DeltaUpdateOp> {
32 public: 32 public:
33 DeltaUpdateOp(); 33 DeltaUpdateOp();
34 34
35 // Parses, runs, and verifies the operation. Calls |callback| with the 35 // Parses, runs, and verifies the operation. Calls |callback| with the
36 // result of the operation. The callback is called using |task_runner|. 36 // result of the operation. The callback is called using |task_runner|.
37 void Run(const base::DictionaryValue* command_args, 37 void Run(const base::DictionaryValue* command_args,
38 const base::FilePath& input_dir, 38 const base::FilePath& input_dir,
39 const base::FilePath& unpack_dir, 39 const base::FilePath& unpack_dir,
40 ComponentInstaller* installer, 40 const scoped_refptr<ComponentInstaller>& installer,
41 const ComponentUnpacker::Callback& callback, 41 const ComponentUnpacker::Callback& callback,
42 scoped_refptr<base::SequencedTaskRunner> task_runner); 42 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
43 43
44 protected: 44 protected:
45 virtual ~DeltaUpdateOp(); 45 virtual ~DeltaUpdateOp();
46 46
47 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner(); 47 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner();
48 48
49 std::string output_sha256_; 49 std::string output_sha256_;
50 base::FilePath output_abs_path_; 50 base::FilePath output_abs_path_;
51 51
52 private: 52 private:
53 friend class base::RefCountedThreadSafe<DeltaUpdateOp>; 53 friend class base::RefCountedThreadSafe<DeltaUpdateOp>;
54 54
55 ComponentUnpacker::Error CheckHash(); 55 ComponentUnpacker::Error CheckHash();
56 56
57 // Subclasses must override DoParseArguments to parse operation-specific 57 // Subclasses must override DoParseArguments to parse operation-specific
58 // arguments. DoParseArguments returns DELTA_OK on success; any other code 58 // arguments. DoParseArguments returns DELTA_OK on success; any other code
59 // represents failure. 59 // represents failure.
60 virtual ComponentUnpacker::Error DoParseArguments( 60 virtual ComponentUnpacker::Error DoParseArguments(
61 const base::DictionaryValue* command_args, 61 const base::DictionaryValue* command_args,
62 const base::FilePath& input_dir, 62 const base::FilePath& input_dir,
63 ComponentInstaller* installer) = 0; 63 const scoped_refptr<ComponentInstaller>& installer) = 0;
64 64
65 // Subclasses must override DoRun to actually perform the patching operation. 65 // Subclasses must override DoRun to actually perform the patching operation.
66 // They must call the provided callback when they have completed their 66 // They must call the provided callback when they have completed their
67 // operations. In practice, the provided callback is always for "DoneRunning". 67 // operations. In practice, the provided callback is always for "DoneRunning".
68 virtual void DoRun(const ComponentUnpacker::Callback& callback) = 0; 68 virtual void DoRun(const ComponentUnpacker::Callback& callback) = 0;
69 69
70 // Callback given to subclasses for when they complete their operation. 70 // Callback given to subclasses for when they complete their operation.
71 // Validates the output, and posts a task to the patching operation's 71 // Validates the output, and posts a task to the patching operation's
72 // callback. 72 // callback.
73 void DoneRunning(ComponentUnpacker::Error error, int extended_error); 73 void DoneRunning(ComponentUnpacker::Error error, int extended_error);
(...skipping 11 matching lines...) Expand all
85 public: 85 public:
86 DeltaUpdateOpCopy(); 86 DeltaUpdateOpCopy();
87 87
88 private: 88 private:
89 ~DeltaUpdateOpCopy() override; 89 ~DeltaUpdateOpCopy() override;
90 90
91 // Overrides of DeltaUpdateOp. 91 // Overrides of DeltaUpdateOp.
92 ComponentUnpacker::Error DoParseArguments( 92 ComponentUnpacker::Error DoParseArguments(
93 const base::DictionaryValue* command_args, 93 const base::DictionaryValue* command_args,
94 const base::FilePath& input_dir, 94 const base::FilePath& input_dir,
95 ComponentInstaller* installer) override; 95 const scoped_refptr<ComponentInstaller>& installer) override;
96 96
97 void DoRun(const ComponentUnpacker::Callback& callback) override; 97 void DoRun(const ComponentUnpacker::Callback& callback) override;
98 98
99 base::FilePath input_abs_path_; 99 base::FilePath input_abs_path_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy); 101 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCopy);
102 }; 102 };
103 103
104 // A 'create' operation takes a full file that was sent in the delta update 104 // A 'create' operation takes a full file that was sent in the delta update
105 // archive and moves it into the unpacking directory: this represents the 105 // archive and moves it into the unpacking directory: this represents the
106 // addition of a new file, or a file so different that no bandwidth could be 106 // addition of a new file, or a file so different that no bandwidth could be
107 // saved by transmitting a differential update. 107 // saved by transmitting a differential update.
108 class DeltaUpdateOpCreate : public DeltaUpdateOp { 108 class DeltaUpdateOpCreate : public DeltaUpdateOp {
109 public: 109 public:
110 DeltaUpdateOpCreate(); 110 DeltaUpdateOpCreate();
111 111
112 private: 112 private:
113 ~DeltaUpdateOpCreate() override; 113 ~DeltaUpdateOpCreate() override;
114 114
115 // Overrides of DeltaUpdateOp. 115 // Overrides of DeltaUpdateOp.
116 ComponentUnpacker::Error DoParseArguments( 116 ComponentUnpacker::Error DoParseArguments(
117 const base::DictionaryValue* command_args, 117 const base::DictionaryValue* command_args,
118 const base::FilePath& input_dir, 118 const base::FilePath& input_dir,
119 ComponentInstaller* installer) override; 119 const scoped_refptr<ComponentInstaller>& installer) override;
120 120
121 void DoRun(const ComponentUnpacker::Callback& callback) override; 121 void DoRun(const ComponentUnpacker::Callback& callback) override;
122 122
123 base::FilePath patch_abs_path_; 123 base::FilePath patch_abs_path_;
124 124
125 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate); 125 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpCreate);
126 }; 126 };
127 127
128 // An interface an embedder may fulfill to enable out-of-process patching. 128 // An interface an embedder may fulfill to enable out-of-process patching.
129 class OutOfProcessPatcher 129 class OutOfProcessPatcher
130 : public base::RefCountedThreadSafe<OutOfProcessPatcher> { 130 : public base::RefCountedThreadSafe<OutOfProcessPatcher> {
131 public: 131 public:
132 virtual void Patch(const std::string& operation, 132 virtual void Patch(
133 scoped_refptr<base::SequencedTaskRunner> task_runner, 133 const std::string& operation,
134 const base::FilePath& input_abs_path, 134 scoped_refptr<base::SequencedTaskRunner> task_runner,
135 const base::FilePath& patch_abs_path, 135 const base::FilePath& input_abs_path,
136 const base::FilePath& output_abs_path, 136 const base::FilePath& patch_abs_path,
137 base::Callback<void(int result)> callback) = 0; 137 const base::FilePath& output_abs_path,
138 base::Callback<void(int result)> callback) = 0;
138 139
139 protected: 140 protected:
140 friend class base::RefCountedThreadSafe<OutOfProcessPatcher>; 141 friend class base::RefCountedThreadSafe<OutOfProcessPatcher>;
141 142
142 virtual ~OutOfProcessPatcher() {} 143 virtual ~OutOfProcessPatcher() {}
143 }; 144 };
144 145
145 // Both 'bsdiff' and 'courgette' operations take an existing file on disk, 146 // Both 'bsdiff' and 'courgette' operations take an existing file on disk,
146 // and a bsdiff- or Courgette-format patch file provided in the delta update 147 // and a bsdiff- or Courgette-format patch file provided in the delta update
147 // package, and run bsdiff or Courgette to construct an output file in the 148 // package, and run bsdiff or Courgette to construct an output file in the
148 // unpacking directory. 149 // unpacking directory.
149 class DeltaUpdateOpPatch : public DeltaUpdateOp { 150 class DeltaUpdateOpPatch : public DeltaUpdateOp {
150 public: 151 public:
151 // |out_of_process_patcher| may be NULL. 152 // |out_of_process_patcher| may be NULL.
152 DeltaUpdateOpPatch(const std::string& operation, 153 DeltaUpdateOpPatch(const std::string& operation,
153 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher); 154 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher);
154 155
155 private: 156 private:
156 ~DeltaUpdateOpPatch() override; 157 ~DeltaUpdateOpPatch() override;
157 158
158 // Overrides of DeltaUpdateOp. 159 // Overrides of DeltaUpdateOp.
159 ComponentUnpacker::Error DoParseArguments( 160 ComponentUnpacker::Error DoParseArguments(
160 const base::DictionaryValue* command_args, 161 const base::DictionaryValue* command_args,
161 const base::FilePath& input_dir, 162 const base::FilePath& input_dir,
162 ComponentInstaller* installer) override; 163 const scoped_refptr<ComponentInstaller>& installer) override;
163 164
164 void DoRun(const ComponentUnpacker::Callback& callback) override; 165 void DoRun(const ComponentUnpacker::Callback& callback) override;
165 166
166 // |success_code| is the code that indicates a successful patch. 167 // |success_code| is the code that indicates a successful patch.
167 // |result| is the code the patching operation returned. 168 // |result| is the code the patching operation returned.
168 void DonePatching(const ComponentUnpacker::Callback& callback, int result); 169 void DonePatching(const ComponentUnpacker::Callback& callback, int result);
169 170
170 std::string operation_; 171 std::string operation_;
171 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_; 172 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_;
172 base::FilePath patch_abs_path_; 173 base::FilePath patch_abs_path_;
173 base::FilePath input_abs_path_; 174 base::FilePath input_abs_path_;
174 175
175 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch); 176 DISALLOW_COPY_AND_ASSIGN(DeltaUpdateOpPatch);
176 }; 177 };
177 178
178 DeltaUpdateOp* CreateDeltaUpdateOp( 179 DeltaUpdateOp* CreateDeltaUpdateOp(
179 const std::string& operation, 180 const std::string& operation,
180 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher); 181 const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher);
181 182
182 } // namespace update_client 183 } // namespace update_client
183 184
184 #endif // COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_ 185 #endif // COMPONENTS_UPDATE_CLIENT_COMPONENT_PATCHER_OPERATION_H_
OLDNEW
« no previous file with comments | « components/update_client/component_patcher.cc ('k') | components/update_client/component_patcher_operation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698