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