OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ | 5 #ifndef UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ |
6 #define UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ | 6 #define UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/important_file_writer.h" | 14 #include "base/files/important_file_writer.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "ui/app_list/app_list_export.h" | 17 #include "ui/app_list/app_list_export.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class DictionaryValue; | 20 class DictionaryValue; |
21 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
22 class SequencedWorkerPool; | 22 class SequencedWorkerPool; |
23 } | 23 } |
24 | 24 |
25 namespace app_list { | 25 namespace app_list { |
26 | 26 |
27 // A simple JSON store to persist a dictionary. | 27 // A simple JSON store to persist a dictionary. |
28 class APP_LIST_EXPORT DictionaryDataStore | 28 class APP_LIST_EXPORT DictionaryDataStore |
29 : public base::RefCountedThreadSafe<DictionaryDataStore>, | 29 : public base::RefCountedThreadSafe<DictionaryDataStore>, |
30 public base::ImportantFileWriter::DataSerializer { | 30 public base::ImportantFileWriter::DataSerializer { |
31 public: | 31 public: |
32 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> | 32 typedef base::Callback<void(std::unique_ptr<base::DictionaryValue>)> |
33 OnLoadedCallback; | 33 OnLoadedCallback; |
34 typedef base::Closure OnFlushedCallback; | 34 typedef base::Closure OnFlushedCallback; |
35 | 35 |
36 DictionaryDataStore(const base::FilePath& data_file, | 36 DictionaryDataStore(const base::FilePath& data_file, |
37 base::SequencedWorkerPool* worker_pool); | 37 base::SequencedWorkerPool* worker_pool); |
38 | 38 |
39 // Flushes pending writes. | 39 // Flushes pending writes. |
40 void Flush(const OnFlushedCallback& on_flushed); | 40 void Flush(const OnFlushedCallback& on_flushed); |
41 | 41 |
42 // Reads the persisted data from disk asynchronously. |on_read| is called | 42 // Reads the persisted data from disk asynchronously. |on_read| is called |
43 // with the loaded and parsed data. If there is an error, |on_read| is called | 43 // with the loaded and parsed data. If there is an error, |on_read| is called |
44 // without data. | 44 // without data. |
45 void Load(const OnLoadedCallback& on_loaded); | 45 void Load(const OnLoadedCallback& on_loaded); |
46 | 46 |
47 // Schedule a job to persist the cached dictionary. | 47 // Schedule a job to persist the cached dictionary. |
48 void ScheduleWrite(); | 48 void ScheduleWrite(); |
49 | 49 |
50 // Used to get a pointer to the cached dictionary. Changes to this dictionary | 50 // Used to get a pointer to the cached dictionary. Changes to this dictionary |
51 // will not be persisted unless ScheduleWrite() is called. | 51 // will not be persisted unless ScheduleWrite() is called. |
52 base::DictionaryValue* cached_dict() { return cached_dict_.get(); } | 52 base::DictionaryValue* cached_dict() { return cached_dict_.get(); } |
53 | 53 |
54 private: | 54 private: |
55 friend class base::RefCountedThreadSafe<DictionaryDataStore>; | 55 friend class base::RefCountedThreadSafe<DictionaryDataStore>; |
56 | 56 |
57 ~DictionaryDataStore() override; | 57 ~DictionaryDataStore() override; |
58 | 58 |
59 // Reads data from backing file. | 59 // Reads data from backing file. |
60 scoped_ptr<base::DictionaryValue> LoadOnBlockingPool(); | 60 std::unique_ptr<base::DictionaryValue> LoadOnBlockingPool(); |
61 | 61 |
62 // ImportantFileWriter::DataSerializer overrides: | 62 // ImportantFileWriter::DataSerializer overrides: |
63 bool SerializeData(std::string* data) override; | 63 bool SerializeData(std::string* data) override; |
64 | 64 |
65 base::FilePath data_file_; | 65 base::FilePath data_file_; |
66 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 66 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
67 scoped_ptr<base::ImportantFileWriter> writer_; | 67 std::unique_ptr<base::ImportantFileWriter> writer_; |
68 | 68 |
69 // Cached JSON dictionary to serve read and incremental change calls. | 69 // Cached JSON dictionary to serve read and incremental change calls. |
70 scoped_ptr<base::DictionaryValue> cached_dict_; | 70 std::unique_ptr<base::DictionaryValue> cached_dict_; |
71 | 71 |
72 base::SequencedWorkerPool* worker_pool_; | 72 base::SequencedWorkerPool* worker_pool_; |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(DictionaryDataStore); | 74 DISALLOW_COPY_AND_ASSIGN(DictionaryDataStore); |
75 }; | 75 }; |
76 | 76 |
77 } // namespace app_list | 77 } // namespace app_list |
78 | 78 |
79 #endif // UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ | 79 #endif // UI_APP_LIST_SEARCH_DICTIONARY_DATA_STORE_H_ |
OLD | NEW |