Upstream version 8.36.156.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / db_store_sqlite_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_COMMON_DB_STORE_SQLITE_IMPL_H_
6 #define XWALK_APPLICATION_COMMON_DB_STORE_SQLITE_IMPL_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "sql/connection.h"
12 #include "sql/meta_table.h"
13 #include "xwalk/application/common/db_store.h"
14
15 namespace xwalk {
16 namespace application {
17
18 // The Sqlite backend implementation of DBStore.
19 class DBStoreSqliteImpl: public DBStore {
20  public:
21   static const base::FilePath::CharType kDBFileName[];
22   explicit DBStoreSqliteImpl(const base::FilePath& path);
23   virtual ~DBStoreSqliteImpl();
24
25   // Implement the DBStore inferface.
26   virtual bool Insert(const ApplicationData* application,
27                       const base::Time install_time) OVERRIDE;
28   virtual bool Remove(const std::string& key) OVERRIDE;
29   virtual bool InitDB() OVERRIDE;
30   virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE;
31
32  private:
33   enum Action {
34     ACTION_UNKNOWN = 0,
35     ACTION_INSERT,
36     ACTION_UPDATE,
37     ACTION_DELETE
38   };
39   bool UpdateDBCache();
40   bool Commit(const std::string& id,
41               const std::string& column,
42               base::Value* value,
43               Action action);
44   void ReportValueChanged(const std::string& key,
45                           const base::Value* value);
46   bool UpgradeToVersion1(const base::FilePath& v0_file);
47   bool SetApplication(const std::string& id, base::Value* value);
48   bool UpdateApplication(const std::string& id, base::Value* value);
49   bool DeleteApplication(const std::string& id);
50   bool SetManifestValue(const std::string& id, base::Value* value);
51   bool SetInstallTimeValue(const std::string& id, base::Value* value);
52   bool SetApplicationPathValue(const std::string& id, base::Value* value);
53
54   bool SetEventsValue(const std::string& id,
55                       base::Value* events,
56                       const std::string& operation);
57   bool DeleteEventsValue(const std::string& id);
58
59   scoped_ptr<sql::Connection> sqlite_db_;
60   sql::MetaTable meta_table_;
61   bool db_initialized_;
62 };
63
64 }  // namespace application
65 }  // namespace xwalk
66
67 #endif  // XWALK_APPLICATION_COMMON_DB_STORE_SQLITE_IMPL_H_