Use a qualified path to blink resources, content part.
[chromium-blink-merge.git] / apps / app_load_service.h
blob1f4998003a3d34a26547c2926b1a5f4d285e4486
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"
17 class Profile;
19 namespace extensions {
20 struct UnloadedExtensionInfo;
23 namespace apps {
25 // Monitors apps being reloaded and performs app specific actions (like launch
26 // or restart) on them. Also provides an interface to schedule these actions.
27 class AppLoadService : public KeyedService,
28 public content::NotificationObserver {
29 public:
30 enum PostReloadActionType {
31 LAUNCH,
32 RESTART,
33 LAUNCH_WITH_COMMAND_LINE,
36 struct PostReloadAction {
37 PostReloadAction();
39 PostReloadActionType action_type;
40 base::CommandLine command_line;
41 base::FilePath current_dir;
44 explicit AppLoadService(Profile* profile);
45 virtual ~AppLoadService();
47 // Reload the application with the given id and then send it the OnRestarted
48 // event.
49 void RestartApplication(const std::string& extension_id);
51 // Reload the application with the given id if it is currently running.
52 void RestartApplicationIfRunning(const std::string& extension_id);
54 // Loads (or reloads) the app with |extension_path|, then launches it. Any
55 // command line parameters from |command_line| will be passed along via
56 // launch parameters. Returns true if loading the extension has begun
57 // successfully.
58 bool LoadAndLaunch(const base::FilePath& extension_path,
59 const base::CommandLine& command_line,
60 const base::FilePath& current_dir);
62 static AppLoadService* Get(Profile* profile);
64 private:
65 // content::NotificationObserver.
66 virtual void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) OVERRIDE;
70 bool WasUnloadedForReload(
71 const extensions::UnloadedExtensionInfo& unload_info);
72 bool HasPostReloadAction(const std::string& extension_id);
74 // Map of extension id to reload action. Absence from the map implies
75 // no action.
76 std::map<std::string, PostReloadAction> post_reload_actions_;
77 content::NotificationRegistrar registrar_;
78 Profile* profile_;
80 DISALLOW_COPY_AND_ASSIGN(AppLoadService);
83 } // namespace apps
85 #endif // APPS_APP_LOAD_SERVICE_H_