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

Side by Side Diff: chrome/browser/extensions/sandboxed_extension_unpacker.cc

Issue 345023: Get rid of MessageLoop* caching in extensions code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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/sandboxed_extension_unpacker.h" 5 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/gfx/codec/png_codec.h" 9 #include "app/gfx/codec/png_codec.h"
10 #include "base/crypto/signature_verifier.h" 10 #include "base/crypto/signature_verifier.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/common/json_value_serializer.h" 22 #include "chrome/common/json_value_serializer.h"
23 #include "net/base/base64.h" 23 #include "net/base/base64.h"
24 24
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 26
27 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; 27 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24";
28 28
29 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( 29 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker(
30 const FilePath& crx_path, ResourceDispatcherHost* rdh, 30 const FilePath& crx_path, ResourceDispatcherHost* rdh,
31 SandboxedExtensionUnpackerClient* client) 31 SandboxedExtensionUnpackerClient* client)
32 : crx_path_(crx_path), file_loop_(NULL), rdh_(rdh), client_(client), 32 : crx_path_(crx_path), thread_identifier_(ChromeThread::ID_COUNT),
33 got_response_(false) { 33 rdh_(rdh), client_(client), got_response_(false) {
34 } 34 }
35 35
36 void SandboxedExtensionUnpacker::Start() { 36 void SandboxedExtensionUnpacker::Start() {
37 // We assume that we are started on the thread that the client wants us to do 37 // We assume that we are started on the thread that the client wants us to do
38 // file IO on. 38 // file IO on.
39 file_loop_ = MessageLoop::current(); 39 CHECK(ChromeThread::GetCurrentThreadIdentifier(&thread_identifier_));
40 40
41 // Create a temporary directory to work in. 41 // Create a temporary directory to work in.
42 if (!temp_dir_.CreateUniqueTempDir()) { 42 if (!temp_dir_.CreateUniqueTempDir()) {
43 ReportFailure("Could not create temporary directory."); 43 ReportFailure("Could not create temporary directory.");
44 return; 44 return;
45 } 45 }
46 46
47 // Initialize the path that will eventually contain the unpacked extension. 47 // Initialize the path that will eventually contain the unpacked extension.
48 extension_root_ = temp_dir_.path().AppendASCII("TEMP_INSTALL"); 48 extension_root_ = temp_dir_.path().AppendASCII("TEMP_INSTALL");
49 49
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ExtensionUnpacker unpacker(temp_crx_path); 84 ExtensionUnpacker unpacker(temp_crx_path);
85 if (unpacker.Run() && unpacker.DumpImagesToFile()) 85 if (unpacker.Run() && unpacker.DumpImagesToFile())
86 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest()); 86 OnUnpackExtensionSucceeded(*unpacker.parsed_manifest());
87 else 87 else
88 OnUnpackExtensionFailed(unpacker.error_message()); 88 OnUnpackExtensionFailed(unpacker.error_message());
89 } 89 }
90 } 90 }
91 91
92 void SandboxedExtensionUnpacker::StartProcessOnIOThread( 92 void SandboxedExtensionUnpacker::StartProcessOnIOThread(
93 const FilePath& temp_crx_path) { 93 const FilePath& temp_crx_path) {
94 UtilityProcessHost* host = new UtilityProcessHost(rdh_, this, file_loop_); 94 UtilityProcessHost* host = new UtilityProcessHost(
95 rdh_, this, thread_identifier_);
95 host->StartExtensionUnpacker(temp_crx_path); 96 host->StartExtensionUnpacker(temp_crx_path);
96 } 97 }
97 98
98 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded( 99 void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded(
99 const DictionaryValue& manifest) { 100 const DictionaryValue& manifest) {
100 DCHECK(file_loop_ == MessageLoop::current()); 101 DCHECK(ChromeThread::CurrentlyOn(thread_identifier_));
101 got_response_ = true; 102 got_response_ = true;
102 103
103 ExtensionUnpacker::DecodedImages images; 104 ExtensionUnpacker::DecodedImages images;
104 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) { 105 if (!ExtensionUnpacker::ReadImagesFromFile(temp_dir_.path(), &images)) {
105 ReportFailure("Couldn't read image data from disk."); 106 ReportFailure("Couldn't read image data from disk.");
106 return; 107 return;
107 } 108 }
108 109
109 // Add the public key extracted earlier to the parsed manifest and overwrite 110 // Add the public key extracted earlier to the parsed manifest and overwrite
110 // the original manifest. We do this to ensure the manifest doesn't contain an 111 // the original manifest. We do this to ensure the manifest doesn't contain an
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 ReportFailure("Error saving theme image."); 192 ReportFailure("Error saving theme image.");
192 return; 193 return;
193 } 194 }
194 } 195 }
195 196
196 ReportSuccess(); 197 ReportSuccess();
197 } 198 }
198 199
199 void SandboxedExtensionUnpacker::OnUnpackExtensionFailed( 200 void SandboxedExtensionUnpacker::OnUnpackExtensionFailed(
200 const std::string& error) { 201 const std::string& error) {
201 DCHECK(file_loop_ == MessageLoop::current()); 202 DCHECK(ChromeThread::CurrentlyOn(thread_identifier_));
202 got_response_ = true; 203 got_response_ = true;
203 ReportFailure(error); 204 ReportFailure(error);
204 } 205 }
205 206
206 void SandboxedExtensionUnpacker::OnProcessCrashed() { 207 void SandboxedExtensionUnpacker::OnProcessCrashed() {
207 // Don't report crashes if they happen after we got a response. 208 // Don't report crashes if they happen after we got a response.
208 if (got_response_) 209 if (got_response_)
209 return; 210 return;
210 211
211 ReportFailure("Utility process crashed while trying to install."); 212 ReportFailure("Utility process crashed while trying to install.");
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 303
303 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) { 304 void SandboxedExtensionUnpacker::ReportFailure(const std::string& error) {
304 client_->OnUnpackFailure(error); 305 client_->OnUnpackFailure(error);
305 } 306 }
306 307
307 void SandboxedExtensionUnpacker::ReportSuccess() { 308 void SandboxedExtensionUnpacker::ReportSuccess() {
308 // Client takes ownership of temporary directory and extension. 309 // Client takes ownership of temporary directory and extension.
309 client_->OnUnpackSuccess(temp_dir_.Take(), extension_root_, 310 client_->OnUnpackSuccess(temp_dir_.Take(), extension_root_,
310 extension_.release()); 311 extension_.release());
311 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/sandboxed_extension_unpacker.h ('k') | chrome/browser/extensions/user_script_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698