OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/extensions/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/gfx/png_encoder.h" | 8 #include "base/gfx/png_encoder.h" |
9 #include "base/scoped_handle.h" | 9 #include "base/scoped_handle.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 80 matching lines...) Loading... |
91 // process. Results are sent back to this class, which we route to the | 91 // process. Results are sent back to this class, which we route to the |
92 // ExtensionServiceBackend. | 92 // ExtensionServiceBackend. |
93 class ExtensionsServiceBackend::UnpackerClient | 93 class ExtensionsServiceBackend::UnpackerClient |
94 : public UtilityProcessHost::Client { | 94 : public UtilityProcessHost::Client { |
95 public: | 95 public: |
96 UnpackerClient(ExtensionsServiceBackend* backend, | 96 UnpackerClient(ExtensionsServiceBackend* backend, |
97 const FilePath& extension_path, | 97 const FilePath& extension_path, |
98 const std::string& expected_id, | 98 const std::string& expected_id, |
99 bool from_external) | 99 bool from_external) |
100 : backend_(backend), extension_path_(extension_path), | 100 : backend_(backend), extension_path_(extension_path), |
101 expected_id_(expected_id), from_external_(from_external) { | 101 expected_id_(expected_id), from_external_(from_external), |
| 102 got_response_(false) { |
102 } | 103 } |
103 | 104 |
104 // Starts the unpack task. We call back to the backend when the task is done, | 105 // Starts the unpack task. We call back to the backend when the task is done, |
105 // or a problem occurs. | 106 // or a problem occurs. |
106 void Start() { | 107 void Start() { |
107 AddRef(); // balanced in OnUnpackExtensionReply() | 108 AddRef(); // balanced in OnUnpackExtensionReply() |
108 | 109 |
109 // TODO(mpcomplete): handle multiple installs | 110 // TODO(mpcomplete): handle multiple installs |
110 FilePath temp_dir = backend_->install_directory_.AppendASCII( | 111 FilePath temp_dir = backend_->install_directory_.AppendASCII( |
111 kUnpackExtensionDir); | 112 kUnpackExtensionDir); |
(...skipping 24 matching lines...) Loading... |
136 unpacker.decoded_images()); | 137 unpacker.decoded_images()); |
137 } else { | 138 } else { |
138 OnUnpackExtensionFailed(unpacker.error_message()); | 139 OnUnpackExtensionFailed(unpacker.error_message()); |
139 } | 140 } |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 private: | 144 private: |
144 // UtilityProcessHost::Client | 145 // UtilityProcessHost::Client |
145 virtual void OnProcessCrashed() { | 146 virtual void OnProcessCrashed() { |
146 OnUnpackExtensionFailed("Chrome crashed while trying to install"); | 147 // Don't report crashes if they happen after we got a response. |
| 148 if (got_response_) |
| 149 return; |
| 150 |
| 151 OnUnpackExtensionFailed("Chrome crashed while trying to install."); |
147 } | 152 } |
148 | 153 |
149 virtual void OnUnpackExtensionSucceeded( | 154 virtual void OnUnpackExtensionSucceeded( |
150 const DictionaryValue& manifest, | 155 const DictionaryValue& manifest, |
151 const std::vector< Tuple2<SkBitmap, FilePath> >& images) { | 156 const std::vector< Tuple2<SkBitmap, FilePath> >& images) { |
152 // The extension was unpacked to the temp dir inside our unpacking dir. | 157 // The extension was unpacked to the temp dir inside our unpacking dir. |
153 FilePath extension_dir = temp_extension_path_.DirName().AppendASCII( | 158 FilePath extension_dir = temp_extension_path_.DirName().AppendASCII( |
154 ExtensionsServiceBackend::kTempExtensionName); | 159 ExtensionsServiceBackend::kTempExtensionName); |
155 backend_->OnExtensionUnpacked(extension_path_, extension_dir, | 160 backend_->OnExtensionUnpacked(extension_path_, extension_dir, |
156 expected_id_, from_external_, | 161 expected_id_, from_external_, |
157 manifest, images); | 162 manifest, images); |
158 Cleanup(); | 163 Cleanup(); |
159 } | 164 } |
160 | 165 |
161 virtual void OnUnpackExtensionFailed(const std::string& error_message) { | 166 virtual void OnUnpackExtensionFailed(const std::string& error_message) { |
162 backend_->ReportExtensionInstallError(extension_path_, error_message); | 167 backend_->ReportExtensionInstallError(extension_path_, error_message); |
163 Cleanup(); | 168 Cleanup(); |
164 } | 169 } |
165 | 170 |
166 // Cleans up our temp directory. | 171 // Cleans up our temp directory. |
167 void Cleanup() { | 172 void Cleanup() { |
| 173 if (got_response_) |
| 174 return; |
| 175 |
| 176 got_response_ = true; |
168 file_util::Delete(temp_extension_path_.DirName(), true); | 177 file_util::Delete(temp_extension_path_.DirName(), true); |
169 Release(); // balanced in Run() | 178 Release(); // balanced in Run() |
170 } | 179 } |
171 | 180 |
172 // Starts the utility process that unpacks our extension. | 181 // Starts the utility process that unpacks our extension. |
173 void StartProcessOnIOThread(ResourceDispatcherHost* rdh, | 182 void StartProcessOnIOThread(ResourceDispatcherHost* rdh, |
174 MessageLoop* file_loop) { | 183 MessageLoop* file_loop) { |
175 UtilityProcessHost* host = new UtilityProcessHost(rdh, this, file_loop); | 184 UtilityProcessHost* host = new UtilityProcessHost(rdh, this, file_loop); |
176 host->StartExtensionUnpacker(temp_extension_path_); | 185 host->StartExtensionUnpacker(temp_extension_path_); |
177 } | 186 } |
178 | 187 |
179 scoped_refptr<ExtensionsServiceBackend> backend_; | 188 scoped_refptr<ExtensionsServiceBackend> backend_; |
180 | 189 |
181 // The path to the crx file that we're installing. | 190 // The path to the crx file that we're installing. |
182 FilePath extension_path_; | 191 FilePath extension_path_; |
183 | 192 |
184 // The path to the copy of the crx file in the temporary directory where we're | 193 // The path to the copy of the crx file in the temporary directory where we're |
185 // unpacking it. | 194 // unpacking it. |
186 FilePath temp_extension_path_; | 195 FilePath temp_extension_path_; |
187 | 196 |
188 // The ID we expect this extension to have, if any. | 197 // The ID we expect this extension to have, if any. |
189 std::string expected_id_; | 198 std::string expected_id_; |
190 | 199 |
191 // True if this is being installed from an external source. | 200 // True if this is being installed from an external source. |
192 bool from_external_; | 201 bool from_external_; |
| 202 |
| 203 // True if we got a response from the utility process and have cleaned up |
| 204 // already. |
| 205 bool got_response_; |
193 }; | 206 }; |
194 | 207 |
195 ExtensionsService::ExtensionsService(Profile* profile, | 208 ExtensionsService::ExtensionsService(Profile* profile, |
196 MessageLoop* frontend_loop, | 209 MessageLoop* frontend_loop, |
197 MessageLoop* backend_loop, | 210 MessageLoop* backend_loop, |
198 const std::string& registry_path) | 211 const std::string& registry_path) |
199 : prefs_(profile->GetPrefs()), | 212 : prefs_(profile->GetPrefs()), |
200 backend_loop_(backend_loop), | 213 backend_loop_(backend_loop), |
201 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), | 214 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), |
202 backend_(new ExtensionsServiceBackend( | 215 backend_(new ExtensionsServiceBackend( |
(...skipping 746 matching lines...) Loading... |
949 | 962 |
950 bool ExtensionsServiceBackend::ShouldInstall(const std::string& id, | 963 bool ExtensionsServiceBackend::ShouldInstall(const std::string& id, |
951 const std::string& version) { | 964 const std::string& version) { |
952 FilePath dir(install_directory_.AppendASCII(id.c_str())); | 965 FilePath dir(install_directory_.AppendASCII(id.c_str())); |
953 std::string current_version; | 966 std::string current_version; |
954 if (ReadCurrentVersion(dir, ¤t_version)) { | 967 if (ReadCurrentVersion(dir, ¤t_version)) { |
955 return CheckCurrentVersion(version, current_version, dir); | 968 return CheckCurrentVersion(version, current_version, dir); |
956 } | 969 } |
957 return true; | 970 return true; |
958 } | 971 } |
OLD | NEW |