- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / search / history_data_store.h
1 // Copyright 2013 The Chromium Authors. 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 CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/files/file_path.h"
14 #include "base/files/important_file_writer.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "chrome/browser/ui/app_list/search/common/dictionary_data_store.h"
18 #include "chrome/browser/ui/app_list/search/history_data.h"
19
20 namespace base {
21 class DictionaryValue;
22 class SequencedTaskRunner;
23 }
24
25 namespace app_list {
26
27 namespace test {
28 class HistoryDataStoreTest;
29 }
30
31 // A simple json store to persist HistoryData.
32 class HistoryDataStore : public base::RefCountedThreadSafe<HistoryDataStore> {
33  public:
34   typedef base::Callback<void(scoped_ptr<HistoryData::Associations>)>
35       OnLoadedCallback;
36
37   explicit HistoryDataStore(const base::FilePath& data_file);
38
39   // Flushes pending writes. |on_flushed| is invoked when disk write is
40   // finished.
41   void Flush(const DictionaryDataStore::OnFlushedCallback& on_flushed);
42
43   // Reads the persisted data from disk asynchronously. |on_read| is called
44   // with the loaded and parsed data. If there is an error, |on_read| is called
45   // without data.
46   void Load(const OnLoadedCallback& on_loaded);
47
48   // Incremental changes allowed on the data store.
49   void SetPrimary(const std::string& query, const std::string& result);
50   void SetSecondary(const std::string& query,
51                     const HistoryData::SecondaryDeque& results);
52   void SetUpdateTime(const std::string& query, const base::Time& update_time);
53   void Delete(const std::string& query);
54
55  private:
56   friend class base::RefCountedThreadSafe<HistoryDataStore>;
57   friend class app_list::test::HistoryDataStoreTest;
58
59   virtual ~HistoryDataStore();
60
61   // Gets the dictionary for "associations" key.
62   base::DictionaryValue* GetAssociationDict();
63
64   // Gets entry dictionary for given |query|. Creates one if necessary.
65   base::DictionaryValue* GetEntryDict(const std::string& query);
66
67   void OnDictionaryLoadedCallback(OnLoadedCallback callback,
68                                   scoped_ptr<base::DictionaryValue> dict);
69
70   scoped_refptr<DictionaryDataStore> data_store_;
71
72   DISALLOW_COPY_AND_ASSIGN(HistoryDataStore);
73 };
74
75 }  // namespace app_list
76
77 #endif  // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_