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

Unified Diff: chrome/common/extensions/extension_file_util.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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension_file_util.cc
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index e8636be7fe6d0a9e3e280a73e0f384cec24eda66..4db2761221545a2caf616a52eb00e7d3ecd5535c 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.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.
@@ -10,8 +10,12 @@
#include "app/l10n_util.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
+#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
+#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_action.h"
#include "chrome/common/extensions/extension_l10n_util.h"
@@ -517,4 +521,70 @@ FilePath ExtensionURLToRelativeFilePath(const GURL& url) {
return path;
}
+FilePath GetUserDataTempDir() {
+ // We do file IO in this function, but only when the current profile
+ // has never had an extension installed, or in a rare error. Developers
Erik does not do reviews 2011/01/18 21:36:34 "has never used the profile temp dir before" (I be
Sam Kerner (Chrome) 2011/01/19 05:01:24 Done.
+ // are not likely to run into these cases often, so do an explicit thread
+ // check.
+ base::ThreadRestrictions::AssertIOAllowed();
+
+ // crbug.com/67627: Getting chrome::DIR_USER_DATA_TEMP is failing.
+ // Use histogram to see why.
Erik does not do reviews 2011/01/18 21:36:34 add TODO remove this code when fixed
Sam Kerner (Chrome) 2011/01/19 05:01:24 Done.
+ enum DirectoryCreationResult {
+ SUCCESS = 0,
+
+ CANT_GET_PARENT_PATH,
+ CANT_GET_UDT_PATH,
+ NOT_A_DIRECTORY,
+ CANT_CREATE_DIR,
+ CANT_WRITE_TO_PATH,
+
+ UNSET,
+ NUM_DIRECTORY_CREATION_RESULTS
+ };
+
+ // All paths should set |result|.
+ DirectoryCreationResult result = UNSET;
+
+ FilePath temp_path;
+ if (!PathService::Get(chrome::DIR_USER_DATA_TEMP, &temp_path)) {
+ FilePath parent_path;
+ if (!PathService::Get(chrome::DIR_USER_DATA, &parent_path))
+ result = CANT_GET_PARENT_PATH;
+ else
+ result = CANT_GET_UDT_PATH;
+
+ } else if (file_util::PathExists(temp_path)) {
+
+ // Path exists. Check that it is a directory we can write to.
+ if (!file_util::DirectoryExists(temp_path)) {
+ result = NOT_A_DIRECTORY;
+
+ } else if (!file_util::PathIsWritable(temp_path)) {
+ result = CANT_WRITE_TO_PATH;
+
+ } else {
+ // Temp is a writable directory.
+ result = SUCCESS;
+ }
+
+ } else if (!file_util::CreateDirectory(temp_path)) {
+ // Path doesn't exist, and we failed to create it.
+ result = CANT_CREATE_DIR;
+
+ } else {
+ // Successfully created the Temp directory.
+ result = SUCCESS;
+ }
+
+ UMA_HISTOGRAM_ENUMERATION("Extensions.GetUserDataTempDir",
+ result,
+ NUM_DIRECTORY_CREATION_RESULTS);
+
+ if (result == SUCCESS)
+ return temp_path;
+
+ return FilePath();
+}
+
} // namespace extension_file_util
« chrome/common/chrome_paths.cc ('K') | « chrome/common/extensions/extension_file_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698