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

Unified Diff: chrome/browser/platform_util_linux.cc

Issue 1867533002: (TOBEDELETED)Select downloaded file in the folder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes according to review Created 4 years, 8 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
« no previous file with comments | « chrome/browser/platform_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/platform_util_linux.cc
diff --git a/chrome/browser/platform_util_linux.cc b/chrome/browser/platform_util_linux.cc
index 5fd8fbbb430393ec9ac2352cae4a9d1c44ae6056..191a4ff1814a7e2da8a4c9fbaf70da5750b61402 100644
--- a/chrome/browser/platform_util_linux.cc
+++ b/chrome/browser/platform_util_linux.cc
@@ -5,10 +5,12 @@
#include "chrome/browser/platform_util.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/version.h"
#include "chrome/browser/platform_util_internal.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
@@ -19,7 +21,11 @@ namespace platform_util {
namespace {
-void XDGUtil(const std::string& util,
+const char kNautilusKey[] = "nautilus.desktop";
+const char kNautilusCmd[] = "nautilus";
+const char kSupportedNautilusVersion[] = "3.0.2";
+
+void CMDUtil(const std::string& util,
Lei Zhang 2016/04/21 06:16:51 How about RunCommand() and change |util| to |comma
const base::FilePath& working_directory,
const std::string& arg) {
std::vector<std::string> argv;
@@ -49,11 +55,76 @@ void XDGUtil(const std::string& util,
}
void XDGOpen(const base::FilePath& working_directory, const std::string& path) {
- XDGUtil("xdg-open", working_directory, path);
+ CMDUtil("xdg-open", working_directory, path);
}
void XDGEmail(const std::string& email) {
- XDGUtil("xdg-email", base::FilePath(), email);
+ CMDUtil("xdg-email", base::FilePath(), email);
+}
+
+void ShowFileInNautilus(const base::FilePath& working_directory,
+ const std::string& path) {
+ CMDUtil(kNautilusCmd, working_directory, path);
+}
+
+std::string GetNautilusVersion() {
+ std::string output;
+ std::string found_version;
+
+ base::CommandLine nautilus_cl((base::FilePath(kNautilusCmd)));
+ nautilus_cl.AppendArg("--version");
+
+ if (base::GetAppOutputAndError(nautilus_cl, &output)) {
+ const std::size_t nautilus_position = output.find(kNautilusCmd);
Lei Zhang 2016/04/21 06:16:51 You may want to add a comment to explain what you
+ if (nautilus_position != std::string::npos) {
+ const std::size_t version_position =
+ nautilus_position + strlen(kNautilusCmd) + 1;
+ found_version = output.substr(version_position);
+ }
+
+ if (!found_version.empty() &&
Lei Zhang 2016/04/21 06:16:51 Maybe what you really want here is TrimWhitespaceA
+ found_version[found_version.length() - 1] == '\n') {
+ found_version.erase(found_version.length() - 1);
+ }
+ }
+
+ return found_version;
+}
+
+bool CheckNautilusIsDefault() {
+ std::string file_browser;
+
+ base::CommandLine xdg_mime(base::FilePath("xdg-mime"));
+ xdg_mime.AppendArg("query");
+ xdg_mime.AppendArg("default");
+ xdg_mime.AppendArg("inode/directory");
+
+ if (base::GetAppOutputAndError(xdg_mime, &file_browser)) {
Lei Zhang 2016/04/21 06:16:51 You can write this block in fewer lines. Incorpora
+ if (file_browser.find(kNautilusKey) != std::string::npos) {
Lei Zhang 2016/04/21 06:16:51 file_browser == kNautilusKey, as previously sugges
maksims (do not use this acc) 2016/04/21 08:33:49 file_browser string gets trailing whitespace in Ge
Lei Zhang 2016/04/22 07:09:57 Trim the whitespace?
+ const base::Version supported_version(kSupportedNautilusVersion);
+ const base::Version current_version(GetNautilusVersion());
+
+ if ((current_version.IsValid() && supported_version.IsValid()) &&
Lei Zhang 2016/04/21 06:16:51 Why do you need the extra parenthesis? Isn't (con
Lei Zhang 2016/04/21 06:16:51 I would just DCHECK(supported_version.IsValid()) a
+ (current_version >= supported_version)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void ShowItem(Profile* profile,
+ const base::FilePath& full_path,
+ bool nautilus_file_browser) {
Lei Zhang 2016/04/21 06:16:51 use_nautilus_file_browser? nautilus_is_default_fil
+ if (nautilus_file_browser) {
+ OpenItem(profile, full_path, SHOW_ITEM_IN_FOLDER, OpenOperationCallback());
+ } else {
+ // TODO(estade): It would be nice to be able to select the file in other
+ // file managers, but that probably requires extending xdg-open.
+ // For now just show the folder for non-Nautilus users.
+ OpenItem(profile, full_path.DirName(), OPEN_FOLDER,
+ OpenOperationCallback());
+ }
}
} // namespace
@@ -75,16 +146,20 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
// time the application invoked by xdg-open inspects the path by name.
XDGOpen(path, ".");
break;
+ case SHOW_ITEM_IN_FOLDER:
+ ShowFileInNautilus(path.DirName(), path.value());
+ break;
}
}
+
} // namespace internal
void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // TODO(estade): It would be nice to be able to select the file in the file
- // manager, but that probably requires extending xdg-open. For now just show
- // the folder.
- OpenItem(profile, full_path.DirName(), OPEN_FOLDER, OpenOperationCallback());
+ base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&CheckNautilusIsDefault),
+ base::Bind(&ShowItem, profile, full_path));
}
void OpenExternal(Profile* profile, const GURL& url) {
« no previous file with comments | « chrome/browser/platform_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698