Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Component updates can be either differential updates or full updates. | 5 // Component updates can be either differential updates or full updates. |
| 6 // Full updates come in CRX format; differential updates come in CRX-style | 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 | 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, | 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 | 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 | 10 // of the component to create the contents of a full update, which is then |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // and allowed to, and fall back to a full update if it fails. | 21 // and allowed to, and fall back to a full update if it fails. |
| 22 // | 22 // |
| 23 // After installation (diff or full), the component updater records "fp", the | 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 | 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. | 25 // the server so that a proper differential update can be provided next cycle. |
| 26 | 26 |
| 27 | 27 |
| 28 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 28 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| 29 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 29 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| 30 | 30 |
| 31 #include "base/basictypes.h" | |
| 32 #include "base/callback_forward.h" | 31 #include "base/callback_forward.h" |
| 33 #include "base/compiler_specific.h" | |
| 34 #include "chrome/browser/component_updater/component_unpacker.h" | 32 #include "chrome/browser/component_updater/component_unpacker.h" |
| 35 | 33 |
| 36 namespace base { | 34 namespace base { |
| 37 class FilePath; | 35 class FilePath; |
| 38 } | 36 } |
| 39 | 37 |
| 40 namespace component_updater { | 38 namespace component_updater { |
| 41 | 39 |
| 42 class ComponentInstaller; | 40 class ComponentInstaller; |
| 41 class DeltaUpdateOp; | |
| 43 | 42 |
| 44 // Applies a delta patch to a single file. Specifically, creates a file at | 43 // The type of a patch file. |
| 45 // |output_file| using |input_file| patched according to the algorithm | 44 enum PatchType { |
| 46 // specified by |patch_type| using |patch_file|. Sets the value of error to | 45 kPatchTypeUnknown, |
| 47 // the error code of the failing patch operation, if there is such a failure. | 46 kPatchTypeCourgette, |
| 47 kPatchTypeBsdiff, | |
| 48 }; | |
| 49 | |
| 50 // Applies a delta patch to a set of files. | |
| 51 // The constructor takes an unpacked differential CRX (|input_dir|) and a | |
| 52 // component installer, and sets up the class to create a new (non-differential) | |
| 53 // unpacked CRX. | |
| 54 // The non-differential files are written into the |unpack_dir| directory. | |
| 55 // When finished, calls |callback|, passing error codes if any errors were | |
| 56 // encountered. | |
| 48 class ComponentPatcher { | 57 class ComponentPatcher { |
| 49 public: | 58 public: |
| 50 // The type of a patch file. | 59 ComponentPatcher(const base::FilePath& input_dir, |
| 51 enum PatchType { | 60 const base::FilePath& unpack_dir, |
| 52 kPatchTypeUnknown, | 61 ComponentInstaller* installer, |
| 53 kPatchTypeCourgette, | 62 bool in_process, |
| 54 kPatchTypeBsdiff, | 63 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 55 }; | |
| 56 | 64 |
| 57 virtual ComponentUnpacker::Error Patch(PatchType patch_type, | 65 virtual ~ComponentPatcher(); |
| 58 const base::FilePath& input_file, | 66 |
| 59 const base::FilePath& patch_file, | 67 // Starts patching files. This method returns immediately, after posting a |
| 60 const base::FilePath& output_file, | 68 // task to do the patching. |
| 61 int* error) = 0; | 69 void Start( |
| 62 virtual ~ComponentPatcher() {} | 70 const base::Callback<void(ComponentUnpacker::Error, int)>& callback); |
| 71 | |
| 72 // Returns a weak pointer to this object. | |
| 73 base::WeakPtr<ComponentPatcher> GetWeakPtr(); | |
| 74 | |
| 75 private: | |
| 76 void PatchNextFile(); | |
| 77 | |
| 78 void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); | |
| 79 | |
| 80 base::FilePath input_dir_; | |
| 81 base::FilePath unpack_dir_; | |
| 82 ComponentInstaller* installer_; | |
| 83 bool in_process_; | |
| 84 base::Callback<void(ComponentUnpacker::Error, int)> callback_; | |
|
Sorin Jianu
2014/02/03 20:57:57
A typedef would be handy to make the code prettier
| |
| 85 scoped_ptr<base::ListValue> commands_; | |
| 86 base::ValueVector::const_iterator next_command_; | |
| 87 scoped_ptr<DeltaUpdateOp> current_operation_; | |
| 88 base::WeakPtrFactory<ComponentPatcher> ptr_factory_; | |
| 89 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); | |
| 63 }; | 92 }; |
| 64 | 93 |
| 65 class ComponentPatcherCrossPlatform : public ComponentPatcher { | |
| 66 public: | |
| 67 ComponentPatcherCrossPlatform(); | |
| 68 virtual ComponentUnpacker::Error Patch(PatchType patch_type, | |
| 69 const base::FilePath& input_file, | |
| 70 const base::FilePath& patch_file, | |
| 71 const base::FilePath& output_file, | |
| 72 int* error) OVERRIDE; | |
| 73 private: | |
| 74 DISALLOW_COPY_AND_ASSIGN(ComponentPatcherCrossPlatform); | |
| 75 }; | |
| 76 | |
| 77 // This function takes an unpacked differential CRX (|input_dir|) and a | |
| 78 // component installer, and creates a new (non-differential) unpacked CRX, which | |
| 79 // is then installed normally. | |
| 80 // The non-differential files are written into the |unpack_dir| directory. | |
| 81 // When finished, calls the callback, passing error codes if any errors were | |
| 82 // encountered. | |
| 83 void DifferentialUpdatePatch( | |
| 84 const base::FilePath& input_dir, | |
| 85 const base::FilePath& unpack_dir, | |
| 86 ComponentPatcher* component_patcher, | |
| 87 ComponentInstaller* installer, | |
| 88 base::Callback<void(ComponentUnpacker::Error, int)> callback); | |
| 89 | |
| 90 } // namespace component_updater | 94 } // namespace component_updater |
| 91 | 95 |
| 92 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 96 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| OLD | NEW |