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.
5 #ifndef XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_
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/application/common/permission_policy_manager.h"
15 #include "xwalk/runtime/browser/runtime_context.h"
16 #include "xwalk/application/common/application_data.h"
22 namespace application {
24 class ApplicationStorage;
25 class ApplicationEventManager;
27 // The application service manages install, uninstall and updates of
29 class ApplicationService : public Application::Observer {
31 // Client code may use this class (and register with AddObserver below) to
32 // keep track of [un]installation of applications.
35 virtual void OnApplicationInstalled(const std::string& app_id) {}
36 virtual void OnApplicationUninstalled(const std::string& app_id) {}
37 virtual void OnApplicationUpdated(const std::string& app_id) {}
38 // When we change the application locale, we might get a new name in
40 virtual void OnApplicationNameChanged(const std::string& app_id,
41 const std::string& app_name) {}
43 virtual void DidLaunchApplication(Application* app) {}
44 virtual void WillDestroyApplication(Application* app) {}
46 virtual ~Observer() {}
49 ApplicationService(RuntimeContext* runtime_context,
50 ApplicationStorage* app_storage,
51 ApplicationEventManager* event_manager);
52 virtual ~ApplicationService();
54 bool Install(const base::FilePath& path, std::string* id);
55 bool Uninstall(const std::string& id);
56 bool Update(const std::string& id, const base::FilePath& path);
57 void ChangeLocale(const std::string& locale);
59 Application* Launch(scoped_refptr<ApplicationData> application_data,
60 const Application::LaunchParams& launch_params);
61 // Launch an installed application using application id.
63 const std::string& id,
64 const Application::LaunchParams& params = Application::LaunchParams());
65 // Launch an unpacked application using path to a local directory which
66 // contains manifest file.
68 const base::FilePath& path,
69 const Application::LaunchParams& params = Application::LaunchParams());
71 Application* GetApplicationByRenderHostID(int id) const;
72 Application* GetApplicationByID(const std::string& app_id) const;
74 const ScopedVector<Application>& active_applications() const {
75 return applications_; }
77 void AddObserver(Observer* observer);
78 void RemoveObserver(Observer* observer);
80 // Check whether application has permission to access API of extension.
81 void CheckAPIAccessControl(const std::string& app_id,
82 const std::string& extension_name,
83 const std::string& api_name, const PermissionCallback& callback);
84 // Register APIs implemented by extension. This method will be called
85 // when application register extensions.
86 // Parameter perm_table is a string which is a map between extension
87 // and it includes APIs. For example perm_table is like '{"bluetooth":
88 // ["read", "write", "management"]}'.
89 bool RegisterPermissions(const std::string& app_id,
90 const std::string& extension_name,
91 const std::string& perm_table);
94 // Implementation of Application::Observer.
95 virtual void OnApplicationTerminated(Application* app) OVERRIDE;
98 xwalk::RuntimeContext* runtime_context_;
99 ApplicationStorage* application_storage_;
100 ApplicationEventManager* event_manager_;
101 ScopedVector<Application> applications_;
102 ObserverList<Observer> observers_;
103 scoped_ptr<PermissionPolicyManager> permission_policy_handler_;
105 DISALLOW_COPY_AND_ASSIGN(ApplicationService);
108 } // namespace application
111 #endif // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_