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

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

Issue 6297003: Fail gracefully if profile Temp dir can not be accessed. (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: Remove fallback code. Use a histogram to inform us when getting DIR_USER_DATA_TEMP fails. Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/crypto/signature_verifier.h" 11 #include "base/crypto/signature_verifier.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/file_util_proxy.h" 13 #include "base/file_util_proxy.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/path_service.h"
15 #include "base/scoped_handle.h" 16 #include "base/scoped_handle.h"
16 #include "base/task.h" 17 #include "base/task.h"
17 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. 18 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me.
18 #include "chrome/browser/browser_thread.h" 19 #include "chrome/browser/browser_thread.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 21 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
22 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/extensions/extension_file_util.h" 26 #include "chrome/common/extensions/extension_file_util.h"
25 #include "chrome/common/extensions/extension_l10n_util.h" 27 #include "chrome/common/extensions/extension_l10n_util.h"
26 #include "chrome/common/extensions/extension_unpacker.h" 28 #include "chrome/common/extensions/extension_unpacker.h"
27 #include "chrome/common/json_value_serializer.h" 29 #include "chrome/common/json_value_serializer.h"
28 #include "gfx/codec/png_codec.h" 30 #include "gfx/codec/png_codec.h"
29 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
31 33
32 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; 34 const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24";
33 35
34 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( 36 SandboxedExtensionUnpacker::SandboxedExtensionUnpacker(
35 const FilePath& crx_path, 37 const FilePath& crx_path,
36 const FilePath& temp_path,
37 ResourceDispatcherHost* rdh, 38 ResourceDispatcherHost* rdh,
38 SandboxedExtensionUnpackerClient* client) 39 SandboxedExtensionUnpackerClient* client)
39 : crx_path_(crx_path), temp_path_(temp_path), 40 : crx_path_(crx_path),
40 thread_identifier_(BrowserThread::ID_COUNT), 41 thread_identifier_(BrowserThread::ID_COUNT),
41 rdh_(rdh), client_(client), got_response_(false) { 42 rdh_(rdh), client_(client), got_response_(false) {
42 } 43 }
43 44
45 bool SandboxedExtensionUnpacker::CreateTempDirectory() {
46 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
47
48 FilePath user_data_temp_dir = extension_file_util::GetUserDataTempDir();
49 if (user_data_temp_dir.empty()) {
50 // TODO(skerner): This should have its own string.
51 // Using an existing string so that the change can be merged.
52 ReportFailure(l10n_util::GetStringFUTF8(
Erik does not do reviews 2011/01/18 21:36:34 maybe we should also add a histogram straight into
Sam Kerner (Chrome) 2011/01/19 05:01:24 Added a histogram to count failures. Also added o
Erik does not do reviews 2011/01/19 05:14:17 yeah, an enum would be best, but I'm fine doing th
53 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
54 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY")));
55 return false;
56 }
57
58 if (!temp_dir_.CreateUniqueTempDirUnderPath(user_data_temp_dir)) {
59 ReportFailure(l10n_util::GetStringFUTF8(
60 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
61 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY")));
62 return false;
63 }
64
65 return true;
66 }
67
44 void SandboxedExtensionUnpacker::Start() { 68 void SandboxedExtensionUnpacker::Start() {
45 // We assume that we are started on the thread that the client wants us to do 69 // We assume that we are started on the thread that the client wants us to do
46 // file IO on. 70 // file IO on.
47 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); 71 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_));
48 72
49 // Create a temporary directory to work in. 73 if (!CreateTempDirectory())
50 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_)) { 74 // ReportFailure() already called.
Erik does not do reviews 2011/01/18 21:36:34 can this fit on the same line as the return?
Sam Kerner (Chrome) 2011/01/19 05:01:24 Done.
51 // Could not create temporary directory.
52 ReportFailure(l10n_util::GetStringFUTF8(
53 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
54 ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY")));
55 return; 75 return;
56 }
57 76
58 // Initialize the path that will eventually contain the unpacked extension. 77 // Initialize the path that will eventually contain the unpacked extension.
59 extension_root_ = temp_dir_.path().AppendASCII( 78 extension_root_ = temp_dir_.path().AppendASCII(
60 extension_filenames::kTempExtensionName); 79 extension_filenames::kTempExtensionName);
61 80
62 // Extract the public key and validate the package. 81 // Extract the public key and validate the package.
63 if (!ValidateSignature()) 82 if (!ValidateSignature())
64 return; // ValidateSignature() already reported the error. 83 return; // ValidateSignature() already reported the error.
65 84
66 // Copy the crx file into our working directory. 85 // Copy the crx file into our working directory.
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // Error saving catalog. 509 // Error saving catalog.
491 ReportFailure(l10n_util::GetStringFUTF8( 510 ReportFailure(l10n_util::GetStringFUTF8(
492 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 511 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
493 ASCIIToUTF16("ERROR_SAVING_CATALOG"))); 512 ASCIIToUTF16("ERROR_SAVING_CATALOG")));
494 return false; 513 return false;
495 } 514 }
496 } 515 }
497 516
498 return true; 517 return true;
499 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698