- add third_party src.
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / application_storage_impl.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_STORAGE_IMPL_H_
6 #define XWALK_APPLICATION_BROWSER_APPLICATION_STORAGE_IMPL_H_
7
8 #include <set>
9 #include <string>
10 #include <utility>
11
12 #include "base/files/file_path.h"
13 #include "sql/connection.h"
14 #include "sql/meta_table.h"
15 #include "xwalk/application/common/application_data.h"
16
17 namespace xwalk {
18 namespace application {
19
20 // The Sqlite backend implementation of ApplicationStorage.
21 class ApplicationStorageImpl {
22  public:
23   static const base::FilePath::CharType kDBFileName[];
24   explicit ApplicationStorageImpl(const base::FilePath& path);
25   ~ApplicationStorageImpl();
26
27   bool AddApplication(const ApplicationData* application,
28                       const base::Time& install_time);
29   bool RemoveApplication(const std::string& key);
30   bool UpdateApplication(ApplicationData* application,
31                          const base::Time& install_time);
32   bool Init(ApplicationData::ApplicationDataMap& applications);
33   bool GetInstalledApplications(
34       ApplicationData::ApplicationDataMap& applications);
35
36  private:
37   bool UpgradeToVersion1(const base::FilePath& v0_file);
38   bool SetApplicationValue(const ApplicationData* application,
39                            const base::Time& install_time,
40                            const std::string& operation);
41
42   bool SetEventsValue(const std::string& id,
43                       const std::set<std::string>& events,
44                       const std::string& operation);
45   bool SetEvents(const std::string& id,
46                  const std::set<std::string>& events);
47   bool UpdateEvents(const std::string& id,
48                     const std::set<std::string>& events);
49   bool DeleteEvents(const std::string& id);
50
51   scoped_ptr<sql::Connection> sqlite_db_;
52   sql::MetaTable meta_table_;
53   base::FilePath data_path_;
54   bool db_initialized_;
55 };
56
57 }  // namespace application
58 }  // namespace xwalk
59
60 #endif  // XWALK_APPLICATION_BROWSER_APPLICATION_STORAGE_IMPL_H_