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/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"
21 class DictionaryValue;
22 class SequencedTaskRunner;
28 class HistoryDataStoreTest;
31 // A simple json store to persist HistoryData.
32 class HistoryDataStore : public base::RefCountedThreadSafe<HistoryDataStore> {
34 typedef base::Callback<void(scoped_ptr<HistoryData::Associations>)>
37 explicit HistoryDataStore(const base::FilePath& data_file);
39 // Flushes pending writes. |on_flushed| is invoked when disk write is
41 void Flush(const DictionaryDataStore::OnFlushedCallback& on_flushed);
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
46 void Load(const OnLoadedCallback& on_loaded);
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);
56 friend class base::RefCountedThreadSafe<HistoryDataStore>;
57 friend class app_list::test::HistoryDataStoreTest;
59 virtual ~HistoryDataStore();
61 // Gets the dictionary for "associations" key.
62 base::DictionaryValue* GetAssociationDict();
64 // Gets entry dictionary for given |query|. Creates one if necessary.
65 base::DictionaryValue* GetEntryDict(const std::string& query);
67 void OnDictionaryLoadedCallback(OnLoadedCallback callback,
68 scoped_ptr<base::DictionaryValue> dict);
70 scoped_refptr<DictionaryDataStore> data_store_;
72 DISALLOW_COPY_AND_ASSIGN(HistoryDataStore);
75 } // namespace app_list
77 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_HISTORY_DATA_STORE_H_