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
3 // found in the LICENSE file.
5 #ifndef APPS_APP_RESTORE_SERVICE_H_
6 #define APPS_APP_RESTORE_SERVICE_H_
11 #include "apps/app_lifetime_monitor.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "extensions/browser/app_window/app_window_registry.h"
15 namespace extensions {
25 // Tracks what apps need to be restarted when the browser restarts.
26 class AppRestoreService : public KeyedService,
27 public AppLifetimeMonitor::Observer {
29 // Returns true if apps should be restored on the current platform, given
30 // whether this new browser process launched due to a restart.
31 static bool ShouldRestoreApps(bool is_browser_restart);
33 explicit AppRestoreService(content::BrowserContext* context);
35 // Restart apps that need to be restarted and clear the "running" preference
36 // from apps to prevent them being restarted in subsequent restarts.
37 void HandleStartup(bool should_restore_apps);
39 // Returns whether this extension is running or, at startup, whether it was
40 // running when Chrome was last terminated.
41 bool IsAppRestorable(const std::string& extension_id);
43 // Called to notify that the application has begun to exit.
44 void OnApplicationTerminating();
46 static AppRestoreService* Get(content::BrowserContext* context);
49 // AppLifetimeMonitor::Observer.
50 void OnAppStart(content::BrowserContext* context,
51 const std::string& app_id) override;
52 void OnAppActivated(content::BrowserContext* context,
53 const std::string& app_id) override;
54 void OnAppDeactivated(content::BrowserContext* context,
55 const std::string& app_id) override;
56 void OnAppStop(content::BrowserContext* context,
57 const std::string& app_id) override;
60 void Shutdown() override;
62 void RecordAppStart(const std::string& extension_id);
63 void RecordAppStop(const std::string& extension_id);
64 void RecordAppActiveState(const std::string& id, bool is_active);
66 void RestoreApp(const extensions::Extension* extension);
68 void StartObservingAppLifetime();
69 void StopObservingAppLifetime();
71 content::BrowserContext* context_;
73 DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
78 #endif // APPS_APP_RESTORE_SERVICE_H_