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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/background/background_mode_optimizer.h
diff --git a/chrome/browser/background/background_mode_optimizer.h b/chrome/browser/background/background_mode_optimizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b2468b1fd781eeb2a07966a586de3c2d09c9f89b
--- /dev/null
+++ b/chrome/browser/background/background_mode_optimizer.h
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_
+#define CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "chrome/browser/lifetime/keep_alive_state_observer.h"
+#include "chrome/browser/ui/browser_list_observer.h"
+
+class Browser;
+
+// BackgroundModeOptimizer is responsible for applying some optimizations to
+// save resources (memory) when Chrome runs in background-only mode.
+// It tries to restart the browser to release accumulated memory when it
+// is considered non distruptive.
+class BackgroundModeOptimizer : public KeepAliveStateObserver,
+ chrome::BrowserListObserver {
+ public:
+ ~BackgroundModeOptimizer() override;
+
+ // Creates a new BackgroundModeOptimizer. Can return null if optimizations
+ // are not supported.
+ static std::unique_ptr<BackgroundModeOptimizer> Create();
+
+ // KeepAliveStateObserver implementation
+ void OnKeepAliveStateChanged(bool is_keeping_alive) override;
+ void OnKeepAliveRestartStateChanged(bool can_restart) override;
+
+ // chrome::BrowserListObserver implementation.
+ void OnBrowserAdded(Browser* browser) override;
+
+ private:
+ friend class DummyBackgroundModeOptimizer;
+
+ BackgroundModeOptimizer();
+
+ // Calls DoRestart() if the current state of the process allows it.
+ void TryBrowserRestart();
+
+ // Stop the browser and restart it in background mode.
+ // Virtual for testing purposes.
+ virtual void DoRestart();
+
+ bool browser_was_added_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundModeOptimizer);
+};
+
+#endif // CHROME_BROWSER_BACKGROUND_BACKGROUND_MODE_OPTIMIZER_H_
« 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