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 CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_
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 "chrome/browser/ui/app_list/search/common/dictionary_data_store.h"
16 #include "chrome/browser/ui/app_list/search/history_data.h"
19 class DictionaryValue;
20 class SequencedTaskRunner;
26 class HistoryDataStoreTest;
29 // A simple json store to persist HistoryData.
30 class HistoryDataStore : public base::RefCountedThreadSafe<HistoryDataStore> {
32 typedef base::Callback<void(scoped_ptr<HistoryData::Associations>)>
35 // A data store with no storage backend.
38 // |data_store| stores the history into the file.
39 explicit HistoryDataStore(scoped_refptr<DictionaryDataStore> data_store);
41 // Flushes pending writes. |on_flushed| is invoked when disk write is
43 void Flush(const DictionaryDataStore::OnFlushedCallback& on_flushed);
45 // Reads the persisted data from disk asynchronously. |on_read| is called
46 // with the loaded and parsed data. If there is an error, |on_read| is called
48 void Load(const OnLoadedCallback& on_loaded);
50 // Incremental changes allowed on the data store.
51 void SetPrimary(const std::string& query, const std::string& result);
52 void SetSecondary(const std::string& query,
53 const HistoryData::SecondaryDeque& results);
54 void SetUpdateTime(const std::string& query, const base::Time& update_time);
55 void Delete(const std::string& query);
58 friend class base::RefCountedThreadSafe<HistoryDataStore>;
59 friend class app_list::test::HistoryDataStoreTest;
61 virtual ~HistoryDataStore();
63 void Init(base::DictionaryValue* cached_dict);
65 // Gets the dictionary for "associations" key.
66 base::DictionaryValue* GetAssociationDict();
68 // Gets entry dictionary for given |query|. Creates one if necessary.
69 base::DictionaryValue* GetEntryDict(const std::string& query);
71 void OnDictionaryLoadedCallback(OnLoadedCallback callback,
72 scoped_ptr<base::DictionaryValue> dict);
74 // |cached_dict_| and |data_store_| is mutually exclusive. |data_store_| is
75 // used if it's backed by a file storage, otherwise |cache_dict_| keeps
77 scoped_ptr<base::DictionaryValue> cached_dict_;
78 scoped_refptr<DictionaryDataStore> data_store_;
80 DISALLOW_COPY_AND_ASSIGN(HistoryDataStore);
83 } // namespace app_list
85 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_