[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / platform_util_linux.cc
blobf863baab929d27992bb5fa8dd51d4be80d645428
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/kill.h"
10 #include "base/process/launch.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "url/gurl.h"
15 using content::BrowserThread;
17 namespace {
19 void XDGUtil(const std::string& util, const std::string& arg) {
20 std::vector<std::string> argv;
21 argv.push_back(util);
22 argv.push_back(arg);
24 base::LaunchOptions options;
25 options.allow_new_privs = true;
26 // xdg-open can fall back on mailcap which eventually might plumb through
27 // to a command that needs a terminal. Set the environment variable telling
28 // it that we definitely don't have a terminal available and that it should
29 // bring up a new terminal if necessary. See "man mailcap".
30 options.environ["MM_NOTTTY"] = "1";
32 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes.
33 // However, we do not want this environment variable to propagate to external
34 // applications. See http://crbug.com/24120
35 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG");
36 if (disable_gnome_bug_buddy &&
37 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME"))
38 options.environ["GNOME_DISABLE_CRASH_DIALOG"] = std::string();
40 base::ProcessHandle handle;
41 if (base::LaunchProcess(argv, options, &handle))
42 base::EnsureProcessGetsReaped(handle);
45 void XDGOpen(const std::string& path) {
46 XDGUtil("xdg-open", path);
49 void XDGEmail(const std::string& email) {
50 XDGUtil("xdg-email", email);
53 // TODO(estade): It would be nice to be able to select the file in the file
54 // manager, but that probably requires extending xdg-open. For now just
55 // show the folder.
56 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) {
57 base::FilePath dir = full_path.DirName();
58 if (!base::DirectoryExists(dir))
59 return;
61 XDGOpen(dir.value());
64 } // namespace
66 namespace platform_util {
68 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
71 base::Bind(&ShowItemInFolderOnFileThread, full_path));
74 void OpenItem(Profile* profile, const base::FilePath& full_path) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
77 base::Bind(&XDGOpen, full_path.value()));
80 void OpenExternal(Profile* profile, const GURL& url) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
82 if (url.SchemeIs("mailto"))
83 XDGEmail(url.spec());
84 else
85 XDGOpen(url.spec());
88 } // namespace platform_util