Chromium Code Reviews| 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..c091c1eb04ceecf0aa7132d2b7c5cfcaa6e3ab9c 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,6 +21,9 @@ namespace platform_util { |
| namespace { |
| +const char kNautilusKey[] = "nautilus"; |
| +const char kSupportedNautilusVersion[] = "3.0.2"; |
| + |
| void XDGUtil(const std::string& util, |
| const base::FilePath& working_directory, |
| const std::string& arg) { |
| @@ -56,6 +61,61 @@ void XDGEmail(const std::string& email) { |
| XDGUtil("xdg-email", base::FilePath(), email); |
| } |
| +void ShowFileInNautilus(const base::FilePath& working_directory, |
| + const std::string& path){ |
|
Lei Zhang
2016/04/19 21:51:25
nit: space after )
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
|
| + XDGUtil("nautilus", working_directory, path); |
| +} |
| + |
| +std::string GetNautilusVersion() { |
| + std::string output; |
| + std::string found_version; |
| + |
| + base::CommandLine nautilus_cl(base::FilePath("/usr/bin/nautilus")); |
|
Lei Zhang
2016/04/19 21:51:25
Don't hard code /usr/bin/nautilus. It's also weird
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
|
| + nautilus_cl.AppendArg("--version"); |
| + |
| + if (base::GetAppOutputAndError(nautilus_cl, &output)) { |
| + const std::size_t version_position = output.find(kNautilusKey) + |
| + std::char_traits<char>::length(kNautilusKey) + 1; |
|
Lei Zhang
2016/04/19 21:51:25
Why not just strlen()?
maksims (do not use this acc)
2016/04/20 12:02:45
Done. Different people like different ways of doin
Lei Zhang
2016/04/20 20:45:57
IMO the simpler version, unless there's some advan
|
| + found_version = output.substr(version_position); |
| + |
| + if (!found_version.empty() && |
| + found_version[found_version.length()-1] == '\n') { |
|
Lei Zhang
2016/04/19 21:51:25
foo - 1
maksims (do not use this acc)
2016/04/20 12:02:45
Spaces?
Lei Zhang
2016/04/20 20:45:57
Yes, you forgot the next line as well. Alternative
|
| + found_version.erase(found_version.length()-1); |
| + } |
| + } |
| + |
| + return found_version; |
| +} |
| + |
| +void CheckNautilusIsDefault(std::string* str) { |
| + const base::Version supported_version(kSupportedNautilusVersion); |
|
Lei Zhang
2016/04/19 21:51:25
You can declare variables closer to where they are
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
Lei Zhang
2016/04/20 20:45:57
I didn't mean move |kSupportedNautilusVersion|. I
|
| + std::string file_browser; |
| + |
| + base::CommandLine xdg_mime(base::FilePath("/usr/bin/xdg-mime")); |
|
Lei Zhang
2016/04/19 21:51:25
Don't hard code /usr/bin/xdg-mime. Use whatever th
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
|
| + xdg_mime.AppendArg("query"); |
| + xdg_mime.AppendArg("default"); |
| + xdg_mime.AppendArg("inode/directory"); |
| + |
| + if (base::GetAppOutputAndError(xdg_mime, &file_browser)) { |
| + if (file_browser.find(kNautilusKey) != std::string::npos) { |
|
Lei Zhang
2016/04/19 21:51:25
xdg-mime query default inode/directory is expected
maksims (do not use this acc)
2016/04/20 12:02:45
Done. Right my fault.
Lei Zhang
2016/04/20 20:45:57
Simplify to: file_browser == kNautilusKey ? If you
|
| + base::Version current_version(GetNautilusVersion()); |
| + if ((current_version.IsValid() && supported_version.IsValid()) && |
| + (current_version >= supported_version)) { |
| + *str = file_browser; |
| + } |
| + } |
| + } |
| +} |
| + |
| +void ShowItem(Profile* profile, const base::FilePath& full_path, |
| + const std::string* file_browser) { |
| + if ((*file_browser).find(kNautilusKey) != std::string::npos) |
|
Lei Zhang
2016/04/19 21:51:25
In general (*foo).bar() can be written as foo->bar
maksims (do not use this acc)
2016/04/20 12:02:45
Done. Depends how you like it.
|
| + OpenItem(profile, full_path, SHOW_ITEM_IN_FOLDER, OpenOperationCallback()); |
| + else |
|
Lei Zhang
2016/04/19 21:51:25
Once again, when there are multi-line statements,
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
|
| + OpenItem(profile, full_path.DirName(), OPEN_FOLDER, |
| + OpenOperationCallback()); |
| +} |
| + |
| } // namespace |
| namespace internal { |
| @@ -75,16 +135,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()); |
| + std::string* output = new std::string; |
|
Lei Zhang
2016/04/19 21:51:25
No need, just:
base::PostTaskAndReplyWithResult(
maksims (do not use this acc)
2016/04/20 12:02:45
Done.
|
| + BrowserThread::PostBlockingPoolTaskAndReply(FROM_HERE, |
| + base::Bind(&CheckNautilusIsDefault, output), |
| + base::Bind(&ShowItem, profile, full_path, base::Owned(output))); |
| } |
| void OpenExternal(Profile* profile, const GURL& url) { |