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

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

Issue 1708343002: Add ScopedKeepAlive to c/b/lifetime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove KeepAliveOrigin::TEST Created 4 years, 9 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
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 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_
6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/background/background_application_list_model.h" 17 #include "chrome/browser/background/background_application_list_model.h"
18 #include "chrome/browser/lifetime/scoped_keep_alive.h"
18 #include "chrome/browser/profiles/profile_attributes_storage.h" 19 #include "chrome/browser/profiles/profile_attributes_storage.h"
19 #include "chrome/browser/status_icons/status_icon.h" 20 #include "chrome/browser/status_icons/status_icon.h"
20 #include "chrome/browser/status_icons/status_icon_menu_model.h" 21 #include "chrome/browser/status_icons/status_icon_menu_model.h"
21 #include "chrome/browser/ui/browser_list_observer.h" 22 #include "chrome/browser/ui/browser_list_observer.h"
22 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
23 #include "components/prefs/pref_change_registrar.h" 24 #include "components/prefs/pref_change_registrar.h"
24 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
26 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
27 28
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void StartBackgroundMode(); 311 void StartBackgroundMode();
311 312
312 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in 313 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in
313 // the background and removes its status bar icon. 314 // the background and removes its status bar icon.
314 void EndBackgroundMode(); 315 void EndBackgroundMode();
315 316
316 // Enables keep alive and the status tray icon if and only if background mode 317 // Enables keep alive and the status tray icon if and only if background mode
317 // is active and not suspended. 318 // is active and not suspended.
318 virtual void UpdateKeepAliveAndTrayIcon(); 319 virtual void UpdateKeepAliveAndTrayIcon();
319 320
321 // Release keep_alive_for_startup_. This is invoked as a callback to make
322 // make sure the message queue was initialized before we attempt to exit.
323 void ReleaseStartupKeepAliveCallback();
324
320 // If --no-startup-window is passed, BackgroundModeManager will manually keep 325 // If --no-startup-window is passed, BackgroundModeManager will manually keep
321 // chrome running while waiting for apps to load. This is called when we no 326 // chrome running while waiting for apps to load. This is called when we no
322 // longer need to do this (either because the user has chosen to exit chrome 327 // longer need to do this (either because the user has chosen to exit chrome
323 // manually, or all apps have been loaded). 328 // manually, or all apps have been loaded).
324 void DecrementKeepAliveCountForStartup(); 329 void ReleaseStartupKeepAlive();
325 330
326 // Return an appropriate name for a Preferences menu entry. Preferences is 331 // Return an appropriate name for a Preferences menu entry. Preferences is
327 // sometimes called Options or Settings. 332 // sometimes called Options or Settings.
328 base::string16 GetPreferencesMenuLabel(); 333 base::string16 GetPreferencesMenuLabel();
329 334
330 // Create a status tray icon to allow the user to shutdown Chrome when running 335 // Create a status tray icon to allow the user to shutdown Chrome when running
331 // in background mode. Virtual to enable testing. 336 // in background mode. Virtual to enable testing.
332 virtual void CreateStatusTrayIcon(); 337 virtual void CreateStatusTrayIcon();
333 338
334 // Removes the status tray icon because we are exiting background mode. 339 // Removes the status tray icon because we are exiting background mode.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 411
407 // Reference to our status icon's context menu (if any) - owned by the 412 // Reference to our status icon's context menu (if any) - owned by the
408 // status_icon_. 413 // status_icon_.
409 StatusIconMenuModel* context_menu_; 414 StatusIconMenuModel* context_menu_;
410 415
411 // Set to true when we are running in background mode. Allows us to track our 416 // Set to true when we are running in background mode. Allows us to track our
412 // current background state so we can take the appropriate action when the 417 // current background state so we can take the appropriate action when the
413 // user disables/enables background mode via preferences. 418 // user disables/enables background mode via preferences.
414 bool in_background_mode_; 419 bool in_background_mode_;
415 420
421 // Background mode does not always keep Chrome alive. When it does, it is
422 // using this scoped object.
423 scoped_ptr<ScopedKeepAlive> keep_alive_;
424
416 // Set when we are keeping chrome running during the startup process - this 425 // Set when we are keeping chrome running during the startup process - this
417 // is required when running with the --no-startup-window flag, as otherwise 426 // is required when running with the --no-startup-window flag, as otherwise
418 // chrome would immediately exit due to having no open windows. 427 // chrome would immediately exit due to having no open windows.
419 bool keep_alive_for_startup_; 428 scoped_ptr<ScopedKeepAlive> keep_alive_for_startup_;
420 429
421 // Set to true when Chrome is running with the --keep-alive-for-test flag 430 // Set to true when Chrome is running with the --keep-alive-for-test flag
422 // (used for testing background mode without having to install a background 431 // (used for testing background mode without having to install a background
423 // app). 432 // app).
424 bool keep_alive_for_test_; 433 bool keep_alive_for_test_;
425 434
426 // Set to true when background mode is suspended. 435 // Set to true when background mode is suspended.
427 bool background_mode_suspended_; 436 bool background_mode_suspended_;
428 437
429 // Set to true when background mode is keeping Chrome alive.
430 bool keeping_alive_;
431
432 base::WeakPtrFactory<BackgroundModeManager> weak_factory_; 438 base::WeakPtrFactory<BackgroundModeManager> weak_factory_;
433 439
434 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); 440 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager);
435 }; 441 };
436 442
437 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ 443 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/apps/scoped_keep_alive.cc ('k') | chrome/browser/background/background_mode_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698