Pass CreateDirectory errors up to IndexedDB.
[chromium-blink-merge.git] / apps / app_restore_service.h
blob5a66005475da512cd8c306d1f99bdd4d7b66f4de
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_
8 #include <string>
9 #include <vector>
11 #include "apps/app_lifetime_monitor.h"
12 #include "chrome/browser/extensions/shell_window_registry.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
15 namespace extensions {
16 class Extension;
19 class Profile;
21 namespace apps {
23 // Tracks what apps need to be restarted when the browser restarts.
24 class AppRestoreService : public BrowserContextKeyedService,
25 public AppLifetimeMonitor::Observer {
26 public:
27 // 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);
31 explicit AppRestoreService(Profile* profile);
33 // Restart apps that need to be restarted and clear the "running" preference
34 // from apps to prevent them being restarted in subsequent restarts.
35 void HandleStartup(bool should_restore_apps);
37 // 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);
41 static AppRestoreService* Get(Profile* profile);
43 private:
44 // AppLifetimeMonitor::Observer.
45 virtual void OnAppStart(Profile* profile, const std::string& app_id) OVERRIDE;
46 virtual void OnAppActivated(Profile* profile,
47 const std::string& app_id) OVERRIDE;
48 virtual void OnAppDeactivated(Profile* profile,
49 const std::string& app_id) OVERRIDE;
50 virtual void OnAppStop(Profile* profile, const std::string& app_id) OVERRIDE;
51 virtual void OnChromeTerminating() OVERRIDE;
53 // BrowserContextKeyedService.
54 virtual void Shutdown() OVERRIDE;
56 void RecordAppStart(const std::string& extension_id);
57 void RecordAppStop(const std::string& extension_id);
58 void RecordAppActiveState(const std::string& id, bool is_active);
60 void RestoreApp(const extensions::Extension* extension);
62 void StartObservingAppLifetime();
63 void StopObservingAppLifetime();
65 Profile* profile_;
67 DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
70 } // namespace apps
72 #endif // APPS_APP_RESTORE_SERVICE_H_