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" |
31 #include "base/callback_forward.h" | 32 #include "base/callback_forward.h" |
32 #include "base/memory/ref_counted.h" | 33 #include "base/compiler_specific.h" |
33 #include "base/values.h" | |
34 #include "chrome/browser/component_updater/component_unpacker.h" | 34 #include "chrome/browser/component_updater/component_unpacker.h" |
35 | 35 |
36 namespace base { | 36 namespace base { |
37 class FilePath; | 37 class FilePath; |
38 } | 38 } |
39 | 39 |
40 namespace component_updater { | 40 namespace component_updater { |
41 | 41 |
42 class ComponentInstaller; | 42 class ComponentInstaller; |
43 class DeltaUpdateOp; | |
44 | 43 |
45 // The type of a patch file. | 44 // Applies a delta patch to a single file. Specifically, creates a file at |
46 enum PatchType { | 45 // |output_file| using |input_file| patched according to the algorithm |
47 kPatchTypeUnknown, | 46 // specified by |patch_type| using |patch_file|. Sets the value of error to |
48 kPatchTypeCourgette, | 47 // the error code of the failing patch operation, if there is such a failure. |
49 kPatchTypeBsdiff, | 48 class ComponentPatcher { |
| 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() {} |
50 }; | 63 }; |
51 | 64 |
52 // Encapsulates a task for applying a differential update to a component. | 65 class ComponentPatcherCrossPlatform : public ComponentPatcher { |
53 class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { | |
54 public: | 66 public: |
55 // Takes an unpacked differential CRX (|input_dir|) and a component installer, | 67 ComponentPatcherCrossPlatform(); |
56 // and sets up the class to create a new (non-differential) unpacked CRX. | 68 virtual ComponentUnpacker::Error Patch(PatchType patch_type, |
57 // If |in_process| is true, patching will be done completely within the | 69 const base::FilePath& input_file, |
58 // existing process. Otherwise, some steps of patching may be done | 70 const base::FilePath& patch_file, |
59 // out-of-process. | 71 const base::FilePath& output_file, |
60 ComponentPatcher(const base::FilePath& input_dir, | 72 int* error) OVERRIDE; |
61 const base::FilePath& unpack_dir, | 73 private: |
62 ComponentInstaller* installer, | 74 DISALLOW_COPY_AND_ASSIGN(ComponentPatcherCrossPlatform); |
63 bool in_process, | 75 }; |
64 scoped_refptr<base::SequencedTaskRunner> task_runner); | |
65 | 76 |
66 // Starts patching files. This member function returns immediately, after | 77 // This function takes an unpacked differential CRX (|input_dir|) and a |
67 // posting a task to do the patching. When patching has been completed, | 78 // component installer, and creates a new (non-differential) unpacked CRX, which |
68 // |callback| will be called with the error codes if any error codes were | 79 // is then installed normally. |
69 // encountered. | 80 // The non-differential files are written into the |unpack_dir| directory. |
70 void Start(const ComponentUnpacker::Callback& callback); | 81 // When finished, calls the callback, passing error codes if any errors were |
71 | 82 // encountered. |
72 private: | 83 void DifferentialUpdatePatch( |
73 friend class base::RefCountedThreadSafe<ComponentPatcher>; | 84 const base::FilePath& input_dir, |
74 | 85 const base::FilePath& unpack_dir, |
75 virtual ~ComponentPatcher(); | 86 ComponentPatcher* component_patcher, |
76 | 87 ComponentInstaller* installer, |
77 void StartPatching(); | 88 base::Callback<void(ComponentUnpacker::Error, int)> callback); |
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 ComponentUnpacker::Callback callback_; | |
90 scoped_ptr<base::ListValue> commands_; | |
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); | |
96 }; | |
97 | 89 |
98 } // namespace component_updater | 90 } // namespace component_updater |
99 | 91 |
100 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 92 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
OLD | NEW |