blob: fec9ed79295c640cb3c6697a681950c04ffb3823 [file] [log] [blame]
[email protected]28c3eeb2012-10-15 05:47:531// 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.
4
[email protected]eb5c9682013-03-04 02:55:005#ifndef APPS_APP_RESTORE_SERVICE_H_
6#define APPS_APP_RESTORE_SERVICE_H_
[email protected]28c3eeb2012-10-15 05:47:537
[email protected]c2e2b6d2013-01-22 02:23:298#include <string>
[email protected]eb5c9682013-03-04 02:55:009#include <vector>
[email protected]c2e2b6d2013-01-22 02:23:2910
[email protected]4b7111f22013-06-18 14:22:1211#include "apps/app_lifetime_monitor.h"
[email protected]12b7af32014-03-13 05:28:2012#include "components/keyed_service/core/keyed_service.h"
hashimotoad3c6872014-08-29 09:46:5713#include "extensions/browser/app_window/app_window_registry.h"
[email protected]28c3eeb2012-10-15 05:47:5314
[email protected]b8816a42013-02-27 07:59:0015namespace extensions {
16class Extension;
[email protected]b897ff82013-02-27 19:50:1317}
18
19class Profile;
20
[email protected]c2e2b6d2013-01-22 02:23:2921namespace apps {
[email protected]28c3eeb2012-10-15 05:47:5322
23// Tracks what apps need to be restarted when the browser restarts.
[email protected]12b7af32014-03-13 05:28:2024class AppRestoreService : public KeyedService,
[email protected]4b7111f22013-06-18 14:22:1225 public AppLifetimeMonitor::Observer {
[email protected]28c3eeb2012-10-15 05:47:5326 public:
[email protected]24ced7dc02013-04-04 08:32:3927 // Returns true if apps should be restored on the current platform, given
28 // whether this new browser process launched due to a restart.
29 static bool ShouldRestoreApps(bool is_browser_restart);
30
[email protected]28c3eeb2012-10-15 05:47:5331 explicit AppRestoreService(Profile* profile);
32
[email protected]119454622012-10-18 09:48:3233 // Restart apps that need to be restarted and clear the "running" preference
34 // from apps to prevent them being restarted in subsequent restarts.
[email protected]300ba0c42012-12-06 06:57:1735 void HandleStartup(bool should_restore_apps);
[email protected]28c3eeb2012-10-15 05:47:5336
[email protected]a2886e8b2013-06-08 05:15:0237 // Returns whether this extension is running or, at startup, whether it was
38 // running when Chrome was last terminated.
39 bool IsAppRestorable(const std::string& extension_id);
40
41 static AppRestoreService* Get(Profile* profile);
42
[email protected]28c3eeb2012-10-15 05:47:5343 private:
[email protected]4b7111f22013-06-18 14:22:1244 // AppLifetimeMonitor::Observer.
dcheng2f5be412014-10-22 01:46:0845 void OnAppStart(Profile* profile, const std::string& app_id) override;
46 void OnAppActivated(Profile* profile, const std::string& app_id) override;
47 void OnAppDeactivated(Profile* profile, const std::string& app_id) override;
48 void OnAppStop(Profile* profile, const std::string& app_id) override;
49 void OnChromeTerminating() override;
[email protected]771c8d272013-05-17 09:47:4050
[email protected]12b7af32014-03-13 05:28:2051 // KeyedService.
dcheng2f5be412014-10-22 01:46:0852 void Shutdown() override;
[email protected]771c8d272013-05-17 09:47:4053
[email protected]28c3eeb2012-10-15 05:47:5354 void RecordAppStart(const std::string& extension_id);
55 void RecordAppStop(const std::string& extension_id);
[email protected]4b7111f22013-06-18 14:22:1256 void RecordAppActiveState(const std::string& id, bool is_active);
[email protected]771c8d272013-05-17 09:47:4057
[email protected]961745f2013-05-25 14:09:2458 void RestoreApp(const extensions::Extension* extension);
[email protected]28c3eeb2012-10-15 05:47:5359
[email protected]4b7111f22013-06-18 14:22:1260 void StartObservingAppLifetime();
61 void StopObservingAppLifetime();
[email protected]771c8d272013-05-17 09:47:4062
[email protected]28c3eeb2012-10-15 05:47:5363 Profile* profile_;
[email protected]eb5c9682013-03-04 02:55:0064
65 DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
[email protected]28c3eeb2012-10-15 05:47:5366};
67
[email protected]c2e2b6d2013-01-22 02:23:2968} // namespace apps
[email protected]28c3eeb2012-10-15 05:47:5369
[email protected]eb5c9682013-03-04 02:55:0070#endif // APPS_APP_RESTORE_SERVICE_H_