Torne (Richard Coles) | 03b57e0 | 2014-08-28 12:05:23 +0100 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Component updates can be either differential updates or full updates. |
| 6 | // Full updates come in CRX format; differential updates come in CRX-style |
| 7 | // archives, but have a different magic number. They contain "commands.json", a |
| 8 | // list of commands for the patcher to follow. The patcher uses these commands, |
| 9 | // the other files in the archive, and the files from the existing installation |
| 10 | // of the component to create the contents of a full update, which is then |
| 11 | // installed normally. |
| 12 | // Component updates are specified by the 'codebasediff' attribute of an |
| 13 | // updatecheck response: |
| 14 | // <updatecheck codebase="http://example.com/extension_1.2.3.4.crx" |
| 15 | // hash="12345" size="9854" status="ok" version="1.2.3.4" |
| 16 | // prodversionmin="2.0.143.0" |
| 17 | // codebasediff="http://example.com/diff_1.2.3.4.crx" |
| 18 | // hashdiff="123" sizediff="101" |
| 19 | // fp="1.123" /> |
| 20 | // The component updater will attempt a differential update if it is available |
| 21 | // and allowed to, and fall back to a full update if it fails. |
| 22 | // |
| 23 | // After installation (diff or full), the component updater records "fp", the |
| 24 | // fingerprint of the installed files, to later identify the existing files to |
| 25 | // the server so that a proper differential update can be provided next cycle. |
| 26 | |
Torne (Richard Coles) | 03b57e0 | 2014-08-28 12:05:23 +0100 | [diff] [blame] | 27 | #ifndef COMPONENTS_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| 28 | #define COMPONENTS_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 29 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 30 | #include "base/callback_forward.h" |
Primiano Tucci | 1320f92 | 2014-09-30 14:45:55 +0100 | [diff] [blame] | 31 | #include "base/macros.h" |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 32 | #include "base/memory/ref_counted.h" |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 33 | #include "base/memory/scoped_ptr.h" |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 34 | #include "base/values.h" |
Torne (Richard Coles) | 03b57e0 | 2014-08-28 12:05:23 +0100 | [diff] [blame] | 35 | #include "components/component_updater/component_unpacker.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 36 | |
| 37 | namespace base { |
| 38 | class FilePath; |
| 39 | } |
| 40 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 41 | namespace component_updater { |
| 42 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 43 | class ComponentInstaller; |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 44 | class DeltaUpdateOp; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 45 | class OutOfProcessPatcher; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 46 | |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 47 | // The type of a patch file. |
| 48 | enum PatchType { |
| 49 | kPatchTypeUnknown, |
| 50 | kPatchTypeCourgette, |
| 51 | kPatchTypeBsdiff, |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 54 | // Encapsulates a task for applying a differential update to a component. |
| 55 | class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 56 | public: |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 57 | // Takes an unpacked differential CRX (|input_dir|) and a component installer, |
| 58 | // and sets up the class to create a new (non-differential) unpacked CRX. |
| 59 | // If |in_process| is true, patching will be done completely within the |
| 60 | // existing process. Otherwise, some steps of patching may be done |
| 61 | // out-of-process. |
| 62 | ComponentPatcher(const base::FilePath& input_dir, |
| 63 | const base::FilePath& unpack_dir, |
| 64 | ComponentInstaller* installer, |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 65 | scoped_refptr<OutOfProcessPatcher> out_of_process_patcher, |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 66 | scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 67 | |
| 68 | // Starts patching files. This member function returns immediately, after |
| 69 | // posting a task to do the patching. When patching has been completed, |
| 70 | // |callback| will be called with the error codes if any error codes were |
| 71 | // encountered. |
| 72 | void Start(const ComponentUnpacker::Callback& callback); |
| 73 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 74 | private: |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 75 | friend class base::RefCountedThreadSafe<ComponentPatcher>; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 76 | |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 77 | virtual ~ComponentPatcher(); |
| 78 | |
| 79 | void StartPatching(); |
| 80 | |
| 81 | void PatchNextFile(); |
| 82 | |
| 83 | void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); |
| 84 | |
| 85 | void DonePatching(ComponentUnpacker::Error error, int extended_error); |
| 86 | |
| 87 | const base::FilePath input_dir_; |
| 88 | const base::FilePath unpack_dir_; |
| 89 | ComponentInstaller* const installer_; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 90 | scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_; |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 91 | ComponentUnpacker::Callback callback_; |
| 92 | scoped_ptr<base::ListValue> commands_; |
| 93 | base::ValueVector::const_iterator next_command_; |
| 94 | scoped_refptr<DeltaUpdateOp> current_operation_; |
| 95 | scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 96 | |
| 97 | DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); |
| 98 | }; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 99 | |
| 100 | } // namespace component_updater |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 101 | |
Torne (Richard Coles) | 03b57e0 | 2014-08-28 12:05:23 +0100 | [diff] [blame] | 102 | #endif // COMPONENTS_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |