app_restore_service.h revision 868fa2fe829687343ffae624259930155e16dbd8
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) 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns whether this extension is running or, at startup, whether it was 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // running when Chrome was last terminated. 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool IsAppRestorable(const std::string& extension_id); 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static AppRestoreService* Get(Profile* profile); 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // content::NotificationObserver. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // extensions::ShellWindowRegistry::Observer. 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE; 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // BrowserContextKeyedService. 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void Shutdown() OVERRIDE; 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RecordAppStart(const std::string& extension_id); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RecordAppStop(const std::string& extension_id); 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void RecordIfAppHasWindows(const std::string& id); 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void RestoreApp(const extensions::Extension* extension); 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StartObservingShellWindows(); 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void StopObservingShellWindows(); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppRestoreService); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace apps 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // APPS_APP_RESTORE_SERVICE_H_ 77