Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: chrome/browser/component_updater/component_patcher.h

Issue 25909005: Use UtilityProcessHost to patch files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nonblocking
Patch Set: sorin@ review and rebase to LKGR r254060 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
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;
43 44
44 // Applies a delta patch to a single file. Specifically, creates a file at 45 // The type of a patch file.
45 // |output_file| using |input_file| patched according to the algorithm 46 enum PatchType {
46 // specified by |patch_type| using |patch_file|. Sets the value of error to 47 kPatchTypeUnknown,
47 // the error code of the failing patch operation, if there is such a failure. 48 kPatchTypeCourgette,
48 class ComponentPatcher { 49 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 }; 50 };
64 51
65 class ComponentPatcherCrossPlatform : public ComponentPatcher { 52 // Encapsulates a task for applying a differential update to a component.
53 class ComponentPatcher : public base::RefCountedThreadSafe<ComponentPatcher> {
66 public: 54 public:
67 ComponentPatcherCrossPlatform(); 55 // Takes an unpacked differential CRX (|input_dir|) and a component installer,
68 virtual ComponentUnpacker::Error Patch(PatchType patch_type, 56 // and sets up the class to create a new (non-differential) unpacked CRX.
69 const base::FilePath& input_file, 57 // If |in_process| is true, patching will be done completely within the
70 const base::FilePath& patch_file, 58 // existing process. Otherwise, some steps of patching may be done
71 const base::FilePath& output_file, 59 // out-of-process.
72 int* error) OVERRIDE; 60 ComponentPatcher(const base::FilePath& input_dir,
61 const base::FilePath& unpack_dir,
62 ComponentInstaller* installer,
63 bool in_process,
64 scoped_refptr<base::SequencedTaskRunner> task_runner);
65
66 // Starts patching files. This member function returns immediately, after
67 // posting a task to do the patching. When patching has been completed,
68 // |callback| will be called with the error codes if any error codes were
69 // encountered.
70 void Start(const ComponentUnpacker::Callback& callback);
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 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);
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698