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" | 32 #include "base/memory/ref_counted.h" |
| 34 #include "chrome/browser/component_updater/component_unpacker.h" | 33 #include "chrome/browser/component_updater/component_unpacker.h" |
| 35 | 34 |
| 36 namespace base { | 35 namespace base { |
| 37 class FilePath; | 36 class FilePath; |
| 38 } | 37 } |
| 39 | 38 |
| 40 namespace component_updater { | 39 namespace component_updater { |
| 41 | 40 |
| 42 class ComponentInstaller; | 41 class ComponentInstaller; |
| 42 class DeltaUpdateOp; | |
| 43 | 43 |
| 44 // Applies a delta patch to a single file. Specifically, creates a file at | 44 // The type of a patch file. |
| 45 // |output_file| using |input_file| patched according to the algorithm | 45 enum PatchType { |
| 46 // specified by |patch_type| using |patch_file|. Sets the value of error to | 46 kPatchTypeUnknown, |
| 47 // the error code of the failing patch operation, if there is such a failure. | 47 kPatchTypeCourgette, |
| 48 class ComponentPatcher { | 48 kPatchTypeBsdiff, |
| 49 public: | |
| 50 // The type of a patch file. | |
| 51 enum PatchType { | |
| 52 kPatchTypeUnknown, | |
| 53 kPatchTypeCourgette, | |
| 54 kPatchTypeBsdiff, | |
| 55 }; | |
| 56 | |
| 57 virtual ComponentUnpacker::Error Patch(PatchType patch_type, | |
| 58 const base::FilePath& input_file, | |
| 59 const base::FilePath& patch_file, | |
| 60 const base::FilePath& output_file, | |
| 61 int* error) = 0; | |
| 62 virtual ~ComponentPatcher() {} | |
| 63 }; | 49 }; |
| 64 | 50 |
| 65 class ComponentPatcherCrossPlatform : public ComponentPatcher { | 51 // Encapsulates a task for applying a differential update to a component. |
| 52 class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { | |
| 66 public: | 53 public: |
| 67 ComponentPatcherCrossPlatform(); | 54 // Takes an unpacked differential CRX (|input_dir|) and a component installer, |
| 68 virtual ComponentUnpacker::Error Patch(PatchType patch_type, | 55 // and sets up the class to create a new (non-differential) unpacked CRX. |
| 69 const base::FilePath& input_file, | 56 // If |in_process| is true, patching will be done completely within the |
| 70 const base::FilePath& patch_file, | 57 // existing process. Otherwise, some steps of patching may be done |
| 71 const base::FilePath& output_file, | 58 // out-of-process. |
| 72 int* error) OVERRIDE; | 59 ComponentPatcher(const base::FilePath& input_dir, |
| 60 const base::FilePath& unpack_dir, | |
| 61 ComponentInstaller* installer, | |
| 62 bool in_process, | |
| 63 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
| 64 | |
| 65 // Starts patching files. This member function returns immediately, after | |
| 66 // posting a task to do the patching. When patching has been completed, | |
| 67 // |callback| will be called with the error codes if any error codes were | |
| 68 // encountered. | |
| 69 void Start( | |
| 70 const base::Callback<void(ComponentUnpacker::Error, int)>& callback); | |
|
Sorin Jianu
2014/02/27 20:53:57
A typedef could help making the code prettier thro
waffles
2014/02/28 00:52:43
Done.
| |
| 71 | |
| 73 private: | 72 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(ComponentPatcherCrossPlatform); | 73 friend class base::RefCountedThreadSafe<ComponentPatcher>; |
| 74 | |
| 75 virtual ~ComponentPatcher(); | |
| 76 | |
| 77 void StartPatching(); | |
| 78 | |
| 79 void PatchNextFile(); | |
| 80 | |
| 81 void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); | |
| 82 | |
| 83 void DonePatching(ComponentUnpacker::Error error, int extended_error); | |
| 84 | |
| 85 const base::FilePath input_dir_; | |
| 86 const base::FilePath unpack_dir_; | |
| 87 ComponentInstaller* const installer_; | |
| 88 const bool in_process_; | |
| 89 base::Callback<void(ComponentUnpacker::Error, int)> callback_; | |
| 90 scoped_ptr<base::ListValue> commands_; | |
|
Sorin Jianu
2014/02/27 20:53:57
do we need values.h?
waffles
2014/02/28 00:52:43
Yes thank you.
| |
| 91 base::ValueVector::const_iterator next_command_; | |
| 92 scoped_refptr<DeltaUpdateOp> current_operation_; | |
| 93 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); | |
| 75 }; | 96 }; |
| 76 | 97 |
| 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 | 98 } // namespace component_updater |
| 91 | 99 |
| 92 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 100 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| OLD | NEW |