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

Unified Diff: chrome/browser/chromeos/file_manager/open_util.cc

Issue 352393002: Be explicit about target type in platform_util::OpenItem() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify Chrome OS change. Created 6 years, 3 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/browser/chromeos/file_manager/open_util.cc
diff --git a/chrome/browser/chromeos/file_manager/open_util.cc b/chrome/browser/chromeos/file_manager/open_util.cc
index dad853242d6b4dd7ad68aacec4cdd91ebf68d9c0..28892a5f35f6e33b300e2d38ae8d102b6140c938 100644
--- a/chrome/browser/chromeos/file_manager/open_util.cc
+++ b/chrome/browser/chromeos/file_manager/open_util.cc
@@ -87,11 +87,23 @@ void OpenFileManagerWithInternalActionId(Profile* profile,
ExecuteFileTaskForUrl(profile, task, url);
}
-// Opens the file with fetched MIME type and calls the callback.
+void WarnOnOpenFileFailure(Profile* profile,
+ const base::FilePath& file_path) {
hashimoto 2014/09/29 05:34:13 nit: indent.
asanka 2014/09/29 16:17:53 Done.
+ int message;
hashimoto 2014/09/29 05:34:13 nit: While you are here, could you fix this line n
asanka 2014/09/29 16:17:52 Done.
+ if (file_path.Extension() == FILE_PATH_LITERAL(".dmg"))
+ message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG;
+ else if (file_path.Extension() == FILE_PATH_LITERAL(".exe") ||
+ file_path.Extension() == FILE_PATH_LITERAL(".msi"))
+ message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE;
+ else
+ message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE;
+ ShowWarningMessageBox(profile, file_path, message);
+}
+
+// Opens the file with fetched MIME type and warns the user on failure.
void OpenFileWithMimeType(Profile* profile,
const base::FilePath& path,
const GURL& url,
- const base::Callback<void(bool)>& callback,
const std::string& mime_type) {
extensions::app_file_handler_util::PathAndMimeTypeSet path_mime_set;
path_mime_set.insert(std::make_pair(path, mime_type));
@@ -108,7 +120,7 @@ void OpenFileWithMimeType(Profile* profile,
&tasks);
if (tasks.empty()) {
- callback.Run(false);
+ WarnOnOpenFileFailure(profile, path);
return;
}
@@ -121,56 +133,6 @@ void OpenFileWithMimeType(Profile* profile,
}
ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url);
- callback.Run(true);
-}
-
-// Opens the file specified by |url| by finding and executing a file task for
-// the file. In case of success, calls |callback| with true. Otherwise the
-// returned value is false.
-void OpenFile(Profile* profile,
- const base::FilePath& path,
- const GURL& url,
- const base::Callback<void(bool)>& callback) {
- extensions::app_file_handler_util::GetMimeTypeForLocalPath(
- profile,
- path,
- base::Bind(&OpenFileWithMimeType, profile, path, url, callback));
-}
-
-// Called when execution of ContinueOpenItem() is completed.
-void OnContinueOpenItemCompleted(Profile* profile,
- const base::FilePath& file_path,
- bool result) {
- if (!result) {
- int message;
- if (file_path.Extension() == FILE_PATH_LITERAL(".dmg"))
- message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG;
- else if (file_path.Extension() == FILE_PATH_LITERAL(".exe") ||
- file_path.Extension() == FILE_PATH_LITERAL(".msi"))
- message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE;
- else
- message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE;
- ShowWarningMessageBox(profile, file_path, message);
- }
-}
-
-// Used to implement OpenItem().
-void ContinueOpenItem(Profile* profile,
- const base::FilePath& file_path,
- const GURL& url,
- base::File::Error error) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- if (error == base::File::FILE_OK) {
- // A directory exists at |url|. Open it with the file manager.
- OpenFileManagerWithInternalActionId(profile, url, "open");
- } else {
- // |url| should be a file. Open it.
- OpenFile(profile,
- file_path,
- url,
- base::Bind(&OnContinueOpenItemCompleted, profile, file_path));
- }
}
// Converts the |given_path| passed from external callers to the form that the
@@ -210,7 +172,21 @@ void OpenRemovableDrive(Profile* profile, const base::FilePath& file_path) {
OpenFileManagerWithInternalActionId(profile, url, "auto-open");
}
-void OpenItem(Profile* profile, const base::FilePath& file_path) {
+void OpenFile(Profile* profile, const base::FilePath& file_path) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ base::FilePath converted_path;
+ GURL url;
+ if (!ConvertPath(profile, file_path, &converted_path, &url))
+ return;
+
+ extensions::app_file_handler_util::GetMimeTypeForLocalPath(
+ profile,
+ converted_path,
+ base::Bind(&OpenFileWithMimeType, profile, converted_path, url));
+}
+
+void OpenFolder(Profile* profile, const base::FilePath& file_path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::FilePath converted_path;
@@ -218,10 +194,8 @@ void OpenItem(Profile* profile, const base::FilePath& file_path) {
if (!ConvertPath(profile, file_path, &converted_path, &url))
return;
- CheckIfDirectoryExists(
- GetFileSystemContextForExtensionId(profile, kFileManagerAppId),
- url,
- base::Bind(&ContinueOpenItem, profile, converted_path, url));
+ // This call will only open Files.app.
+ OpenFileManagerWithInternalActionId(profile, url, "open");
}
void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) {
« no previous file with comments | « chrome/browser/chromeos/file_manager/open_util.h ('k') | chrome/browser/download/chrome_download_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698