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

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

Issue 25909005: Use UtilityProcessHost to patch files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nonblocking
Patch Set: sorin@ review + rebase to LKGR r253860 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/json/json_file_value_serializer.h" 14 #include "base/json/json_file_value_serializer.h"
15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 18
19 namespace component_updater { 19 namespace component_updater {
20 20
21 class ComponentInstaller; 21 class ComponentInstaller;
22 class ComponentPatcher; 22 class ComponentPatcher;
23 23
24 // Deserializes the CRX manifest. The top level must be a dictionary. 24 // Deserializes the CRX manifest. The top level must be a dictionary.
25 scoped_ptr<base::DictionaryValue> ReadManifest( 25 scoped_ptr<base::DictionaryValue> ReadManifest(
26 const base::FilePath& unpack_path); 26 const base::FilePath& unpack_path);
(...skipping 29 matching lines...) Expand all
56 // \_ Unzip 56 // \_ Unzip
57 // \_ BeginPatching 57 // \_ BeginPatching
58 // | 58 // |
59 // V 59 // V
60 // EndPatching 60 // EndPatching
61 // \_ Install 61 // \_ Install
62 // \_ Finish 62 // \_ Finish
63 // 63 //
64 // In both cases, if there is an error at any point, the remaining steps will 64 // In both cases, if there is an error at any point, the remaining steps will
65 // be skipped and Finish will be called. 65 // be skipped and Finish will be called.
66 class ComponentUnpacker { 66 class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
67 public: 67 public:
68 // Possible error conditions. 68 // Possible error conditions.
69 // Add only to the bottom of this enum; the order must be kept stable. 69 // Add only to the bottom of this enum; the order must be kept stable.
70 enum Error { 70 enum Error {
71 kNone, 71 kNone,
72 kInvalidParams, 72 kInvalidParams,
73 kInvalidFile, 73 kInvalidFile,
74 kUnzipPathError, 74 kUnzipPathError,
75 kUnzipFailed, 75 kUnzipFailed,
76 kNoManifest, 76 kNoManifest,
77 kBadManifest, 77 kBadManifest,
78 kBadExtension, 78 kBadExtension,
79 kInvalidId, 79 kInvalidId,
80 kInstallerError, 80 kInstallerError,
81 kIoError, 81 kIoError,
82 kDeltaVerificationFailure, 82 kDeltaVerificationFailure,
83 kDeltaBadCommands, 83 kDeltaBadCommands,
84 kDeltaUnsupportedCommand, 84 kDeltaUnsupportedCommand,
85 kDeltaOperationFailure, 85 kDeltaOperationFailure,
86 kDeltaPatchProcessFailure, 86 kDeltaPatchProcessFailure,
87 kDeltaMissingExistingFile, 87 kDeltaMissingExistingFile,
88 kFingerprintWriteFailed, 88 kFingerprintWriteFailed,
89 }; 89 };
90 90
91 typedef base::Callback<void(Error, int)> Callback;
92
91 // Constructs an unpacker for a specific component unpacking operation. 93 // Constructs an unpacker for a specific component unpacking operation.
92 // |pk_hash| is the expected/ public key SHA256 hash. |path| is the current 94 // |pk_hash| is the expected/ public key SHA256 hash. |path| is the current
93 // location of the CRX. 95 // location of the CRX.
94 ComponentUnpacker(const std::vector<uint8>& pk_hash, 96 ComponentUnpacker(const std::vector<uint8>& pk_hash,
95 const base::FilePath& path, 97 const base::FilePath& path,
96 const std::string& fingerprint, 98 const std::string& fingerprint,
97 ComponentPatcher* patcher,
98 ComponentInstaller* installer, 99 ComponentInstaller* installer,
100 bool in_process,
99 scoped_refptr<base::SequencedTaskRunner> task_runner); 101 scoped_refptr<base::SequencedTaskRunner> task_runner);
100 102
103 // Begins the actual unpacking of the files. May invoke a patcher if the
104 // package is a differential update. Calls |callback| with the result.
105 void Unpack(const Callback& callback);
106
107 private:
108 friend class base::RefCountedThreadSafe<ComponentUnpacker>;
109
101 virtual ~ComponentUnpacker(); 110 virtual ~ComponentUnpacker();
102 111
103 // Begins the actual unpacking of the files. May invoke a patcher if the
104 // package is a differential update. Calls |callback| with the result.
105 void Unpack(
106 const base::Callback<void(Error, int)>& callback);
107
108 private:
109 bool UnpackInternal(); 112 bool UnpackInternal();
110 113
111 // The first step of unpacking is to verify the file. Returns false if an 114 // The first step of unpacking is to verify the file. Returns false if an
112 // error is encountered, the file is malformed, or the file is incorrectly 115 // error is encountered, the file is malformed, or the file is incorrectly
113 // signed. 116 // signed.
114 bool Verify(); 117 bool Verify();
115 118
116 // The second step of unpacking is to unzip. Returns false if an error 119 // The second step of unpacking is to unzip. Returns false if an error
117 // occurs as part of unzipping. 120 // occurs as part of unzipping.
118 bool Unzip(); 121 bool Unzip();
119 122
120 // The third step is to optionally patch files - this is a no-op for full 123 // The third step is to optionally patch files - this is a no-op for full
121 // (non-differential) updates. This step is asynchronous. Returns false if an 124 // (non-differential) updates. This step is asynchronous. Returns false if an
122 // error is encountered. 125 // error is encountered.
123 bool BeginPatching(); 126 bool BeginPatching();
124 127
125 // When patching is complete, EndPatching is called before moving on to step 128 // When patching is complete, EndPatching is called before moving on to step
126 // four. 129 // four.
127 void EndPatching(Error error, int extended_error); 130 void EndPatching(Error error, int extended_error);
128 131
129 // The fourth step is to install the unpacked component. 132 // The fourth step is to install the unpacked component.
130 void Install(); 133 void Install();
131 134
132 // The final step is to do clean-up for things that can't be tidied as we go. 135 // The final step is to do clean-up for things that can't be tidied as we go.
133 // If there is an error at any step, the remaining steps are skipped and 136 // If there is an error at any step, the remaining steps are skipped and
134 // and Finish is called. 137 // and Finish is called.
135 // Finish is responsible for calling the callback provided in Start(). 138 // Finish is responsible for calling the callback provided in Start().
136 void Finish(); 139 void Finish();
137 140
138 // Returns a weak pointer to this object.
139 base::WeakPtr<ComponentUnpacker> GetWeakPtr();
140
141 std::vector<uint8> pk_hash_; 141 std::vector<uint8> pk_hash_;
142 base::FilePath path_; 142 base::FilePath path_;
143 base::FilePath unpack_path_; 143 base::FilePath unpack_path_;
144 base::FilePath unpack_diff_path_; 144 base::FilePath unpack_diff_path_;
145 bool is_delta_; 145 bool is_delta_;
146 std::string fingerprint_; 146 std::string fingerprint_;
147 ComponentPatcher* patcher_; 147 scoped_refptr<ComponentPatcher> patcher_;
148 ComponentInstaller* installer_; 148 ComponentInstaller* installer_;
149 base::Callback<void(Error, int)> callback_; 149 Callback callback_;
150 const bool in_process_;
150 Error error_; 151 Error error_;
151 int extended_error_; 152 int extended_error_;
152 base::WeakPtrFactory<ComponentUnpacker> ptr_factory_;
153 scoped_refptr<base::SequencedTaskRunner> task_runner_; 153 scoped_refptr<base::SequencedTaskRunner> task_runner_;
154 154
155 DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker); 155 DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker);
156 }; 156 };
157 157
158 } // namespace component_updater 158 } // namespace component_updater
159 159
160 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_ 160 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698