OLD | NEW |
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 Loading... |
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 should_restart_in_background() { |
| 86 return should_restart_in_background_; |
| 87 } |
| 88 |
| 89 static void set_should_restart_in_background(bool enable) { |
| 90 should_restart_in_background_ = enable; |
| 91 } |
| 92 |
82 // Returns true if background mode is active. | 93 // Returns true if background mode is active. |
83 virtual bool IsBackgroundModeActive(); | 94 virtual bool IsBackgroundModeActive(); |
84 | 95 |
85 // Suspends background mode until either ResumeBackgroundMode is called or | 96 // Suspends background mode until either ResumeBackgroundMode is called or |
86 // Chrome is restarted. This has the same effect as ending background mode | 97 // Chrome is restarted. This has the same effect as ending background mode |
87 // for the current browser session. | 98 // for the current browser session. |
88 virtual void SuspendBackgroundMode(); | 99 virtual void SuspendBackgroundMode(); |
89 | 100 |
90 // Resumes background mode. This ends a suspension of background mode, but | 101 // Resumes background mode. This ends a suspension of background mode, but |
91 // will not start it if it is not enabled. | 102 // will not start it if it is not enabled. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 virtual void EnableLaunchOnStartup(bool should_launch); | 318 virtual void EnableLaunchOnStartup(bool should_launch); |
308 | 319 |
309 // Invoked when a client is installed so we can display a platform-specific | 320 // Invoked when a client is installed so we can display a platform-specific |
310 // notification. | 321 // notification. |
311 virtual void DisplayClientInstalledNotification(const base::string16& name); | 322 virtual void DisplayClientInstalledNotification(const base::string16& name); |
312 | 323 |
313 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background | 324 // Invoked to put Chrome in KeepAlive mode - chrome runs in the background |
314 // and has a status bar icon. | 325 // and has a status bar icon. |
315 void StartBackgroundMode(); | 326 void StartBackgroundMode(); |
316 | 327 |
317 // Invoked to take Chrome out of KeepAlive mode - chrome stops running in | 328 // Invoked to take Chrome out of KeepAlive mode - Chrome stops running in |
318 // the background and removes its status bar icon. | 329 // the background and removes its status bar icon. |
319 void EndBackgroundMode(); | 330 void EndBackgroundMode(); |
320 | 331 |
321 // Enables keep alive and the status tray icon if and only if background mode | 332 // Enables keep alive and the status tray icon if and only if background mode |
322 // is active and not suspended. | 333 // is active and not suspended. |
323 virtual void UpdateKeepAliveAndTrayIcon(); | 334 virtual void UpdateKeepAliveAndTrayIcon(); |
324 | 335 |
325 // Release keep_alive_for_startup_. This is invoked as a callback to make | 336 // 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. | 337 // make sure the message queue was initialized before we attempt to exit. |
327 void ReleaseStartupKeepAliveCallback(); | 338 void ReleaseStartupKeepAliveCallback(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 // Returns the number of pending triggers in the system, for all profiles. | 393 // Returns the number of pending triggers in the system, for all profiles. |
383 int GetPendingTriggerCount() const; | 394 int GetPendingTriggerCount() const; |
384 | 395 |
385 // Returns true if we should be in background mode. | 396 // Returns true if we should be in background mode. |
386 bool ShouldBeInBackgroundMode() const; | 397 bool ShouldBeInBackgroundMode() const; |
387 | 398 |
388 // Finds the BackgroundModeData associated with the last active profile, | 399 // Finds the BackgroundModeData associated with the last active profile, |
389 // if the profile isn't locked. Returns NULL otherwise. | 400 // if the profile isn't locked. Returns NULL otherwise. |
390 BackgroundModeData* GetBackgroundModeDataForLastProfile() const; | 401 BackgroundModeData* GetBackgroundModeDataForLastProfile() const; |
391 | 402 |
| 403 // Set to true when the next restart should be done in background mode. |
| 404 // Static because its value is read after the background mode manager is |
| 405 // destroyed. |
| 406 static bool should_restart_in_background_; |
| 407 |
392 // Reference to the ProfileAttributesStorage. It is used to update the | 408 // Reference to the ProfileAttributesStorage. It is used to update the |
393 // background app status of profiles when they open/close background apps. | 409 // background app status of profiles when they open/close background apps. |
394 ProfileAttributesStorage* profile_storage_; | 410 ProfileAttributesStorage* profile_storage_; |
395 | 411 |
396 // Registrars for managing our change observers. | 412 // Registrars for managing our change observers. |
397 content::NotificationRegistrar registrar_; | 413 content::NotificationRegistrar registrar_; |
398 PrefChangeRegistrar pref_registrar_; | 414 PrefChangeRegistrar pref_registrar_; |
399 | 415 |
400 // The profile-keyed data for this background mode manager. Keyed on profile. | 416 // The profile-keyed data for this background mode manager. Keyed on profile. |
401 BackgroundModeInfoMap background_mode_data_; | 417 BackgroundModeInfoMap background_mode_data_; |
(...skipping 22 matching lines...) Expand all Loading... |
424 | 440 |
425 // Background mode does not always keep Chrome alive. When it does, it is | 441 // Background mode does not always keep Chrome alive. When it does, it is |
426 // using this scoped object. | 442 // using this scoped object. |
427 std::unique_ptr<ScopedKeepAlive> keep_alive_; | 443 std::unique_ptr<ScopedKeepAlive> keep_alive_; |
428 | 444 |
429 // Set when we are keeping chrome running during the startup process - this | 445 // 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 | 446 // is required when running with the --no-startup-window flag, as otherwise |
431 // chrome would immediately exit due to having no open windows. | 447 // chrome would immediately exit due to having no open windows. |
432 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_; | 448 std::unique_ptr<ScopedKeepAlive> keep_alive_for_startup_; |
433 | 449 |
| 450 // Reference to the optimizer to use to reduce Chrome's footprint when in |
| 451 // background mode. If null, optimizations are disabled. |
| 452 std::unique_ptr<BackgroundModeOptimizer> optimizer_; |
| 453 |
434 // Set to true when Chrome is running with the --keep-alive-for-test flag | 454 // 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 | 455 // (used for testing background mode without having to install a background |
436 // app). | 456 // app). |
437 bool keep_alive_for_test_; | 457 bool keep_alive_for_test_; |
438 | 458 |
439 // Set to true when background mode is suspended. | 459 // Set to true when background mode is suspended. |
440 bool background_mode_suspended_; | 460 bool background_mode_suspended_; |
441 | 461 |
442 base::WeakPtrFactory<BackgroundModeManager> weak_factory_; | 462 base::WeakPtrFactory<BackgroundModeManager> weak_factory_; |
443 | 463 |
444 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); | 464 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
445 }; | 465 }; |
446 | 466 |
447 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ | 467 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_MANAGER_H_ |
OLD | NEW |