blob: bf538293a8d554a4ccff9453879ed58d5e2db7cf [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]771c8d272013-05-17 09:47:4011#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]0dd6f2032013-05-20 23:33:4012#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
[email protected]28c3eeb2012-10-15 05:47:5313#include "content/public/browser/notification_observer.h"
14#include "content/public/browser/notification_registrar.h"
15
[email protected]b8816a42013-02-27 07:59:0016namespace extensions {
17class Extension;
[email protected]b897ff872013-02-27 19:50:1318}
19
20class Profile;
21
[email protected]c2e2b6d2013-01-22 02:23:2922namespace apps {
[email protected]28c3eeb2012-10-15 05:47:5323
24// Tracks what apps need to be restarted when the browser restarts.
[email protected]f1484c52013-05-22 23:25:4425class AppRestoreService : public BrowserContextKeyedService,
[email protected]771c8d272013-05-17 09:47:4026 public content::NotificationObserver,
[email protected]4abde492013-06-06 14:13:0027 public extensions::ShellWindowRegistry::Observer {
[email protected]28c3eeb2012-10-15 05:47:5328 public:
[email protected]24ced7dc02013-04-04 08:32:3929 // 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);
32
[email protected]28c3eeb2012-10-15 05:47:5333 explicit AppRestoreService(Profile* profile);
34
[email protected]119454622012-10-18 09:48:3235 // Restart apps that need to be restarted and clear the "running" preference
36 // from apps to prevent them being restarted in subsequent restarts.
[email protected]300ba0c42012-12-06 06:57:1737 void HandleStartup(bool should_restore_apps);
[email protected]28c3eeb2012-10-15 05:47:5338
[email protected]a2886e8b2013-06-08 05:15:0239 // 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);
42
43 static AppRestoreService* Get(Profile* profile);
44
[email protected]28c3eeb2012-10-15 05:47:5345 private:
46 // content::NotificationObserver.
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
50
[email protected]4abde492013-06-06 14:13:0051 // extensions::ShellWindowRegistry::Observer.
52 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
53 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE;
54 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
[email protected]771c8d272013-05-17 09:47:4055
[email protected]f1484c52013-05-22 23:25:4456 // BrowserContextKeyedService.
[email protected]771c8d272013-05-17 09:47:4057 virtual void Shutdown() OVERRIDE;
58
[email protected]28c3eeb2012-10-15 05:47:5359 void RecordAppStart(const std::string& extension_id);
60 void RecordAppStop(const std::string& extension_id);
[email protected]4abde492013-06-06 14:13:0061 void RecordIfAppHasWindows(const std::string& id);
[email protected]771c8d272013-05-17 09:47:4062
[email protected]961745f2013-05-25 14:09:2463 void RestoreApp(const extensions::Extension* extension);
[email protected]28c3eeb2012-10-15 05:47:5364
[email protected]4abde492013-06-06 14:13:0065 void StartObservingShellWindows();
66 void StopObservingShellWindows();
[email protected]771c8d272013-05-17 09:47:4067
[email protected]28c3eeb2012-10-15 05:47:5368 content::NotificationRegistrar registrar_;
69 Profile* profile_;
[email protected]eb5c9682013-03-04 02:55:0070
71 DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
[email protected]28c3eeb2012-10-15 05:47:5372};
73
[email protected]c2e2b6d2013-01-22 02:23:2974} // namespace apps
[email protected]28c3eeb2012-10-15 05:47:5375
[email protected]eb5c9682013-03-04 02:55:0076#endif // APPS_APP_RESTORE_SERVICE_H_