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 PackageInstaller;
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 // When we change the application locale, we might get a new name in
37 virtual void OnApplicationNameChanged(const std::string& app_id,
38 const std::string& app_name) {}
40 virtual void DidLaunchApplication(Application* app) {}
41 virtual void WillDestroyApplication(Application* app) {}
43 virtual ~Observer() {}
46 ApplicationService(RuntimeContext* runtime_context,
47 ApplicationStorage* app_storage);
48 virtual ~ApplicationService();
50 void ChangeLocale(const std::string& locale);
52 Application* Launch(scoped_refptr<ApplicationData> application_data,
53 const Application::LaunchParams& launch_params);
54 // Launch an installed application using application id.
56 const std::string& id,
57 const Application::LaunchParams& params = Application::LaunchParams());
58 // Launch an unpacked application using path to a local directory which
59 // contains manifest file.
61 const base::FilePath& path,
62 const Application::LaunchParams& params = Application::LaunchParams());
64 Application* GetApplicationByRenderHostID(int id) const;
65 Application* GetApplicationByID(const std::string& app_id) const;
67 const ScopedVector<Application>& active_applications() const {
68 return applications_; }
70 void AddObserver(Observer* observer);
71 void RemoveObserver(Observer* observer);
73 // Check whether application has permission to access API of extension.
74 void CheckAPIAccessControl(const std::string& app_id,
75 const std::string& extension_name,
76 const std::string& api_name, const PermissionCallback& callback);
77 // Register APIs implemented by extension. This method will be called
78 // when application register extensions.
79 // Parameter perm_table is a string which is a map between extension
80 // and it includes APIs. For example perm_table is like '{"bluetooth":
81 // ["read", "write", "management"]}'.
82 bool RegisterPermissions(const std::string& app_id,
83 const std::string& extension_name,
84 const std::string& perm_table);
87 // Implementation of Application::Observer.
88 virtual void OnApplicationTerminated(Application* app) OVERRIDE;
90 xwalk::RuntimeContext* runtime_context_;
91 ApplicationStorage* application_storage_;
92 ScopedVector<Application> applications_;
93 ObserverList<Observer> observers_;
95 DISALLOW_COPY_AND_ASSIGN(ApplicationService);
98 } // namespace application
101 #endif // XWALK_APPLICATION_BROWSER_APPLICATION_SERVICE_H_