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

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

Issue 1931503002: Add BackgroundModeOptimizer that can restart the browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushKeepAlive
Patch Set: address comments. disable feature by default 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
(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_
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_manager_unittest.cc ('k') | chrome/browser/background/background_mode_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698