Code cleanup

This commit is contained in:
Cheng Zhao 2015-10-01 17:30:59 +08:00
parent 1f2d934d9d
commit 5a97cfaa64

View file

@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h"
#include "content/public/browser/desktop_notification_delegate.h" #include "content/public/browser/desktop_notification_delegate.h"
@ -16,46 +17,33 @@
#include <stdlib.h> #include <stdlib.h>
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
using namespace base;
using namespace std;
namespace brightray { namespace brightray {
namespace { namespace {
static bool unity_has_result = false; bool unity_has_result = false;
static bool unity_result = false; bool unity_result = false;
static bool UnityIsRunning() { bool UnityIsRunning() {
FileEnumerator* enumerator = NULL; if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER"))
return true;
if (unity_has_result) { if (unity_has_result)
return unity_result; return unity_result;
}
if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) { unity_has_result = true;
unity_result = true;
goto out;
}
// Look for the presence of libunity as our hint that we're under Ubuntu // Look for the presence of libunity as our hint that we're under Ubuntu.
FilePath haystack; base::FileEnumerator enumerator(base::FilePath("/usr/lib"),
string needle("/usr/lib/libunity-"); false, base::FileEnumerator::FILES);
base::FilePath haystack;
enumerator = new FileEnumerator(FilePath("/usr/lib"), false, FileEnumerator::FILES); while (!((haystack = enumerator.Next()).empty())) {
if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", base::CompareCase::SENSITIVE)) {
while (!((haystack = enumerator->Next()).empty())) {
if (haystack.value().compare(0, needle.length(), needle) == 0) {
unity_result = true; unity_result = true;
goto out; break;
} }
} }
unity_result = false;
out:
if (enumerator) delete enumerator;
unity_has_result = true;
return unity_result; return unity_result;
} }