- update source.
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_service.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
7
8 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/observer_list.h"
13 #include "xwalk/application/browser/application.h"
14 #include "xwalk/runtime/browser/runtime_context.h"
15 #include "xwalk/application/common/application_data.h"
16
17 namespace xwalk {
18
19 class RuntimeContext;
20
21 namespace application {
22
23 class ApplicationStorage;
24 class ApplicationEventManager;
25
26 // The application service manages install, uninstall and updates of
27 // applications.
28 class ApplicationService : public Application::Observer {
29  public:
30   // Client code may use this class (and register with AddObserver below) to
31   // keep track of [un]installation of applications.
32   class Observer {
33    public:
34     virtual void OnApplicationInstalled(const std::string& app_id) {}
35     virtual void OnApplicationUninstalled(const std::string& app_id) {}
36
37     virtual void DidLaunchApplication(Application* app) {}
38     virtual void WillDestroyApplication(Application* app) {}
39    protected:
40     virtual ~Observer() {}
41   };
42
43   ApplicationService(RuntimeContext* runtime_context,
44                      ApplicationStorage* app_storage,
45                      ApplicationEventManager* event_manager);
46   virtual ~ApplicationService();
47
48   bool Install(const base::FilePath& path, std::string* id);
49   bool Uninstall(const std::string& id);
50   // Launch an installed application using application id.
51   Application* Launch(const std::string& id);
52   // Launch an unpacked application using path to a local directory which
53   // contains manifest file.
54   Application* Launch(const base::FilePath& path);
55   // Launch an application created from arbitrary url.
56   // FIXME: This application should have the same strict permissions
57   // as common browser apps.
58   Application* Launch(const GURL& url);
59
60   Application* GetApplicationByRenderHostID(int id) const;
61   Application* GetApplicationByID(const std::string& app_id) const;
62
63   const ScopedVector<Application>& active_applications() const {
64       return applications_; }
65
66   void AddObserver(Observer* observer);
67   void RemoveObserver(Observer* observer);
68
69  private:
70   // Implementation of Application::Observer.
71   virtual void OnApplicationTerminated(Application* app) OVERRIDE;
72
73   Application* Launch(scoped_refptr<ApplicationData> application_data,
74                       const Application::LaunchParams& launch_params);
75
76   xwalk::RuntimeContext* runtime_context_;
77   ApplicationStorage* application_storage_;
78   ApplicationEventManager* event_manager_;
79   ScopedVector<Application> applications_;
80   ObserverList<Observer> observers_;
81
82   DISALLOW_COPY_AND_ASSIGN(ApplicationService);
83 };
84
85 }  // namespace application
86 }  // namespace xwalk
87
88 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_