| 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 #include "ui/app_list/search/dictionary_data_store.h" | 5 #include "ui/app_list/search/dictionary_data_store.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/important_file_writer.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 | 17 |
| 17 namespace app_list { | 18 namespace app_list { |
| 18 | 19 |
| 19 DictionaryDataStore::DictionaryDataStore(const base::FilePath& data_file, | 20 DictionaryDataStore::DictionaryDataStore(const base::FilePath& data_file, |
| 20 base::SequencedWorkerPool* worker_pool) | 21 base::SequencedWorkerPool* worker_pool) |
| 21 : data_file_(data_file), worker_pool_(worker_pool) { | 22 : data_file_(data_file), worker_pool_(worker_pool) { |
| 22 std::string token("app-launcher-data-store"); | 23 std::string token("app-launcher-data-store"); |
| 23 token.append(data_file.AsUTF8Unsafe()); | 24 token.append(data_file.AsUTF8Unsafe()); |
| 24 | 25 |
| 25 // Uses a SKIP_ON_SHUTDOWN file task runner because losing a couple | 26 // Uses a SKIP_ON_SHUTDOWN file task runner because losing a couple |
| 26 // associations is better than blocking shutdown. | 27 // associations is better than blocking shutdown. |
| 27 file_task_runner_ = worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 28 file_task_runner_ = worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 28 worker_pool->GetNamedSequenceToken(token), | 29 worker_pool->GetNamedSequenceToken(token), |
| 29 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 30 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 30 writer_.reset( | 31 writer_.reset( |
| 31 new base::ImportantFileWriter(data_file, file_task_runner_.get())); | 32 new base::ImportantFileWriterImpl(data_file, file_task_runner_.get())); |
| 32 | 33 |
| 33 cached_dict_.reset(new base::DictionaryValue); | 34 cached_dict_.reset(new base::DictionaryValue); |
| 34 } | 35 } |
| 35 | 36 |
| 36 DictionaryDataStore::~DictionaryDataStore() { | 37 DictionaryDataStore::~DictionaryDataStore() { |
| 37 Flush(OnFlushedCallback()); | 38 Flush(OnFlushedCallback()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void DictionaryDataStore::Flush(const OnFlushedCallback& on_flushed) { | 41 void DictionaryDataStore::Flush(const OnFlushedCallback& on_flushed) { |
| 41 if (writer_->HasPendingWrite()) | 42 if (writer_->HasPendingWrite()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return make_scoped_ptr(return_dict); | 80 return make_scoped_ptr(return_dict); |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool DictionaryDataStore::SerializeData(std::string* data) { | 83 bool DictionaryDataStore::SerializeData(std::string* data) { |
| 83 JSONStringValueSerializer serializer(data); | 84 JSONStringValueSerializer serializer(data); |
| 84 serializer.set_pretty_print(true); | 85 serializer.set_pretty_print(true); |
| 85 return serializer.Serialize(*cached_dict_.get()); | 86 return serializer.Serialize(*cached_dict_.get()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace app_list | 89 } // namespace app_list |
| OLD | NEW |