Don't crash when SimpleCache index is corrupt.
[chromium-blink-merge.git] / chrome / browser / platform_util_linux.cc
blob5bae77f561ed506edb94dc857ba3e786c9827076
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/platform_util.h"
7 #include "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/process_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "googleurl/src/gurl.h"
14 using content::BrowserThread;
16 namespace {
18 void XDGUtil(const std::string& util, const std::string& arg) {
19 std::vector<std::string> argv;
20 argv.push_back(util);
21 argv.push_back(arg);
23 base::EnvironmentVector env;
24 // xdg-open can fall back on mailcap which eventually might plumb through
25 // to a command that needs a terminal. Set the environment variable telling
26 // it that we definitely don't have a terminal available and that it should
27 // bring up a new terminal if necessary. See "man mailcap".
28 env.push_back(std::make_pair("MM_NOTTTY", "1"));
30 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes.
31 // However, we do not want this environment variable to propagate to external
32 // applications. See http://crbug.com/24120
33 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG");
34 if (disable_gnome_bug_buddy &&
35 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME")) {
36 env.push_back(std::make_pair("GNOME_DISABLE_CRASH_DIALOG", ""));
39 base::ProcessHandle handle;
40 base::LaunchOptions options;
41 options.environ = &env;
42 if (base::LaunchProcess(argv, options, &handle))
43 base::EnsureProcessGetsReaped(handle);
46 void XDGOpen(const std::string& path) {
47 XDGUtil("xdg-open", path);
50 void XDGEmail(const std::string& email) {
51 XDGUtil("xdg-email", email);
54 // TODO(estade): It would be nice to be able to select the file in the file
55 // manager, but that probably requires extending xdg-open. For now just
56 // show the folder.
57 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) {
58 base::FilePath dir = full_path.DirName();
59 if (!file_util::DirectoryExists(dir))
60 return;
62 XDGOpen(dir.value());
65 } // namespace
67 namespace platform_util {
69 void ShowItemInFolder(const base::FilePath& full_path) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
72 base::Bind(&ShowItemInFolderOnFileThread, full_path));
75 void OpenItem(const base::FilePath& full_path) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
77 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
78 base::Bind(&XDGOpen, full_path.value()));
81 void OpenExternal(const GURL& url) {
82 if (url.SchemeIs("mailto"))
83 XDGEmail(url.spec());
84 else
85 XDGOpen(url.spec());
88 } // namespace platform_util