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

Side by Side Diff: chrome/browser/background/background_mode_manager.cc

Issue 12096060: browser: Start moving application_lifetime.h functions into chrome namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged, 177 base::Bind(&BackgroundModeManager::OnBackgroundModeEnabledPrefChanged,
178 base::Unretained(this))); 178 base::Unretained(this)));
179 } 179 }
180 180
181 // Keep the browser alive until extensions are done loading - this is needed 181 // Keep the browser alive until extensions are done loading - this is needed
182 // by the --no-startup-window flag. We want to stay alive until we load 182 // by the --no-startup-window flag. We want to stay alive until we load
183 // extensions, at which point we should either run in background mode (if 183 // extensions, at which point we should either run in background mode (if
184 // there are background apps) or exit if there are none. 184 // there are background apps) or exit if there are none.
185 if (command_line->HasSwitch(switches::kNoStartupWindow)) { 185 if (command_line->HasSwitch(switches::kNoStartupWindow)) {
186 keep_alive_for_startup_ = true; 186 keep_alive_for_startup_ = true;
187 browser::StartKeepAlive(); 187 chrome::StartKeepAlive();
188 } 188 }
189 189
190 // If the -keep-alive-for-test flag is passed, then always keep chrome running 190 // If the -keep-alive-for-test flag is passed, then always keep chrome running
191 // in the background until the user explicitly terminates it. 191 // in the background until the user explicitly terminates it.
192 if (command_line->HasSwitch(switches::kKeepAliveForTest)) 192 if (command_line->HasSwitch(switches::kKeepAliveForTest))
193 keep_alive_for_test_ = true; 193 keep_alive_for_test_ = true;
194 194
195 if (ShouldBeInBackgroundMode()) 195 if (ShouldBeInBackgroundMode())
196 StartBackgroundMode(); 196 StartBackgroundMode();
197 197
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 chrome::OpenTaskManager(bmd->GetBrowserWindow(), true); 497 chrome::OpenTaskManager(bmd->GetBrowserWindow(), true);
498 break; 498 break;
499 case IDC_EXIT: 499 case IDC_EXIT:
500 content::RecordAction(UserMetricsAction("Exit")); 500 content::RecordAction(UserMetricsAction("Exit"));
501 browser::AttemptExit(); 501 browser::AttemptExit();
502 break; 502 break;
503 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { 503 case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: {
504 // Background mode must already be enabled (as otherwise this menu would 504 // Background mode must already be enabled (as otherwise this menu would
505 // not be visible). 505 // not be visible).
506 DCHECK(IsBackgroundModePrefEnabled()); 506 DCHECK(IsBackgroundModePrefEnabled());
507 DCHECK(browser::WillKeepAlive()); 507 DCHECK(chrome::WillKeepAlive());
508 508
509 // Set the background mode pref to "disabled" - the resulting notification 509 // Set the background mode pref to "disabled" - the resulting notification
510 // will result in a call to DisableBackgroundMode(). 510 // will result in a call to DisableBackgroundMode().
511 PrefService* service = g_browser_process->local_state(); 511 PrefService* service = g_browser_process->local_state();
512 DCHECK(service); 512 DCHECK(service);
513 service->SetBoolean(prefs::kBackgroundModeEnabled, false); 513 service->SetBoolean(prefs::kBackgroundModeEnabled, false);
514 break; 514 break;
515 } 515 }
516 default: 516 default:
517 bmd->ExecuteCommand(command_id); 517 bmd->ExecuteCommand(command_id);
518 break; 518 break;
519 } 519 }
520 } 520 }
521 521
522 522
523 /////////////////////////////////////////////////////////////////////////////// 523 ///////////////////////////////////////////////////////////////////////////////
524 // BackgroundModeManager, private 524 // BackgroundModeManager, private
525 void BackgroundModeManager::EndKeepAliveForStartup() { 525 void BackgroundModeManager::EndKeepAliveForStartup() {
526 if (keep_alive_for_startup_) { 526 if (keep_alive_for_startup_) {
527 keep_alive_for_startup_ = false; 527 keep_alive_for_startup_ = false;
528 // We call this via the message queue to make sure we don't try to end 528 // We call this via the message queue to make sure we don't try to end
529 // keep-alive (which can shutdown Chrome) before the message loop has 529 // keep-alive (which can shutdown Chrome) before the message loop has
530 // started. 530 // started.
531 MessageLoop::current()->PostTask( 531 MessageLoop::current()->PostTask(FROM_HERE,
532 FROM_HERE, base::Bind(&browser::EndKeepAlive)); 532 base::Bind(&chrome::EndKeepAlive));
533 } 533 }
534 } 534 }
535 535
536 void BackgroundModeManager::StartBackgroundMode() { 536 void BackgroundModeManager::StartBackgroundMode() {
537 DCHECK(ShouldBeInBackgroundMode()); 537 DCHECK(ShouldBeInBackgroundMode());
538 // Don't bother putting ourselves in background mode if we're already there 538 // Don't bother putting ourselves in background mode if we're already there
539 // or if background mode is disabled. 539 // or if background mode is disabled.
540 if (in_background_mode_) 540 if (in_background_mode_)
541 return; 541 return;
542 542
543 // Mark ourselves as running in background mode. 543 // Mark ourselves as running in background mode.
544 in_background_mode_ = true; 544 in_background_mode_ = true;
545 545
546 // Put ourselves in KeepAlive mode and create a status tray icon. 546 // Put ourselves in KeepAlive mode and create a status tray icon.
547 browser::StartKeepAlive(); 547 chrome::StartKeepAlive();
548 548
549 // Display a status icon to exit Chrome. 549 // Display a status icon to exit Chrome.
550 InitStatusTrayIcon(); 550 InitStatusTrayIcon();
551 551
552 content::NotificationService::current()->Notify( 552 content::NotificationService::current()->Notify(
553 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, 553 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED,
554 content::Source<BackgroundModeManager>(this), 554 content::Source<BackgroundModeManager>(this),
555 content::Details<bool>(&in_background_mode_)); 555 content::Details<bool>(&in_background_mode_));
556 } 556 }
557 557
558 void BackgroundModeManager::InitStatusTrayIcon() { 558 void BackgroundModeManager::InitStatusTrayIcon() {
559 // Only initialize status tray icons for those profiles which actually 559 // Only initialize status tray icons for those profiles which actually
560 // have a background app running. 560 // have a background app running.
561 if (ShouldBeInBackgroundMode()) 561 if (ShouldBeInBackgroundMode())
562 CreateStatusTrayIcon(); 562 CreateStatusTrayIcon();
563 } 563 }
564 564
565 void BackgroundModeManager::EndBackgroundMode() { 565 void BackgroundModeManager::EndBackgroundMode() {
566 if (!in_background_mode_) 566 if (!in_background_mode_)
567 return; 567 return;
568 in_background_mode_ = false; 568 in_background_mode_ = false;
569 569
570 // End KeepAlive mode and blow away our status tray icon. 570 // End KeepAlive mode and blow away our status tray icon.
571 browser::EndKeepAlive(); 571 chrome::EndKeepAlive();
572 572
573 RemoveStatusTrayIcon(); 573 RemoveStatusTrayIcon();
574 content::NotificationService::current()->Notify( 574 content::NotificationService::current()->Notify(
575 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, 575 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED,
576 content::Source<BackgroundModeManager>(this), 576 content::Source<BackgroundModeManager>(this),
577 content::Details<bool>(&in_background_mode_)); 577 content::Details<bool>(&in_background_mode_));
578 } 578 }
579 579
580 void BackgroundModeManager::EnableBackgroundMode() { 580 void BackgroundModeManager::EnableBackgroundMode() {
581 DCHECK(IsBackgroundModePrefEnabled()); 581 DCHECK(IsBackgroundModePrefEnabled());
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 770 }
771 } 771 }
772 return profile_it; 772 return profile_it;
773 } 773 }
774 774
775 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { 775 bool BackgroundModeManager::IsBackgroundModePrefEnabled() const {
776 PrefService* service = g_browser_process->local_state(); 776 PrefService* service = g_browser_process->local_state();
777 DCHECK(service); 777 DCHECK(service);
778 return service->GetBoolean(prefs::kBackgroundModeEnabled); 778 return service->GetBoolean(prefs::kBackgroundModeEnabled);
779 } 779 }
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | chrome/browser/background/background_mode_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698