app_restore_service.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef APPS_APP_RESTORE_SERVICE_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define APPS_APP_RESTORE_SERVICE_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/extensions/shell_window_registry.h"
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace extensions {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Extension;
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace apps {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Tracks what apps need to be restarted when the browser restarts.
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class AppRestoreService : public BrowserContextKeyedService,
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                          public content::NotificationObserver,
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                          public extensions::ShellWindowRegistry::Observer {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns true if apps should be restored on the current platform, given
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // whether this new browser process launched due to a restart.
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static bool ShouldRestoreApps(bool is_browser_restart);
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit AppRestoreService(Profile* profile);
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restart apps that need to be restarted and clear the "running" preference
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from apps to prevent them being restarted in subsequent restarts.
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void HandleStartup(bool should_restore_apps);
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // content::NotificationObserver.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Observe(int type,
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationSource& source,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // extensions::ShellWindowRegistry::Observer.
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE;
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // BrowserContextKeyedService.
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void Shutdown() OVERRIDE;
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RecordAppStart(const std::string& extension_id);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RecordAppStop(const std::string& extension_id);
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void RecordIfAppHasWindows(const std::string& id);
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void RestoreApp(const extensions::Extension* extension);
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void StartObservingShellWindows();
6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void StopObservingShellWindows();
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::NotificationRegistrar registrar_;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace apps
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // APPS_APP_RESTORE_SERVICE_H_
71