Upstream version 8.36.156.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / common / db_store.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_H_
6 #define XWALK_APPLICATION_COMMON_DB_STORE_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/time/time.h"
13 #include "xwalk/application/common/application_data.h"
14
15 namespace xwalk {
16 namespace application {
17
18 class DBStore {
19  public:
20   // Observer interface for monitoring DBStore.
21   class Observer {
22    public:
23     // Called when the value for the given |key| in the store changes.
24     virtual void OnDBValueChanged(const std::string& key,
25                                   const base::Value* value) = 0;
26     // Notification about the DBStore being fully initialized.
27     virtual void OnInitializationCompleted(bool succeeded) = 0;
28
29    protected:
30     virtual ~Observer() {}
31   };
32   explicit DBStore(base::FilePath path);
33   virtual ~DBStore();
34   virtual bool Insert(const ApplicationData* application,
35                       const base::Time install_time) = 0;
36   virtual bool Remove(const std::string& key) = 0;
37   base::DictionaryValue* GetApplications() const { return db_.get(); }
38
39   void AddObserver(DBStore::Observer* observer) {
40     observers_.AddObserver(observer);
41   }
42   void RemoveObserver(DBStore::Observer* observer) {
43     observers_.RemoveObserver(observer);
44   }
45
46   // Initialize the database, calling OnInitializationCompleted for each
47   // observer on completion.
48   virtual bool InitDB() = 0;
49
50   // Set value in database, resulting is calling OnDBValueChanged for
51   // each observer.
52   virtual void SetValue(const std::string& key, base::Value* value) = 0;
53
54  protected:
55   scoped_ptr<base::DictionaryValue> db_;
56   base::FilePath data_path_;
57   ObserverList<DBStore::Observer, true> observers_;
58 };
59
60 }  // namespace application
61 }  // namespace xwalk
62
63 #endif  // XWALK_APPLICATION_COMMON_DB_STORE_H_