Roll src/third_party/skia 8fd97ea:87a5c9f
[chromium-blink-merge.git] / apps / app_load_service.h
blob1b6fbab6b46125b48dc135c3d2b00d478b8ccab8
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.
5 #ifndef APPS_APP_LOAD_SERVICE_H_
6 #define APPS_APP_LOAD_SERVICE_H_
8 #include <map>
9 #include <string>
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"
18 class Profile;
20 namespace extensions {
21 struct UnloadedExtensionInfo;
24 namespace apps {
26 // Monitors apps being reloaded and performs app specific actions (like launch
27 // or restart) on them. Also provides an interface to schedule these actions.
28 class AppLoadService : public KeyedService,
29 public content::NotificationObserver,
30 public extensions::ExtensionRegistryObserver {
31 public:
32 enum PostReloadActionType {
33 LAUNCH_FOR_RELOAD,
34 RESTART,
35 LAUNCH_FOR_LOAD_AND_LAUNCH,
38 struct PostReloadAction {
39 PostReloadAction();
41 PostReloadActionType action_type;
42 base::CommandLine command_line;
43 base::FilePath current_dir;
46 explicit AppLoadService(Profile* profile);
47 ~AppLoadService() override;
49 // Reload the application with the given id and then send it the OnRestarted
50 // event.
51 void RestartApplication(const std::string& extension_id);
53 // Reload the application with the given id if it is currently running.
54 void RestartApplicationIfRunning(const std::string& extension_id);
56 // Loads (or reloads) the app with |extension_path|, then launches it. Any
57 // command line parameters from |command_line| will be passed along via
58 // launch parameters. Returns true if loading the extension has begun
59 // successfully.
60 bool LoadAndLaunch(const base::FilePath& extension_path,
61 const base::CommandLine& command_line,
62 const base::FilePath& current_dir);
64 // Loads (or reloads) the app with |extension_path|. Returns true if loading
65 // the app has begun successfully.
66 bool Load(const base::FilePath& extension_path);
68 static AppLoadService* Get(Profile* profile);
70 private:
71 // content::NotificationObserver.
72 void Observe(int type,
73 const content::NotificationSource& source,
74 const content::NotificationDetails& details) override;
76 // extensions::ExtensionRegistryObserver.
77 void OnExtensionUnloaded(
78 content::BrowserContext* browser_context,
79 const extensions::Extension* extension,
80 extensions::UnloadedExtensionInfo::Reason reason) override;
82 bool WasUnloadedForReload(
83 const extensions::ExtensionId& extension_id,
84 const extensions::UnloadedExtensionInfo::Reason reason);
85 bool HasPostReloadAction(const std::string& extension_id);
87 // Map of extension id to reload action. Absence from the map implies
88 // no action.
89 std::map<std::string, PostReloadAction> post_reload_actions_;
90 content::NotificationRegistrar registrar_;
91 Profile* profile_;
93 DISALLOW_COPY_AND_ASSIGN(AppLoadService);
96 } // namespace apps
98 #endif // APPS_APP_LOAD_SERVICE_H_