| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/win_util.h" | 10 #include "base/win_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 : window_(NULL), locked_(false) { | 38 : window_(NULL), locked_(false) { |
| 39 // FindWindoEx and Create() should be one atomic operation in order to not | 39 // FindWindoEx and Create() should be one atomic operation in order to not |
| 40 // have a race condition. | 40 // have a race condition. |
| 41 remote_window_ = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, | 41 remote_window_ = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, |
| 42 user_data_dir.ToWStringHack().c_str()); | 42 user_data_dir.ToWStringHack().c_str()); |
| 43 if (!remote_window_) | 43 if (!remote_window_) |
| 44 Create(); | 44 Create(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ProcessSingleton::~ProcessSingleton() { | 47 ProcessSingleton::~ProcessSingleton() { |
| 48 if (window_) | 48 if (window_) { |
| 49 DestroyWindow(window_); | 49 DestroyWindow(window_); |
| 50 UnregisterClass(chrome::kMessageWindowClass, GetModuleHandle(NULL)); |
| 51 } |
| 50 } | 52 } |
| 51 | 53 |
| 52 bool ProcessSingleton::NotifyOtherProcess() { | 54 bool ProcessSingleton::NotifyOtherProcess() { |
| 53 if (!remote_window_) | 55 if (!remote_window_) |
| 54 return false; | 56 return false; |
| 55 | 57 |
| 56 // Found another window, send our command line to it | 58 // Found another window, send our command line to it |
| 57 // format is "START\0<<<current directory>>>\0<<<commandline>>>". | 59 // format is "START\0<<<current directory>>>\0<<<commandline>>>". |
| 58 std::wstring to_send(L"START\0", 6); // want the NULL in the string. | 60 std::wstring to_send(L"START\0", 6); // want the NULL in the string. |
| 59 std::wstring cur_dir; | 61 std::wstring cur_dir; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (window_) | 137 if (window_) |
| 136 return; | 138 return; |
| 137 | 139 |
| 138 HINSTANCE hinst = GetModuleHandle(NULL); | 140 HINSTANCE hinst = GetModuleHandle(NULL); |
| 139 | 141 |
| 140 WNDCLASSEX wc = {0}; | 142 WNDCLASSEX wc = {0}; |
| 141 wc.cbSize = sizeof(wc); | 143 wc.cbSize = sizeof(wc); |
| 142 wc.lpfnWndProc = ProcessSingleton::WndProcStatic; | 144 wc.lpfnWndProc = ProcessSingleton::WndProcStatic; |
| 143 wc.hInstance = hinst; | 145 wc.hInstance = hinst; |
| 144 wc.lpszClassName = chrome::kMessageWindowClass; | 146 wc.lpszClassName = chrome::kMessageWindowClass; |
| 145 RegisterClassEx(&wc); | 147 ATOM clazz = RegisterClassEx(&wc); |
| 148 DCHECK(clazz); |
| 146 | 149 |
| 147 std::wstring user_data_dir; | 150 std::wstring user_data_dir; |
| 148 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 151 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 149 | 152 |
| 150 // Set the window's title to the path of our user data directory so other | 153 // Set the window's title to the path of our user data directory so other |
| 151 // Chrome instances can decide if they should forward to us or not. | 154 // Chrome instances can decide if they should forward to us or not. |
| 152 window_ = CreateWindow(chrome::kMessageWindowClass, user_data_dir.c_str(), | 155 window_ = CreateWindow(chrome::kMessageWindowClass, user_data_dir.c_str(), |
| 153 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0); | 156 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0); |
| 154 DCHECK(window_); | 157 DCHECK(window_); |
| 155 | 158 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 switch (message) { | 253 switch (message) { |
| 251 case WM_COPYDATA: | 254 case WM_COPYDATA: |
| 252 return OnCopyData(reinterpret_cast<HWND>(wparam), | 255 return OnCopyData(reinterpret_cast<HWND>(wparam), |
| 253 reinterpret_cast<COPYDATASTRUCT*>(lparam)); | 256 reinterpret_cast<COPYDATASTRUCT*>(lparam)); |
| 254 default: | 257 default: |
| 255 break; | 258 break; |
| 256 } | 259 } |
| 257 | 260 |
| 258 return ::DefWindowProc(hwnd, message, wparam, lparam); | 261 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 259 } | 262 } |
| OLD | NEW |