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_COMMON_DB_STORE_H_
6 #define XWALK_APPLICATION_COMMON_DB_STORE_H_
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"
16 namespace application {
20 // Observer interface for monitoring DBStore.
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;
30 virtual ~Observer() {}
32 explicit DBStore(base::FilePath path);
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(); }
39 void AddObserver(DBStore::Observer* observer) {
40 observers_.AddObserver(observer);
42 void RemoveObserver(DBStore::Observer* observer) {
43 observers_.RemoveObserver(observer);
46 // Initialize the database, calling OnInitializationCompleted for each
47 // observer on completion.
48 virtual bool InitDB() = 0;
50 // Set value in database, resulting is calling OnDBValueChanged for
52 virtual void SetValue(const std::string& key, base::Value* value) = 0;
55 scoped_ptr<base::DictionaryValue> db_;
56 base::FilePath data_path_;
57 ObserverList<DBStore::Observer, true> observers_;
60 } // namespace application
63 #endif // XWALK_APPLICATION_COMMON_DB_STORE_H_