| 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 11 matching lines...) Expand all Loading... |
| 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 27 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| 28 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 28 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| 29 | 29 |
| 30 #include "base/callback_forward.h" | 30 #include "base/callback_forward.h" |
| 31 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
| 32 #include "base/memory/scoped_ptr.h" |
| 32 #include "base/values.h" | 33 #include "base/values.h" |
| 33 #include "chrome/browser/component_updater/component_unpacker.h" | 34 #include "chrome/browser/component_updater/component_unpacker.h" |
| 34 | 35 |
| 35 namespace base { | 36 namespace base { |
| 36 class FilePath; | 37 class FilePath; |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace component_updater { | 40 namespace component_updater { |
| 40 | 41 |
| 41 class ComponentInstaller; | 42 class ComponentInstaller; |
| 42 class DeltaUpdateOp; | 43 class DeltaUpdateOp; |
| 44 class OutOfProcessPatcher; |
| 43 | 45 |
| 44 // The type of a patch file. | 46 // The type of a patch file. |
| 45 enum PatchType { | 47 enum PatchType { |
| 46 kPatchTypeUnknown, | 48 kPatchTypeUnknown, |
| 47 kPatchTypeCourgette, | 49 kPatchTypeCourgette, |
| 48 kPatchTypeBsdiff, | 50 kPatchTypeBsdiff, |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 // Encapsulates a task for applying a differential update to a component. | 53 // Encapsulates a task for applying a differential update to a component. |
| 52 class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { | 54 class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> { |
| 53 public: | 55 public: |
| 54 // Takes an unpacked differential CRX (|input_dir|) and a component installer, | 56 // Takes an unpacked differential CRX (|input_dir|) and a component installer, |
| 55 // and sets up the class to create a new (non-differential) unpacked CRX. | 57 // and sets up the class to create a new (non-differential) unpacked CRX. |
| 56 // If |in_process| is true, patching will be done completely within the | 58 // If |in_process| is true, patching will be done completely within the |
| 57 // existing process. Otherwise, some steps of patching may be done | 59 // existing process. Otherwise, some steps of patching may be done |
| 58 // out-of-process. | 60 // out-of-process. |
| 59 ComponentPatcher(const base::FilePath& input_dir, | 61 ComponentPatcher(const base::FilePath& input_dir, |
| 60 const base::FilePath& unpack_dir, | 62 const base::FilePath& unpack_dir, |
| 61 ComponentInstaller* installer, | 63 ComponentInstaller* installer, |
| 62 bool in_process, | 64 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher, |
| 63 scoped_refptr<base::SequencedTaskRunner> task_runner); | 65 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 64 | 66 |
| 65 // Starts patching files. This member function returns immediately, after | 67 // Starts patching files. This member function returns immediately, after |
| 66 // posting a task to do the patching. When patching has been completed, | 68 // 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 | 69 // |callback| will be called with the error codes if any error codes were |
| 68 // encountered. | 70 // encountered. |
| 69 void Start(const ComponentUnpacker::Callback& callback); | 71 void Start(const ComponentUnpacker::Callback& callback); |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 friend class base::RefCountedThreadSafe<ComponentPatcher>; | 74 friend class base::RefCountedThreadSafe<ComponentPatcher>; |
| 73 | 75 |
| 74 virtual ~ComponentPatcher(); | 76 virtual ~ComponentPatcher(); |
| 75 | 77 |
| 76 void StartPatching(); | 78 void StartPatching(); |
| 77 | 79 |
| 78 void PatchNextFile(); | 80 void PatchNextFile(); |
| 79 | 81 |
| 80 void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); | 82 void DonePatchingFile(ComponentUnpacker::Error error, int extended_error); |
| 81 | 83 |
| 82 void DonePatching(ComponentUnpacker::Error error, int extended_error); | 84 void DonePatching(ComponentUnpacker::Error error, int extended_error); |
| 83 | 85 |
| 84 const base::FilePath input_dir_; | 86 const base::FilePath input_dir_; |
| 85 const base::FilePath unpack_dir_; | 87 const base::FilePath unpack_dir_; |
| 86 ComponentInstaller* const installer_; | 88 ComponentInstaller* const installer_; |
| 87 const bool in_process_; | 89 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher_; |
| 88 ComponentUnpacker::Callback callback_; | 90 ComponentUnpacker::Callback callback_; |
| 89 scoped_ptr<base::ListValue> commands_; | 91 scoped_ptr<base::ListValue> commands_; |
| 90 base::ValueVector::const_iterator next_command_; | 92 base::ValueVector::const_iterator next_command_; |
| 91 scoped_refptr<DeltaUpdateOp> current_operation_; | 93 scoped_refptr<DeltaUpdateOp> current_operation_; |
| 92 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 94 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 93 | 95 |
| 94 DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); | 96 DISALLOW_COPY_AND_ASSIGN(ComponentPatcher); |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 } // namespace component_updater | 99 } // namespace component_updater |
| 98 | 100 |
| 99 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ | 101 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_ |
| OLD | NEW |