Index: chrome/browser/extensions/sandboxed_extension_unpacker.cc |
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc |
index 9d7e45b7c1c98cfc20b7b70053c4ee6d0ba0e70b..b47d83f97a4eb908fae5c717824e2f3f9fffd8f5 100644 |
--- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc |
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -12,12 +12,15 @@ |
#include "base/file_util.h" |
#include "base/file_util_proxy.h" |
#include "base/message_loop.h" |
+#include "base/metrics/histogram.h" |
+#include "base/path_service.h" |
#include "base/scoped_handle.h" |
#include "base/task.h" |
#include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
#include "chrome/browser/browser_thread.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
+#include "chrome/common/chrome_paths.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/extension.h" |
#include "chrome/common/extensions/extension_constants.h" |
@@ -29,32 +32,74 @@ |
#include "grit/generated_resources.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+namespace { |
+ |
+const int kUnpackPathKeys[] = { |
+ // First try unpacking in the temp directory inside the user's |
+ // profile. |
+ chrome::DIR_USER_DATA_TEMP, |
+ |
+ // Fall back to system temp. System temp is less than ideal, |
Erik does not do reviews
2011/01/14 22:34:44
I don't think this is a good idea. Much of Chrome
Sam Kerner (Chrome)
2011/01/18 19:26:45
The fall-back to /tmp serves two purposes:
* Miti
|
+ // because moving a directory across volumes is more likly to fail: |
+ // crbug.com/37572 . However, if we can't access a better unpack |
+ // directory, this is better than nothing. |
+ base::DIR_TEMP |
+}; |
+ |
+} |
+ |
const char SandboxedExtensionUnpacker::kExtensionHeaderMagic[] = "Cr24"; |
SandboxedExtensionUnpacker::SandboxedExtensionUnpacker( |
const FilePath& crx_path, |
- const FilePath& temp_path, |
ResourceDispatcherHost* rdh, |
SandboxedExtensionUnpackerClient* client) |
- : crx_path_(crx_path), temp_path_(temp_path), |
+ : crx_path_(crx_path), |
thread_identifier_(BrowserThread::ID_COUNT), |
rdh_(rdh), client_(client), got_response_(false) { |
} |
-void SandboxedExtensionUnpacker::Start() { |
- // We assume that we are started on the thread that the client wants us to do |
- // file IO on. |
+bool SandboxedExtensionUnpacker::CreateTempDirectory( |
+ const int unpack_path_keys[], size_t unpack_path_keys_size) { |
CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); |
- // Create a temporary directory to work in. |
- if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_)) { |
- // Could not create temporary directory. |
+ FilePath temp_path; |
+ bool found_path = false; |
+ for (size_t i = 0; !found_path && i < unpack_path_keys_size; ++i) { |
+ if (!PathService::Get(unpack_path_keys[i], &temp_path)) { |
+ UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackerCantGetTemp", i, 10); |
Erik does not do reviews
2011/01/14 22:34:44
From what I can tell, the only way this can fail i
Sam Kerner (Chrome)
2011/01/18 19:26:45
I had some other theories as to why PathService::G
|
+ continue; |
+ } |
+ |
+ if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path)) { |
+ UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackerCantCreateTemp", i, 10); |
Erik does not do reviews
2011/01/14 22:34:44
simply knowing that this is failing might not be t
|
+ continue; |
+ } |
+ |
+ found_path = true; |
+ } |
+ |
+ if (!found_path) { |
+ // TODO(skerner): This should have its own string. |
+ // Using an existing string so that the change can be merged. |
ReportFailure(l10n_util::GetStringFUTF8( |
IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
ASCIIToUTF16("COULD_NOT_CREATE_TEMP_DIRECTORY"))); |
- return; |
+ return false; |
} |
+ return true; |
+} |
+ |
+void SandboxedExtensionUnpacker::Start() { |
+ // We assume that we are started on the thread that the client wants us to do |
+ // file IO on. |
+ CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_identifier_)); |
+ |
+ if (!CreateTempDirectory(kUnpackPathKeys, arraysize(kUnpackPathKeys))) |
+ // ReportError() already called. |
Erik does not do reviews
2011/01/14 22:34:44
typo: ReportFailure
Sam Kerner (Chrome)
2011/01/18 19:26:45
Done.
|
+ return; |
+ |
// Initialize the path that will eventually contain the unpacked extension. |
extension_root_ = temp_dir_.path().AppendASCII( |
extension_filenames::kTempExtensionName); |