Remove wpr.archive_info dependancy on page to avoid circular dependancies.
[chromium-blink-merge.git] / ui / app_list / search / history_data_store.h
blobbeda4b8fe04cb46c2a0c0f2785cc0f1cc5eadd7d
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.
5 #ifndef UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
6 #define UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/app_list/app_list_export.h"
16 #include "ui/app_list/search/dictionary_data_store.h"
17 #include "ui/app_list/search/history_data.h"
19 namespace base {
20 class DictionaryValue;
21 class SequencedTaskRunner;
24 namespace app_list {
26 namespace test {
27 class HistoryDataStoreTest;
30 // A simple json store to persist HistoryData.
31 class APP_LIST_EXPORT HistoryDataStore
32 : public base::RefCountedThreadSafe<HistoryDataStore> {
33 public:
34 typedef base::Callback<void(scoped_ptr<HistoryData::Associations>)>
35 OnLoadedCallback;
37 // A data store with no storage backend.
38 HistoryDataStore();
40 // |data_store| stores the history into the file.
41 explicit HistoryDataStore(scoped_refptr<DictionaryDataStore> data_store);
43 // Flushes pending writes. |on_flushed| is invoked when disk write is
44 // finished.
45 void Flush(const DictionaryDataStore::OnFlushedCallback& on_flushed);
47 // Reads the persisted data from disk asynchronously. |on_read| is called
48 // with the loaded and parsed data. If there is an error, |on_read| is called
49 // without data.
50 void Load(const OnLoadedCallback& on_loaded);
52 // Incremental changes allowed on the data store.
53 void SetPrimary(const std::string& query, const std::string& result);
54 void SetSecondary(const std::string& query,
55 const HistoryData::SecondaryDeque& results);
56 void SetUpdateTime(const std::string& query, const base::Time& update_time);
57 void Delete(const std::string& query);
59 private:
60 friend class base::RefCountedThreadSafe<HistoryDataStore>;
61 friend class app_list::test::HistoryDataStoreTest;
63 virtual ~HistoryDataStore();
65 void Init(base::DictionaryValue* cached_dict);
67 // Gets the dictionary for "associations" key.
68 base::DictionaryValue* GetAssociationDict();
70 // Gets entry dictionary for given |query|. Creates one if necessary.
71 base::DictionaryValue* GetEntryDict(const std::string& query);
73 void OnDictionaryLoadedCallback(OnLoadedCallback callback,
74 scoped_ptr<base::DictionaryValue> dict);
76 // |cached_dict_| and |data_store_| is mutually exclusive. |data_store_| is
77 // used if it's backed by a file storage, otherwise |cache_dict_| keeps
78 // on-memory data.
79 scoped_ptr<base::DictionaryValue> cached_dict_;
80 scoped_refptr<DictionaryDataStore> data_store_;
82 DISALLOW_COPY_AND_ASSIGN(HistoryDataStore);
85 } // namespace app_list
87 #endif // UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_