Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/process_singleton_win.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restrict chrome_process_singleton_unittest to WIN for now. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 530 }
532 } 531 }
533 532
534 return window_ != NULL; 533 return window_ != NULL;
535 } 534 }
536 535
537 void ProcessSingleton::Cleanup() { 536 void ProcessSingleton::Cleanup() {
538 } 537 }
539 538
540 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { 539 LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) {
541 // If locked, it means we are not ready to process this message because
542 // we are probably in a first run critical phase.
543 if (locked_) {
544 #if defined(USE_AURA)
545 NOTIMPLEMENTED();
546 #else
547 // Attempt to place ourselves in the foreground / flash the task bar.
548 if (foreground_window_ != NULL && ::IsWindow(foreground_window_)) {
549 DoSetForegroundWindow(foreground_window_);
550 } else {
551 // Read the command line and store it. It will be replayed when the
552 // ProcessSingleton becomes unlocked.
553 CommandLine parsed_command_line(CommandLine::NO_PROGRAM);
554 base::FilePath current_directory;
555 if (ParseCommandLine(cds, &parsed_command_line, &current_directory))
556 saved_startup_messages_.push_back(
557 std::make_pair(parsed_command_line.argv(), current_directory));
558 }
559 #endif
560 return TRUE;
561 }
562
563 CommandLine parsed_command_line(CommandLine::NO_PROGRAM); 540 CommandLine parsed_command_line(CommandLine::NO_PROGRAM);
564 base::FilePath current_directory; 541 base::FilePath current_directory;
565 if (!ParseCommandLine(cds, &parsed_command_line, &current_directory)) 542 if (!ParseCommandLine(cds, &parsed_command_line, &current_directory))
566 return TRUE; 543 return TRUE;
567 return notification_callback_.Run(parsed_command_line, current_directory) ? 544 return notification_callback_.Run(parsed_command_line, current_directory) ?
568 TRUE : FALSE; 545 TRUE : FALSE;
569 } 546 }
570 547
571 void ProcessSingleton::DoSetForegroundWindow(HWND target_window) {
572 ::SetForegroundWindow(target_window);
573 }
574
575 LRESULT ProcessSingleton::WndProc(HWND hwnd, UINT message, 548 LRESULT ProcessSingleton::WndProc(HWND hwnd, UINT message,
576 WPARAM wparam, LPARAM lparam) { 549 WPARAM wparam, LPARAM lparam) {
577 switch (message) { 550 switch (message) {
578 case WM_COPYDATA: 551 case WM_COPYDATA:
579 return OnCopyData(reinterpret_cast<HWND>(wparam), 552 return OnCopyData(reinterpret_cast<HWND>(wparam),
580 reinterpret_cast<COPYDATASTRUCT*>(lparam)); 553 reinterpret_cast<COPYDATASTRUCT*>(lparam));
581 default: 554 default:
582 break; 555 break;
583 } 556 }
584 557
585 return ::DefWindowProc(hwnd, message, wparam, lparam); 558 return ::DefWindowProc(hwnd, message, wparam, lparam);
586 } 559 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698