| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 | |
| 5 #ifndef APPS_APP_LOAD_SERVICE_H_ | |
| 6 #define APPS_APP_LOAD_SERVICE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "components/keyed_service/core/keyed_service.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "extensions/browser/extension_registry_observer.h" | |
| 17 | |
| 18 namespace content { | |
| 19 class BrowserContext; | |
| 20 } | |
| 21 | |
| 22 namespace extensions { | |
| 23 struct UnloadedExtensionInfo; | |
| 24 } | |
| 25 | |
| 26 namespace apps { | |
| 27 | |
| 28 // Monitors apps being reloaded and performs app specific actions (like launch | |
| 29 // or restart) on them. Also provides an interface to schedule these actions. | |
| 30 class AppLoadService : public KeyedService, | |
| 31 public content::NotificationObserver, | |
| 32 public extensions::ExtensionRegistryObserver { | |
| 33 public: | |
| 34 enum PostReloadActionType { | |
| 35 LAUNCH_FOR_RELOAD, | |
| 36 RESTART, | |
| 37 LAUNCH_FOR_LOAD_AND_LAUNCH, | |
| 38 }; | |
| 39 | |
| 40 struct PostReloadAction { | |
| 41 PostReloadAction(); | |
| 42 | |
| 43 PostReloadActionType action_type; | |
| 44 base::CommandLine command_line; | |
| 45 base::FilePath current_dir; | |
| 46 }; | |
| 47 | |
| 48 explicit AppLoadService(content::BrowserContext* context); | |
| 49 ~AppLoadService() override; | |
| 50 | |
| 51 // KeyedService support: | |
| 52 void Shutdown() override; | |
| 53 | |
| 54 // Reload the application with the given id and then send it the OnRestarted | |
| 55 // event. | |
| 56 void RestartApplication(const std::string& extension_id); | |
| 57 | |
| 58 // Reload the application with the given id if it is currently running. | |
| 59 void RestartApplicationIfRunning(const std::string& extension_id); | |
| 60 | |
| 61 // Loads (or reloads) the app with |extension_path|, then launches it. Any | |
| 62 // command line parameters from |command_line| will be passed along via | |
| 63 // launch parameters. Returns true if loading the extension has begun | |
| 64 // successfully. | |
| 65 bool LoadAndLaunch(const base::FilePath& extension_path, | |
| 66 const base::CommandLine& command_line, | |
| 67 const base::FilePath& current_dir); | |
| 68 | |
| 69 // Loads (or reloads) the app with |extension_path|. Returns true if loading | |
| 70 // the app has begun successfully. | |
| 71 bool Load(const base::FilePath& extension_path); | |
| 72 | |
| 73 static AppLoadService* Get(content::BrowserContext* context); | |
| 74 | |
| 75 private: | |
| 76 // content::NotificationObserver. | |
| 77 void Observe(int type, | |
| 78 const content::NotificationSource& source, | |
| 79 const content::NotificationDetails& details) override; | |
| 80 | |
| 81 // extensions::ExtensionRegistryObserver. | |
| 82 void OnExtensionUnloaded( | |
| 83 content::BrowserContext* browser_context, | |
| 84 const extensions::Extension* extension, | |
| 85 extensions::UnloadedExtensionInfo::Reason reason) override; | |
| 86 | |
| 87 bool WasUnloadedForReload( | |
| 88 const extensions::ExtensionId& extension_id, | |
| 89 const extensions::UnloadedExtensionInfo::Reason reason); | |
| 90 bool HasPostReloadAction(const std::string& extension_id); | |
| 91 | |
| 92 // Map of extension id to reload action. Absence from the map implies | |
| 93 // no action. | |
| 94 std::map<std::string, PostReloadAction> post_reload_actions_; | |
| 95 content::NotificationRegistrar registrar_; | |
| 96 content::BrowserContext* context_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(AppLoadService); | |
| 99 }; | |
| 100 | |
| 101 } // namespace apps | |
| 102 | |
| 103 #endif // APPS_APP_LOAD_SERVICE_H_ | |
| OLD | NEW |