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

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

Issue 1931503002: Add BackgroundModeOptimizer that can restart the browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushKeepAlive
Patch Set: Switch the flag to disabled by default Created 4 years, 7 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 <memory>
9 #include <set> 10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/background/background_application_list_model.h" 18 #include "chrome/browser/background/background_application_list_model.h"
18 #include "chrome/browser/lifetime/scoped_keep_alive.h" 19 #include "chrome/browser/lifetime/scoped_keep_alive.h"
19 #include "chrome/browser/profiles/profile_attributes_storage.h" 20 #include "chrome/browser/profiles/profile_attributes_storage.h"
20 #include "chrome/browser/status_icons/status_icon.h" 21 #include "chrome/browser/status_icons/status_icon.h"
21 #include "chrome/browser/status_icons/status_icon_menu_model.h" 22 #include "chrome/browser/status_icons/status_icon_menu_model.h"
22 #include "chrome/browser/ui/browser_list_observer.h" 23 #include "chrome/browser/ui/browser_list_observer.h"
23 #include "components/keyed_service/core/keyed_service.h" 24 #include "components/keyed_service/core/keyed_service.h"
24 #include "components/prefs/pref_change_registrar.h" 25 #include "components/prefs/pref_change_registrar.h"
25 #include "content/public/browser/notification_observer.h" 26 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 27 #include "content/public/browser/notification_registrar.h"
27 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
28 29
30 class BackgroundModeOptimizer;
29 class BackgroundTrigger; 31 class BackgroundTrigger;
30 class Browser; 32 class Browser;
31 class PrefRegistrySimple; 33 class PrefRegistrySimple;
32 class Profile; 34 class Profile;
33 class StatusIcon; 35 class StatusIcon;
34 class StatusTray; 36 class StatusTray;
35 37
36 namespace base { 38 namespace base {
37 class CommandLine; 39 class CommandLine;
38 } 40 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 82
81 // Suspends background mode until either ResumeBackgroundMode is called or 83 // Suspends background mode until either ResumeBackgroundMode is called or
82 // Chrome is restarted. This has the same effect as ending background mode 84 // Chrome is restarted. This has the same effect as ending background mode
83 // for the current browser session. 85 // for the current browser session.
84 virtual void SuspendBackgroundMode(); 86 virtual void SuspendBackgroundMode();
85 87
86 // Resumes background mode. This ends a suspension of background mode, but 88 // Resumes background mode. This ends a suspension of background mode, but
87 // will not start it if it is not enabled. 89 // will not start it if it is not enabled.
88 virtual void ResumeBackgroundMode(); 90 virtual void ResumeBackgroundMode();
89 91
92 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in
Bernhard Bauer 2016/05/19 08:56:56 Nit: capitalize "Chrome".
dgn 2016/06/20 17:45:18 Done.
93 // the background and removes its status bar icon.
94 void EndBackgroundMode();
sky 2016/05/18 19:23:05 Move implementation to match new position.
dgn 2016/06/20 17:45:18 Made this private as it was before, introduced ano
95
90 // For testing purposes. 96 // For testing purposes.
91 int NumberOfBackgroundModeData(); 97 int NumberOfBackgroundModeData();
92 98
93 // Registers |trigger| as a reason for enabling background mode. Does not 99 // Registers |trigger| as a reason for enabling background mode. Does not
94 // take ownership of |profile| or |trigger|. 100 // take ownership of |profile| or |trigger|.
95 void RegisterTrigger(Profile* profile, 101 void RegisterTrigger(Profile* profile,
96 BackgroundTrigger* trigger, 102 BackgroundTrigger* trigger,
97 bool should_notify_user); 103 bool should_notify_user);
98 104
99 // Unregisters |trigger| as a reason for enabling background mode. 105 // Unregisters |trigger| as a reason for enabling background mode.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 virtual void EnableLaunchOnStartup(bool should_launch); 309 virtual void EnableLaunchOnStartup(bool should_launch);
304 310
305 // Invoked when a client is installed so we can display a platform-specific 311 // Invoked when a client is installed so we can display a platform-specific
306 // notification. 312 // notification.
307 virtual void DisplayClientInstalledNotification(const base::string16& name); 313 virtual void DisplayClientInstalledNotification(const base::string16& name);
308 314
309 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background 315 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background
310 // and has a status bar icon. 316 // and has a status bar icon.
311 void StartBackgroundMode(); 317 void StartBackgroundMode();
312 318
313 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in
314 // the background and removes its status bar icon.
315 void EndBackgroundMode();
316
317 // Enables keep alive and the status tray icon if and only if background mode 319 // Enables keep alive and the status tray icon if and only if background mode
318 // is active and not suspended. 320 // is active and not suspended.
319 virtual void UpdateKeepAliveAndTrayIcon(); 321 virtual void UpdateKeepAliveAndTrayIcon();
320 322
321 // Release keep_alive_for_startup_. This is invoked as a callback to make 323 // 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. 324 // make sure the message queue was initialized before we attempt to exit.
323 void ReleaseStartupKeepAliveCallback(); 325 void ReleaseStartupKeepAliveCallback();
324 326
325 // If --no-startup-window is passed, BackgroundModeManager will manually keep 327 // If --no-startup-window is passed, BackgroundModeManager will manually keep
326 // chrome running while waiting for apps to load. This is called when we no 328 // chrome running while waiting for apps to load. This is called when we no
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 422
421 // Background mode does not always keep Chrome alive. When it does, it is 423 // Background mode does not always keep Chrome alive. When it does, it is
422 // using this scoped object. 424 // using this scoped object.
423 std::unique_ptr<ScopedKeepAlive> keep_alive_; 425 std::unique_ptr<ScopedKeepAlive> keep_alive_;
424 426
425 // Set when we are keeping chrome running during the startup process - this 427 // Set when we are keeping chrome running during the startup process - this
426 // is required when running with the --no-startup-window flag, as otherwise 428 // is required when running with the --no-startup-window flag, as otherwise
427 // chrome would immediately exit due to having no open windows. 429 // chrome would immediately exit due to having no open windows.
428 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_; 430 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_;
429 431
432 // Reference to the optimizer to use to reduce Chrome's footprint when in
433 // background mode. If null, optimizations are disabled.
434 std::unique_ptr<BackgroundModeOptimizer> optimizer_;
435
430 // Set to true when Chrome is running with the --keep-alive-for-test flag 436 // Set to true when Chrome is running with the --keep-alive-for-test flag
431 // (used for testing background mode without having to install a background 437 // (used for testing background mode without having to install a background
432 // app). 438 // app).
433 bool keep_alive_for_test_; 439 bool keep_alive_for_test_;
434 440
435 // Set to true when background mode is suspended. 441 // Set to true when background mode is suspended.
436 bool background_mode_suspended_; 442 bool background_mode_suspended_;
437 443
438 base::WeakPtrFactory<BackgroundModeManager> weak_factory_; 444 base::WeakPtrFactory<BackgroundModeManager> weak_factory_;
439 445
440 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); 446 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager);
441 }; 447 };
442 448
443 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ 449 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698