Componentize AccountReconcilor.
[chromium-blink-merge.git] / chrome / browser / browser_util_win.cc
blob47254930df3064f2afc6cb807205f4dced390046
1 // Copyright (c) 2011 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/browser_util_win.h"
7 #include <windows.h>
9 #include <algorithm>
10 #include <string>
12 #include "base/base_paths.h"
13 #include "base/files/file_path.h"
14 #include "base/path_service.h"
16 namespace browser_util {
18 bool IsBrowserAlreadyRunning() {
19 static HANDLE handle = NULL;
20 base::FilePath exe_path;
21 PathService::Get(base::FILE_EXE, &exe_path);
22 std::wstring exe = exe_path.value();
23 std::replace(exe.begin(), exe.end(), '\\', '!');
24 std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
25 exe = L"Global\\" + exe;
26 if (handle != NULL)
27 CloseHandle(handle);
28 handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str());
29 int error = GetLastError();
30 return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
33 } // namespace browser_util