Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / process_singleton_modal_dialog_lock.cc
blob98627c18aeb9c6ab9669a94c14086204c0a25a32
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/process_singleton_modal_dialog_lock.h"
7 #if defined(OS_WIN)
8 #include <Windows.h>
9 #endif
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/files/file_path.h"
14 #include "base/logging.h"
16 namespace {
18 #if !defined(OS_WIN) || defined(USE_AURA)
19 void DoSetForegroundWindow(gfx::NativeWindow /* target_window */) {
20 NOTREACHED();
22 #else
23 void DoSetForegroundWindow(HWND target_window) {
24 ::SetForegroundWindow(target_window);
26 #endif
28 } // namespace
30 ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock(
31 const ProcessSingleton::NotificationCallback& original_callback)
32 : active_dialog_(NULL),
33 original_callback_(original_callback),
34 set_foreground_window_handler_(base::Bind(&DoSetForegroundWindow)) {}
36 ProcessSingletonModalDialogLock::ProcessSingletonModalDialogLock(
37 const ProcessSingleton::NotificationCallback& original_callback,
38 const SetForegroundWindowHandler& set_foreground_window_handler)
39 : active_dialog_(NULL),
40 original_callback_(original_callback),
41 set_foreground_window_handler_(set_foreground_window_handler) {}
43 ProcessSingletonModalDialogLock::~ProcessSingletonModalDialogLock() {}
45 void ProcessSingletonModalDialogLock::SetActiveModalDialog(
46 gfx::NativeWindow active_dialog) {
47 active_dialog_ = active_dialog;
50 ProcessSingleton::NotificationCallback
51 ProcessSingletonModalDialogLock::AsNotificationCallback() {
52 return base::Bind(&ProcessSingletonModalDialogLock::NotificationCallbackImpl,
53 base::Unretained(this));
56 bool ProcessSingletonModalDialogLock::NotificationCallbackImpl(
57 const base::CommandLine& command_line,
58 const base::FilePath& current_directory) {
59 if (active_dialog_ != NULL) {
60 set_foreground_window_handler_.Run(active_dialog_);
61 return true;
62 } else {
63 return original_callback_.Run(command_line, current_directory);