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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 ::Sleep(10); | 248 ::Sleep(10); |
249 } | 249 } |
250 return true; | 250 return true; |
251 } | 251 } |
252 return false; | 252 return false; |
253 } | 253 } |
254 | 254 |
255 ProcessSingleton::ProcessSingleton( | 255 ProcessSingleton::ProcessSingleton( |
256 const base::FilePath& user_data_dir, | 256 const base::FilePath& user_data_dir, |
257 const NotificationCallback& notification_callback) | 257 const NotificationCallback& notification_callback) |
258 : window_(NULL), locked_(false), foreground_window_(NULL), | 258 : window_(NULL), notification_callback_(notification_callback), |
259 notification_callback_(notification_callback), | |
260 is_virtualized_(false), lock_file_(INVALID_HANDLE_VALUE), | 259 is_virtualized_(false), lock_file_(INVALID_HANDLE_VALUE), |
261 user_data_dir_(user_data_dir) { | 260 user_data_dir_(user_data_dir) { |
262 } | 261 } |
263 | 262 |
264 ProcessSingleton::~ProcessSingleton() { | 263 ProcessSingleton::~ProcessSingleton() { |
265 // We need to unregister the window as late as possible so that we can detect | 264 // We need to unregister the window as late as possible so that we can detect |
266 // another instance of chrome running. Otherwise we may end up writing out | 265 // another instance of chrome running. Otherwise we may end up writing out |
267 // data while a new chrome is starting up. | 266 // data while a new chrome is starting up. |
268 if (window_) { | 267 if (window_) { |
269 ::DestroyWindow(window_); | 268 ::DestroyWindow(window_); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 529 } |
531 } | 530 } |
532 | 531 |
533 return window_ != NULL; | 532 return window_ != NULL; |
534 } | 533 } |
535 | 534 |
536 void ProcessSingleton::Cleanup() { | 535 void ProcessSingleton::Cleanup() { |
537 } | 536 } |
538 | 537 |
539 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { | 538 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { |
540 // If locked, it means we are not ready to process this message because | |
541 // we are probably in a first run critical phase. | |
542 if (locked_) { | |
543 #if defined(USE_AURA) | |
544 NOTIMPLEMENTED(); | |
545 #else | |
546 // Attempt to place ourselves in the foreground / flash the task bar. | |
547 if (foreground_window_ != NULL && IsWindow(foreground_window_)) { | |
548 DoSetForegroundWindow(foreground_window_); | |
549 } else { | |
550 // Read the command line and store it. It will be replayed when the | |
551 // ProcessSingleton becomes unlocked. | |
552 CommandLine parsed_command_line(CommandLine::NO_PROGRAM); | |
553 base::FilePath current_directory; | |
554 if (ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) | |
555 saved_startup_messages_.push_back( | |
556 std::make_pair(parsed_command_line.argv(), current_directory)); | |
557 } | |
558 #endif | |
559 return TRUE; | |
560 } | |
561 | |
562 CommandLine parsed_command_line(CommandLine::NO_PROGRAM); | 539 CommandLine parsed_command_line(CommandLine::NO_PROGRAM); |
563 base::FilePath current_directory; | 540 base::FilePath current_directory; |
564 if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) | 541 if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) |
565 return TRUE; | 542 return TRUE; |
566 return notification_callback_.Run(parsed_command_line, current_directory) ? | 543 return notification_callback_.Run(parsed_command_line, current_directory) ? |
567 TRUE : FALSE; | 544 TRUE : FALSE; |
568 } | 545 } |
569 | 546 |
570 void ProcessSingleton::DoSetForegroundWindow(HWND target_window) { | |
571 ::SetForegroundWindow(target_window); | |
572 } | |
573 | |
574 LRESULT ProcessSingleton::WndProc(HWND hwnd, UINT message, | 547 LRESULT ProcessSingleton::WndProc(HWND hwnd, UINT message, |
575 WPARAM wparam, LPARAM lparam) { | 548 WPARAM wparam, LPARAM lparam) { |
576 switch (message) { | 549 switch (message) { |
577 case WM_COPYDATA: | 550 case WM_COPYDATA: |
578 return OnCopyData(reinterpret_cast<HWND>(wparam), | 551 return OnCopyData(reinterpret_cast<HWND>(wparam), |
579 reinterpret_cast<COPYDATASTRUCT*>(lparam)); | 552 reinterpret_cast<COPYDATASTRUCT*>(lparam)); |
580 default: | 553 default: |
581 break; | 554 break; |
582 } | 555 } |
583 | 556 |
584 return ::DefWindowProc(hwnd, message, wparam, lparam); | 557 return ::DefWindowProc(hwnd, message, wparam, lparam); |
585 } | 558 } |
OLD | NEW |