OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_ |
| 6 #define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "chrome/browser/lifetime/keep_alive_state_observer.h" |
| 12 #include "chrome/browser/ui/browser_list_observer.h" |
| 13 |
| 14 class Browser; |
| 15 |
| 16 // BackgroundModeOptimizer is responsible for applying some optimizations to |
| 17 // save resources (memory) when Chrome runs in background-only mode. |
| 18 // It tries to restart the browser to release accumulated memory when it |
| 19 // is considered non distruptive. |
| 20 class BackgroundModeOptimizer : public KeepAliveStateObserver, |
| 21 chrome::BrowserListObserver { |
| 22 public: |
| 23 ~BackgroundModeOptimizer() override; |
| 24 |
| 25 // Creates a new BackgroundModeOptimizer. Can return null if optimizations |
| 26 // are not supported. |
| 27 static std::unique_ptr<BackgroundModeOptimizer> Create(); |
| 28 |
| 29 // KeepAliveStateObserver implementation |
| 30 void OnKeepAliveStateChanged(bool is_keeping_alive) override; |
| 31 void OnKeepAliveRestartStateChanged(bool can_restart) override; |
| 32 |
| 33 // chrome::BrowserListObserver implementation. |
| 34 void OnBrowserAdded(Browser* browser) override; |
| 35 |
| 36 private: |
| 37 friend class DummyBackgroundModeOptimizer; |
| 38 |
| 39 BackgroundModeOptimizer(); |
| 40 |
| 41 // Calls DoRestart() if the current state of the process allows it. |
| 42 void TryBrowserRestart(); |
| 43 |
| 44 // Stop the browser and restart it in background mode. |
| 45 // Virtual for testing purposes. |
| 46 virtual void DoRestart(); |
| 47 |
| 48 bool browser_was_added_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(BackgroundModeOptimizer); |
| 51 }; |
| 52 |
| 53 #endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_ |
OLD | NEW |