blob: c7e75c6e1aaf767dfdd5f3df6db3e9754deb14b7 [file] [log] [blame]
[email protected]2a69b942013-05-31 09:37:531// 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 "components/browser_context_keyed_service/browser_context_keyed_service.h"
12#include "content/public/browser/notification_observer.h"
13#include "content/public/browser/notification_registrar.h"
14
15class Profile;
16
17namespace apps {
18
19// Monitors apps being reloaded and performs app specific actions (like launch
20// or restart) on them. Also provides an interface to schedule these actions.
21class AppLoadService : public BrowserContextKeyedService,
22 public content::NotificationObserver {
23 public:
24 explicit AppLoadService(Profile* profile);
25 virtual ~AppLoadService();
26
27 // Reload the application with the given id and then send it the OnRestarted
28 // event.
29 void RestartApplication(const std::string& extension_id);
30
31 // Schedule a launch to happen for the extension with id |extension_id|
32 // when it loads next. This does not cause the extension to be reloaded.
33 void ScheduleLaunchOnLoad(const std::string& extension_id);
34
35 static AppLoadService* Get(Profile* profile);
36
37 private:
38 // content::NotificationObserver.
39 virtual void Observe(int type,
40 const content::NotificationSource& source,
41 const content::NotificationDetails& details) OVERRIDE;
42
43 // Map of extension id to reload action. Absence from the map implies
44 // no action.
45 std::map<std::string, int> reload_actions_;
46 content::NotificationRegistrar registrar_;
47 Profile* profile_;
48
49 DISALLOW_COPY_AND_ASSIGN(AppLoadService);
50};
51
52} // namespace apps
53
54#endif // APPS_APP_LOAD_SERVICE_H_