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

Unified Diff: chrome/browser/chromeos/login/ui/preloaded_web_view.h

Issue 2610373002: cros: Only preload the lock screen; do not reuse it. (Closed)
Patch Set: Initial upload Created 3 years, 11 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/chromeos/login/ui/preloaded_web_view.h
diff --git a/chrome/browser/chromeos/login/ui/preloaded_web_view.h b/chrome/browser/chromeos/login/ui/preloaded_web_view.h
new file mode 100644
index 0000000000000000000000000000000000000000..2dcab092ca745692bdd859133faf462cef0cf1bb
--- /dev/null
+++ b/chrome/browser/chromeos/login/ui/preloaded_web_view.h
@@ -0,0 +1,84 @@
+// 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_CHROMEOS_LOGIN_UI_PRELOADED_WEB_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_PRELOADED_WEB_VIEW_H_
+
+#include <memory>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/memory_pressure_listener.h"
+#include "base/memory/weak_ptr.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class Profile;
+
+namespace views {
+class WebView;
+}
+
+namespace chromeos {
+
+class IdleDetector;
+
+// Stores and fetches a views::WebView instance that is ulimately owned by the
+// signin profile. This allows for a WebView to be reused over time or
+// preloaded. Use PreloadedWebViewFactory to get an instance of this class.
+class PreloadedWebView : public KeyedService,
+ public content::NotificationObserver {
+ public:
+ explicit PreloadedWebView(Profile* profile);
+ ~PreloadedWebView() override;
+
+ using PreloadCallback =
+ base::OnceCallback<std::unique_ptr<views::WebView>(Profile*)>;
xiyuan 2017/01/06 17:14:25 nit: move this to the beginning of all declaration
jdufault 2017/01/13 19:46:58 Done.
+
+ // Executes the given |preload| function when the device is idle.
+ void PreloadOnIdle(PreloadCallback preload);
+
+ // Try to fetch a preloaded instance. Returns nullptr if no instance has been
+ // preloaded. Calling this function will cancel any pending preload.
+ std::unique_ptr<views::WebView> TryTake();
+
+ private:
+ // KeyedSerivce:
+ void Shutdown() override;
+
+ // content::NotificationObserver:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // Called when there is a memory pressure event.
+ void OnMemoryPressure(
+ base::MemoryPressureListener::MemoryPressureLevel level);
+
+ // Runs the preload function. Called only by |idle_detector_|.
+ void RunPreloader();
+
+ // Used to execute the preload function when the user is idle.
+ std::unique_ptr<IdleDetector> idle_detector_;
+ // The preload function. Can only be called once.
+ PreloadCallback preload_function_;
+ // The result of the preload function.
+ std::unique_ptr<views::WebView> preloaded_instance_;
+ // Profile passed into the preload function.
+ Profile* profile_;
+
+ // Used to destroy a preloaded but not used WebView on shutdown.
+ content::NotificationRegistrar registrar_;
+ // Used to destroy a preloaded but not used WebView on low-memory.
+ std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
+
+ base::WeakPtrFactory<PreloadedWebView> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PreloadedWebView);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_PRELOADED_WEB_VIEW_H_

Powered by Google App Engine
This is Rietveld 408576698