| 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 <windows.h> | 7 #include <windows.h> | 
| 8 #include <shellapi.h> | 8 #include <shellapi.h> | 
| 9 #include <stddef.h> | 9 #include <stddef.h> | 
| 10 | 10 | 
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" | 
| 12 #include "base/bind.h" | 12 #include "base/bind.h" | 
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" | 
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" | 
| 15 #include "base/macros.h" | 15 #include "base/macros.h" | 
|  | 16 #include "base/metrics/histogram_macros.h" | 
| 16 #include "base/process/process.h" | 17 #include "base/process/process.h" | 
| 17 #include "base/process/process_info.h" | 18 #include "base/process/process_info.h" | 
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" | 
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" | 
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" | 
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" | 
| 22 #include "base/win/registry.h" | 23 #include "base/win/registry.h" | 
| 23 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" | 
| 24 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" | 
| 25 #include "chrome/browser/shell_integration.h" | 26 #include "chrome/browser/shell_integration.h" | 
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 274   } | 275   } | 
| 275 | 276 | 
| 276   // Time to take action. Kill the browser process. | 277   // Time to take action. Kill the browser process. | 
| 277   process.Terminate(content::RESULT_CODE_HUNG, true); | 278   process.Terminate(content::RESULT_CODE_HUNG, true); | 
| 278   remote_window_ = NULL; | 279   remote_window_ = NULL; | 
| 279   return PROCESS_NONE; | 280   return PROCESS_NONE; | 
| 280 } | 281 } | 
| 281 | 282 | 
| 282 ProcessSingleton::NotifyResult | 283 ProcessSingleton::NotifyResult | 
| 283 ProcessSingleton::NotifyOtherProcessOrCreate() { | 284 ProcessSingleton::NotifyOtherProcessOrCreate() { | 
|  | 285   const base::TimeTicks begin_ticks = base::TimeTicks::Now(); | 
| 284   for (int i = 0; i < 2; ++i) { | 286   for (int i = 0; i < 2; ++i) { | 
| 285     if (Create()) { | 287     if (Create()) { | 
|  | 288       UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToCreate", | 
|  | 289                                  base::TimeTicks::Now() - begin_ticks); | 
| 286       return PROCESS_NONE;  // This is the single browser process. | 290       return PROCESS_NONE;  // This is the single browser process. | 
| 287     } | 291     } | 
| 288     ProcessSingleton::NotifyResult result = NotifyOtherProcess(); | 292     ProcessSingleton::NotifyResult result = NotifyOtherProcess(); | 
| 289     if (result == PROCESS_NOTIFIED || result == LOCK_ERROR) { | 293     if (result == PROCESS_NOTIFIED || result == LOCK_ERROR) { | 
|  | 294       if (result == PROCESS_NOTIFIED) { | 
|  | 295         UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToNotify", | 
|  | 296                                    base::TimeTicks::Now() - begin_ticks); | 
|  | 297       } else { | 
|  | 298         UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToFailure", | 
|  | 299                                    base::TimeTicks::Now() - begin_ticks); | 
|  | 300       } | 
| 290       // The single browser process was notified, the user chose not to | 301       // The single browser process was notified, the user chose not to | 
| 291       // terminate a hung browser, or the lock file could not be created. | 302       // terminate a hung browser, or the lock file could not be created. | 
| 292       // Nothing more to do. | 303       // Nothing more to do. | 
| 293       return result; | 304       return result; | 
| 294     } | 305     } | 
| 295     DCHECK_EQ(PROCESS_NONE, result); | 306     DCHECK_EQ(PROCESS_NONE, result); | 
| 296     // The process could not be notified for some reason, or it was hung and | 307     // The process could not be notified for some reason, or it was hung and | 
| 297     // terminated. Retry once if this is the first time; otherwise, fall through | 308     // terminated. Retry once if this is the first time; otherwise, fall through | 
| 298     // to report that the process must exit because the profile is in use. | 309     // to report that the process must exit because the profile is in use. | 
| 299   } | 310   } | 
|  | 311   UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToFailure", | 
|  | 312                              base::TimeTicks::Now() - begin_ticks); | 
| 300   return PROFILE_IN_USE; | 313   return PROFILE_IN_USE; | 
| 301 } | 314 } | 
| 302 | 315 | 
| 303 // Look for a Chrome instance that uses the same profile directory. If there | 316 // Look for a Chrome instance that uses the same profile directory. If there | 
| 304 // isn't one, create a message window with its title set to the profile | 317 // isn't one, create a message window with its title set to the profile | 
| 305 // directory path. | 318 // directory path. | 
| 306 bool ProcessSingleton::Create() { | 319 bool ProcessSingleton::Create() { | 
| 307   static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; | 320   static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; | 
| 308 | 321 | 
| 309   remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 322   remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 359   return window_.hwnd() != NULL; | 372   return window_.hwnd() != NULL; | 
| 360 } | 373 } | 
| 361 | 374 | 
| 362 void ProcessSingleton::Cleanup() { | 375 void ProcessSingleton::Cleanup() { | 
| 363 } | 376 } | 
| 364 | 377 | 
| 365 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 378 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 
| 366     const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 379     const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 
| 367   should_kill_remote_process_callback_ = display_dialog_callback; | 380   should_kill_remote_process_callback_ = display_dialog_callback; | 
| 368 } | 381 } | 
| OLD | NEW | 
|---|