• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
6 
7 #include "base/memory/singleton.h"
8 
AddDialog(AppModalDialog * dialog)9 void AppModalDialogQueue::AddDialog(AppModalDialog* dialog) {
10   if (!active_dialog_) {
11     ShowModalDialog(dialog);
12     return;
13   }
14   app_modal_dialog_queue_.push(dialog);
15 }
16 
ShowNextDialog()17 void AppModalDialogQueue::ShowNextDialog() {
18   AppModalDialog* dialog = GetNextDialog();
19   if (dialog)
20     ShowModalDialog(dialog);
21   else
22     active_dialog_ = NULL;
23 }
24 
ActivateModalDialog()25 void AppModalDialogQueue::ActivateModalDialog() {
26   if (showing_modal_dialog_) {
27     // As part of showing a modal dialog we may end up back in this method
28     // (showing a dialog activates the TabContents, which can trigger a call
29     // to ActivateModalDialog). We ignore such a request as after the call to
30     // activate the tab contents the dialog is shown.
31     return;
32   }
33   if (active_dialog_)
34     active_dialog_->ActivateModalDialog();
35 }
36 
AppModalDialogQueue()37 AppModalDialogQueue::AppModalDialogQueue()
38     : active_dialog_(NULL), showing_modal_dialog_(false) {
39 }
40 
~AppModalDialogQueue()41 AppModalDialogQueue::~AppModalDialogQueue() {}
42 
43 // static
GetInstance()44 AppModalDialogQueue* AppModalDialogQueue::GetInstance() {
45   return Singleton<AppModalDialogQueue>::get();
46 }
47 
ShowModalDialog(AppModalDialog * dialog)48 void AppModalDialogQueue::ShowModalDialog(AppModalDialog* dialog) {
49   // Be sure and set the active_dialog_ field first, otherwise if
50   // ShowModalDialog triggers a call back to the queue they'll get the old
51   // dialog. Also, if the dialog calls |ShowNextDialog()| before returning, that
52   // would write NULL into |active_dialog_| and this function would then undo
53   // that.
54   active_dialog_ = dialog;
55   showing_modal_dialog_ = true;
56   dialog->ShowModalDialog();
57   showing_modal_dialog_ = false;
58 }
59 
GetNextDialog()60 AppModalDialog* AppModalDialogQueue::GetNextDialog() {
61   while (!app_modal_dialog_queue_.empty()) {
62     AppModalDialog* dialog = app_modal_dialog_queue_.front();
63     app_modal_dialog_queue_.pop();
64     if (dialog->IsValid())
65       return dialog;
66     delete dialog;
67   }
68   return NULL;
69 }
70