Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: ui/app_list/search/dictionary_data_store.cc

Issue 1127963002: Implement lossy pref behavior for JsonPrefStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs-fix-flags
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« base/prefs/json_pref_store_unittest.cc ('K') | « net/http/transport_security_persister.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698