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

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: cleanup, enable by default (that's just to verify the tests) Created 4 years, 5 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/lifetime/scoped_keep_alive.h"
19 #include "chrome/browser/profiles/profile_attributes_storage.h" 19 #include "chrome/browser/profiles/profile_attributes_storage.h"
20 #include "chrome/browser/status_icons/status_icon.h" 20 #include "chrome/browser/status_icons/status_icon.h"
21 #include "chrome/browser/status_icons/status_icon_menu_model.h" 21 #include "chrome/browser/status_icons/status_icon_menu_model.h"
22 #include "chrome/browser/ui/browser_list_observer.h" 22 #include "chrome/browser/ui/browser_list_observer.h"
23 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
24 #include "components/prefs/pref_change_registrar.h" 24 #include "components/prefs/pref_change_registrar.h"
25 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
27 #include "extensions/common/extension_id.h" 27 #include "extensions/common/extension_id.h"
28 28
29 class BackgroundModeOptimizer;
29 class BackgroundTrigger; 30 class BackgroundTrigger;
30 class Browser; 31 class Browser;
31 class PrefRegistrySimple; 32 class PrefRegistrySimple;
32 class Profile; 33 class Profile;
33 class StatusIcon; 34 class StatusIcon;
34 class StatusTray; 35 class StatusTray;
35 36
36 namespace base { 37 namespace base {
37 class CommandLine; 38 class CommandLine;
38 } 39 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 virtual void RegisterProfile(Profile* profile); 74 virtual void RegisterProfile(Profile* profile);
74 75
75 static void LaunchBackgroundApplication(Profile* profile, 76 static void LaunchBackgroundApplication(Profile* profile,
76 const extensions::Extension* extension); 77 const extensions::Extension* extension);
77 78
78 // Gets a browser window for |profile| associated with the active desktop. 79 // Gets a browser window for |profile| associated with the active desktop.
79 // Opens a new browser window if there isn't one for the active desktop. 80 // Opens a new browser window if there isn't one for the active desktop.
80 static Browser* GetBrowserWindowForProfile(Profile* profile); 81 static Browser* GetBrowserWindowForProfile(Profile* profile);
81 82
83 // Getter and setter for the flag indicating whether Chrome should start in
84 // background mode the next time.
85 static bool ShouldRestartInBackground();
sky 2016/07/06 16:55:33 nit: inline these are these are trivially.
dgn 2016/07/22 15:18:09 Done.
86 static void SetShouldRestartInBackground(bool enable);
87
82 // Returns true if background mode is active. 88 // Returns true if background mode is active.
83 virtual bool IsBackgroundModeActive(); 89 virtual bool IsBackgroundModeActive();
84 90
85 // Suspends background mode until either ResumeBackgroundMode is called or 91 // Suspends background mode until either ResumeBackgroundMode is called or
86 // Chrome is restarted. This has the same effect as ending background mode 92 // Chrome is restarted. This has the same effect as ending background mode
87 // for the current browser session. 93 // for the current browser session.
88 virtual void SuspendBackgroundMode(); 94 virtual void SuspendBackgroundMode();
89 95
90 // Resumes background mode. This ends a suspension of background mode, but 96 // Resumes background mode. This ends a suspension of background mode, but
91 // will not start it if it is not enabled. 97 // will not start it if it is not enabled.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 virtual void EnableLaunchOnStartup(bool should_launch); 313 virtual void EnableLaunchOnStartup(bool should_launch);
308 314
309 // Invoked when a client is installed so we can display a platform-specific 315 // Invoked when a client is installed so we can display a platform-specific
310 // notification. 316 // notification.
311 virtual void DisplayClientInstalledNotification(const base::string16& name); 317 virtual void DisplayClientInstalledNotification(const base::string16& name);
312 318
313 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background 319 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background
314 // and has a status bar icon. 320 // and has a status bar icon.
315 void StartBackgroundMode(); 321 void StartBackgroundMode();
316 322
317 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in 323 // Invoked to take Chrome out of KeepAlive mode - Chrome stops running in
318 // the background and removes its status bar icon. 324 // the background and removes its status bar icon.
319 void EndBackgroundMode(); 325 void EndBackgroundMode();
320 326
321 // Enables keep alive and the status tray icon if and only if background mode 327 // Enables keep alive and the status tray icon if and only if background mode
322 // is active and not suspended. 328 // is active and not suspended.
323 virtual void UpdateKeepAliveAndTrayIcon(); 329 virtual void UpdateKeepAliveAndTrayIcon();
324 330
325 // Release keep_alive_for_startup_. This is invoked as a callback to make 331 // Release keep_alive_for_startup_. This is invoked as a callback to make
326 // make sure the message queue was initialized before we attempt to exit. 332 // make sure the message queue was initialized before we attempt to exit.
327 void ReleaseStartupKeepAliveCallback(); 333 void ReleaseStartupKeepAliveCallback();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Returns the number of pending triggers in the system, for all profiles. 388 // Returns the number of pending triggers in the system, for all profiles.
383 int GetPendingTriggerCount() const; 389 int GetPendingTriggerCount() const;
384 390
385 // Returns true if we should be in background mode. 391 // Returns true if we should be in background mode.
386 bool ShouldBeInBackgroundMode() const; 392 bool ShouldBeInBackgroundMode() const;
387 393
388 // Finds the BackgroundModeData associated with the last active profile, 394 // Finds the BackgroundModeData associated with the last active profile,
389 // if the profile isn't locked. Returns NULL otherwise. 395 // if the profile isn't locked. Returns NULL otherwise.
390 BackgroundModeData* GetBackgroundModeDataForLastProfile() const; 396 BackgroundModeData* GetBackgroundModeDataForLastProfile() const;
391 397
398 // Set to true when the next restart should be done in background mode.
399 // Static because its value is read after the background mode manager is
400 // destroyed.
401 static bool should_restart_in_background_;
402
392 // Reference to the ProfileAttributesStorage. It is used to update the 403 // Reference to the ProfileAttributesStorage. It is used to update the
393 // background app status of profiles when they open/close background apps. 404 // background app status of profiles when they open/close background apps.
394 ProfileAttributesStorage* profile_storage_; 405 ProfileAttributesStorage* profile_storage_;
395 406
396 // Registrars for managing our change observers. 407 // Registrars for managing our change observers.
397 content::NotificationRegistrar registrar_; 408 content::NotificationRegistrar registrar_;
398 PrefChangeRegistrar pref_registrar_; 409 PrefChangeRegistrar pref_registrar_;
399 410
400 // The profile-keyed data for this background mode manager. Keyed on profile. 411 // The profile-keyed data for this background mode manager. Keyed on profile.
401 BackgroundModeInfoMap background_mode_data_; 412 BackgroundModeInfoMap background_mode_data_;
(...skipping 22 matching lines...) Expand all
424 435
425 // Background mode does not always keep Chrome alive. When it does, it is 436 // Background mode does not always keep Chrome alive. When it does, it is
426 // using this scoped object. 437 // using this scoped object.
427 std::unique_ptr<ScopedKeepAlive> keep_alive_; 438 std::unique_ptr<ScopedKeepAlive> keep_alive_;
428 439
429 // Set when we are keeping chrome running during the startup process - this 440 // Set when we are keeping chrome running during the startup process - this
430 // is required when running with the --no-startup-window flag, as otherwise 441 // is required when running with the --no-startup-window flag, as otherwise
431 // chrome would immediately exit due to having no open windows. 442 // chrome would immediately exit due to having no open windows.
432 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_; 443 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_;
433 444
445 // Reference to the optimizer to use to reduce Chrome's footprint when in
446 // background mode. If null, optimizations are disabled.
447 std::unique_ptr<BackgroundModeOptimizer> optimizer_;
448
434 // Set to true when Chrome is running with the --keep-alive-for-test flag 449 // Set to true when Chrome is running with the --keep-alive-for-test flag
435 // (used for testing background mode without having to install a background 450 // (used for testing background mode without having to install a background
436 // app). 451 // app).
437 bool keep_alive_for_test_; 452 bool keep_alive_for_test_;
438 453
439 // Set to true when background mode is suspended. 454 // Set to true when background mode is suspended.
440 bool background_mode_suspended_; 455 bool background_mode_suspended_;
441 456
442 base::WeakPtrFactory<BackgroundModeManager> weak_factory_; 457 base::WeakPtrFactory<BackgroundModeManager> weak_factory_;
443 458
444 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); 459 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager);
445 }; 460 };
446 461
447 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ 462 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698