OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <shellapi.h> | 7 #include <shellapi.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // Checks the visibility of the enumerated window and signals once a visible | 84 // Checks the visibility of the enumerated window and signals once a visible |
85 // window has been found. | 85 // window has been found. |
86 BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { | 86 BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { |
87 bool* result = reinterpret_cast<bool*>(param); | 87 bool* result = reinterpret_cast<bool*>(param); |
88 *result = ::IsWindowVisible(window) != 0; | 88 *result = ::IsWindowVisible(window) != 0; |
89 // Stops enumeration if a visible window has been found. | 89 // Stops enumeration if a visible window has been found. |
90 return !*result; | 90 return !*result; |
91 } | 91 } |
92 | 92 |
93 bool ParseCommandLine(const COPYDATASTRUCT* cds, | 93 bool ParseCommandLine(const COPYDATASTRUCT* cds, |
94 CommandLine* parsed_command_line, | 94 base::CommandLine* parsed_command_line, |
95 base::FilePath* current_directory) { | 95 base::FilePath* current_directory) { |
96 // We should have enough room for the shortest command (min_message_size) | 96 // We should have enough room for the shortest command (min_message_size) |
97 // and also be a multiple of wchar_t bytes. The shortest command | 97 // and also be a multiple of wchar_t bytes. The shortest command |
98 // possible is L"START\0\0" (empty current directory and command line). | 98 // possible is L"START\0\0" (empty current directory and command line). |
99 static const int min_message_size = 7; | 99 static const int min_message_size = 7; |
100 if (cds->cbData < min_message_size * sizeof(wchar_t) || | 100 if (cds->cbData < min_message_size * sizeof(wchar_t) || |
101 cds->cbData % sizeof(wchar_t) != 0) { | 101 cds->cbData % sizeof(wchar_t) != 0) { |
102 LOG(WARNING) << "Invalid WM_COPYDATA, length = " << cds->cbData; | 102 LOG(WARNING) << "Invalid WM_COPYDATA, length = " << cds->cbData; |
103 return false; | 103 return false; |
104 } | 104 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 msg.find_first_of(L'\0', second_null + 1); | 137 msg.find_first_of(L'\0', second_null + 1); |
138 if (third_null == std::wstring::npos || | 138 if (third_null == std::wstring::npos || |
139 third_null == msg.length()) { | 139 third_null == msg.length()) { |
140 LOG(WARNING) << "Invalid format for start command, we need a string in 4 " | 140 LOG(WARNING) << "Invalid format for start command, we need a string in 4 " |
141 "parts separated by NULLs"; | 141 "parts separated by NULLs"; |
142 } | 142 } |
143 | 143 |
144 // Get command line. | 144 // Get command line. |
145 const std::wstring cmd_line = | 145 const std::wstring cmd_line = |
146 msg.substr(second_null + 1, third_null - second_null); | 146 msg.substr(second_null + 1, third_null - second_null); |
147 *parsed_command_line = CommandLine::FromString(cmd_line); | 147 *parsed_command_line = base::CommandLine::FromString(cmd_line); |
148 return true; | 148 return true; |
149 } | 149 } |
150 return false; | 150 return false; |
151 } | 151 } |
152 | 152 |
153 bool ProcessLaunchNotification( | 153 bool ProcessLaunchNotification( |
154 const ProcessSingleton::NotificationCallback& notification_callback, | 154 const ProcessSingleton::NotificationCallback& notification_callback, |
155 UINT message, | 155 UINT message, |
156 WPARAM wparam, | 156 WPARAM wparam, |
157 LPARAM lparam, | 157 LPARAM lparam, |
158 LRESULT* result) { | 158 LRESULT* result) { |
159 if (message != WM_COPYDATA) | 159 if (message != WM_COPYDATA) |
160 return false; | 160 return false; |
161 | 161 |
162 // Handle the WM_COPYDATA message from another process. | 162 // Handle the WM_COPYDATA message from another process. |
163 const COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(lparam); | 163 const COPYDATASTRUCT* cds = reinterpret_cast<COPYDATASTRUCT*>(lparam); |
164 | 164 |
165 CommandLine parsed_command_line(CommandLine::NO_PROGRAM); | 165 base::CommandLine parsed_command_line(base::CommandLine::NO_PROGRAM); |
166 base::FilePath current_directory; | 166 base::FilePath current_directory; |
167 if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) { | 167 if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) { |
168 *result = TRUE; | 168 *result = TRUE; |
169 return true; | 169 return true; |
170 } | 170 } |
171 | 171 |
172 *result = notification_callback.Run(parsed_command_line, current_directory) ? | 172 *result = notification_callback.Run(parsed_command_line, current_directory) ? |
173 TRUE : FALSE; | 173 TRUE : FALSE; |
174 return true; | 174 return true; |
175 } | 175 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 326 |
327 ProcessSingleton::NotifyResult | 327 ProcessSingleton::NotifyResult |
328 ProcessSingleton::NotifyOtherProcessOrCreate() { | 328 ProcessSingleton::NotifyOtherProcessOrCreate() { |
329 ProcessSingleton::NotifyResult result = PROCESS_NONE; | 329 ProcessSingleton::NotifyResult result = PROCESS_NONE; |
330 if (!Create()) { | 330 if (!Create()) { |
331 result = NotifyOtherProcess(); | 331 result = NotifyOtherProcess(); |
332 if (result == PROCESS_NONE) | 332 if (result == PROCESS_NONE) |
333 result = PROFILE_IN_USE; | 333 result = PROFILE_IN_USE; |
334 } else { | 334 } else { |
335 g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing( | 335 g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing( |
336 *CommandLine::ForCurrentProcess()); | 336 *base::CommandLine::ForCurrentProcess()); |
337 } | 337 } |
338 return result; | 338 return result; |
339 } | 339 } |
340 | 340 |
341 // Look for a Chrome instance that uses the same profile directory. If there | 341 // Look for a Chrome instance that uses the same profile directory. If there |
342 // isn't one, create a message window with its title set to the profile | 342 // isn't one, create a message window with its title set to the profile |
343 // directory path. | 343 // directory path. |
344 bool ProcessSingleton::Create() { | 344 bool ProcessSingleton::Create() { |
345 static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; | 345 static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; |
346 static const wchar_t kMetroActivationEventName[] = | 346 static const wchar_t kMetroActivationEventName[] = |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 ::SetEvent(metro_activation_event.Get()); | 454 ::SetEvent(metro_activation_event.Get()); |
455 } | 455 } |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 return window_.hwnd() != NULL; | 459 return window_.hwnd() != NULL; |
460 } | 460 } |
461 | 461 |
462 void ProcessSingleton::Cleanup() { | 462 void ProcessSingleton::Cleanup() { |
463 } | 463 } |
OLD | NEW |