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

Side by Side Diff: base/prefs/json_pref_store.cc

Issue 1479473002: base: Use std::move() instead of Pass() for real movable types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: basepass: missing-include Created 5 years 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
« no previous file with comments | « base/prefs/default_pref_store.cc ('k') | base/prefs/json_pref_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/prefs/json_pref_store.h" 5 #include "base/prefs/json_pref_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/json/json_file_value_serializer.h" 14 #include "base/json/json_file_value_serializer.h"
14 #include "base/json/json_string_value_serializer.h" 15 #include "base/json/json_string_value_serializer.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_filter.h" 18 #include "base/prefs/pref_filter.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 new JsonPrefStore::ReadResult); 120 new JsonPrefStore::ReadResult);
120 JSONFileValueDeserializer deserializer(path); 121 JSONFileValueDeserializer deserializer(path);
121 read_result->value = deserializer.Deserialize(&error_code, &error_msg); 122 read_result->value = deserializer.Deserialize(&error_code, &error_msg);
122 read_result->error = 123 read_result->error =
123 HandleReadErrors(read_result->value.get(), path, error_code, error_msg); 124 HandleReadErrors(read_result->value.get(), path, error_code, error_msg);
124 read_result->no_dir = !base::PathExists(path.DirName()); 125 read_result->no_dir = !base::PathExists(path.DirName());
125 126
126 if (read_result->error == PersistentPrefStore::PREF_READ_ERROR_NONE) 127 if (read_result->error == PersistentPrefStore::PREF_READ_ERROR_NONE)
127 RecordJsonDataSizeHistogram(path, deserializer.get_last_read_size()); 128 RecordJsonDataSizeHistogram(path, deserializer.get_last_read_size());
128 129
129 return read_result.Pass(); 130 return read_result;
130 } 131 }
131 132
132 } // namespace 133 } // namespace
133 134
134 // static 135 // static
135 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile( 136 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile(
136 const base::FilePath& filename, 137 const base::FilePath& filename,
137 base::SequencedWorkerPool* worker_pool) { 138 base::SequencedWorkerPool* worker_pool) {
138 std::string token("json_pref_store-"); 139 std::string token("json_pref_store-");
139 token.append(filename.AsUTF8Unsafe()); 140 token.append(filename.AsUTF8Unsafe());
140 return worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 141 return worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
141 worker_pool->GetNamedSequenceToken(token), 142 worker_pool->GetNamedSequenceToken(token),
142 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 143 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
143 } 144 }
144 145
145 JsonPrefStore::JsonPrefStore( 146 JsonPrefStore::JsonPrefStore(
146 const base::FilePath& pref_filename, 147 const base::FilePath& pref_filename,
147 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, 148 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner,
148 scoped_ptr<PrefFilter> pref_filter) 149 scoped_ptr<PrefFilter> pref_filter)
149 : JsonPrefStore(pref_filename, 150 : JsonPrefStore(pref_filename,
150 base::FilePath(), 151 base::FilePath(),
151 sequenced_task_runner, 152 sequenced_task_runner,
152 pref_filter.Pass()) { 153 std::move(pref_filter)) {}
153 }
154 154
155 JsonPrefStore::JsonPrefStore( 155 JsonPrefStore::JsonPrefStore(
156 const base::FilePath& pref_filename, 156 const base::FilePath& pref_filename,
157 const base::FilePath& pref_alternate_filename, 157 const base::FilePath& pref_alternate_filename,
158 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner, 158 const scoped_refptr<base::SequencedTaskRunner>& sequenced_task_runner,
159 scoped_ptr<PrefFilter> pref_filter) 159 scoped_ptr<PrefFilter> pref_filter)
160 : path_(pref_filename), 160 : path_(pref_filename),
161 alternate_path_(pref_alternate_filename), 161 alternate_path_(pref_alternate_filename),
162 sequenced_task_runner_(sequenced_task_runner), 162 sequenced_task_runner_(sequenced_task_runner),
163 prefs_(new base::DictionaryValue()), 163 prefs_(new base::DictionaryValue()),
164 read_only_(false), 164 read_only_(false),
165 writer_(pref_filename, sequenced_task_runner), 165 writer_(pref_filename, sequenced_task_runner),
166 pref_filter_(pref_filter.Pass()), 166 pref_filter_(std::move(pref_filter)),
167 initialized_(false), 167 initialized_(false),
168 filtering_in_progress_(false), 168 filtering_in_progress_(false),
169 pending_lossy_write_(false), 169 pending_lossy_write_(false),
170 read_error_(PREF_READ_ERROR_NONE), 170 read_error_(PREF_READ_ERROR_NONE),
171 write_count_histogram_(writer_.commit_interval(), path_) { 171 write_count_histogram_(writer_.commit_interval(), path_) {
172 DCHECK(!path_.empty()); 172 DCHECK(!path_.empty());
173 } 173 }
174 174
175 bool JsonPrefStore::GetValue(const std::string& key, 175 bool JsonPrefStore::GetValue(const std::string& key,
176 const base::Value** result) const { 176 const base::Value** result) const {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 void JsonPrefStore::SetValue(const std::string& key, 219 void JsonPrefStore::SetValue(const std::string& key,
220 scoped_ptr<base::Value> value, 220 scoped_ptr<base::Value> value,
221 uint32 flags) { 221 uint32 flags) {
222 DCHECK(CalledOnValidThread()); 222 DCHECK(CalledOnValidThread());
223 223
224 DCHECK(value); 224 DCHECK(value);
225 base::Value* old_value = nullptr; 225 base::Value* old_value = nullptr;
226 prefs_->Get(key, &old_value); 226 prefs_->Get(key, &old_value);
227 if (!old_value || !value->Equals(old_value)) { 227 if (!old_value || !value->Equals(old_value)) {
228 prefs_->Set(key, value.Pass()); 228 prefs_->Set(key, std::move(value));
229 ReportValueChanged(key, flags); 229 ReportValueChanged(key, flags);
230 } 230 }
231 } 231 }
232 232
233 void JsonPrefStore::SetValueSilently(const std::string& key, 233 void JsonPrefStore::SetValueSilently(const std::string& key,
234 scoped_ptr<base::Value> value, 234 scoped_ptr<base::Value> value,
235 uint32 flags) { 235 uint32 flags) {
236 DCHECK(CalledOnValidThread()); 236 DCHECK(CalledOnValidThread());
237 237
238 DCHECK(value); 238 DCHECK(value);
239 base::Value* old_value = nullptr; 239 base::Value* old_value = nullptr;
240 prefs_->Get(key, &old_value); 240 prefs_->Get(key, &old_value);
241 if (!old_value || !value->Equals(old_value)) { 241 if (!old_value || !value->Equals(old_value)) {
242 prefs_->Set(key, value.Pass()); 242 prefs_->Set(key, std::move(value));
243 ScheduleWrite(flags); 243 ScheduleWrite(flags);
244 } 244 }
245 } 245 }
246 246
247 void JsonPrefStore::RemoveValue(const std::string& key, uint32 flags) { 247 void JsonPrefStore::RemoveValue(const std::string& key, uint32 flags) {
248 DCHECK(CalledOnValidThread()); 248 DCHECK(CalledOnValidThread());
249 249
250 if (prefs_->RemovePath(key, nullptr)) 250 if (prefs_->RemovePath(key, nullptr))
251 ReportValueChanged(key, flags); 251 ReportValueChanged(key, flags);
252 } 252 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 370 }
371 } 371 }
372 372
373 if (pref_filter_) { 373 if (pref_filter_) {
374 filtering_in_progress_ = true; 374 filtering_in_progress_ = true;
375 const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback( 375 const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
376 base::Bind( 376 base::Bind(
377 &JsonPrefStore::FinalizeFileRead, AsWeakPtr(), 377 &JsonPrefStore::FinalizeFileRead, AsWeakPtr(),
378 initialization_successful)); 378 initialization_successful));
379 pref_filter_->FilterOnLoad(post_filter_on_load_callback, 379 pref_filter_->FilterOnLoad(post_filter_on_load_callback,
380 unfiltered_prefs.Pass()); 380 std::move(unfiltered_prefs));
381 } else { 381 } else {
382 FinalizeFileRead(initialization_successful, unfiltered_prefs.Pass(), false); 382 FinalizeFileRead(initialization_successful, std::move(unfiltered_prefs),
383 false);
383 } 384 }
384 } 385 }
385 386
386 JsonPrefStore::~JsonPrefStore() { 387 JsonPrefStore::~JsonPrefStore() {
387 CommitPendingWrite(); 388 CommitPendingWrite();
388 } 389 }
389 390
390 bool JsonPrefStore::SerializeData(std::string* output) { 391 bool JsonPrefStore::SerializeData(std::string* output) {
391 DCHECK(CalledOnValidThread()); 392 DCHECK(CalledOnValidThread());
392 393
(...skipping 19 matching lines...) Expand all
412 413
413 filtering_in_progress_ = false; 414 filtering_in_progress_ = false;
414 415
415 if (!initialization_successful) { 416 if (!initialization_successful) {
416 FOR_EACH_OBSERVER(PrefStore::Observer, 417 FOR_EACH_OBSERVER(PrefStore::Observer,
417 observers_, 418 observers_,
418 OnInitializationCompleted(false)); 419 OnInitializationCompleted(false));
419 return; 420 return;
420 } 421 }
421 422
422 prefs_ = prefs.Pass(); 423 prefs_ = std::move(prefs);
423 424
424 initialized_ = true; 425 initialized_ = true;
425 426
426 if (schedule_write) 427 if (schedule_write)
427 ScheduleWrite(DEFAULT_PREF_WRITE_FLAGS); 428 ScheduleWrite(DEFAULT_PREF_WRITE_FLAGS);
428 429
429 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) 430 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE)
430 error_delegate_->OnError(read_error_); 431 error_delegate_->OnError(read_error_);
431 432
432 FOR_EACH_OBSERVER(PrefStore::Observer, 433 FOR_EACH_OBSERVER(PrefStore::Observer,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 DCHECK_EQ(31, num_buckets); 527 DCHECK_EQ(31, num_buckets);
527 528
528 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS 529 // The histogram below is an expansion of the UMA_HISTOGRAM_CUSTOM_COUNTS
529 // macro adapted to allow for a dynamically suffixed histogram name. 530 // macro adapted to allow for a dynamically suffixed histogram name.
530 // Note: The factory creates and owns the histogram. 531 // Note: The factory creates and owns the histogram.
531 base::HistogramBase* histogram = base::Histogram::FactoryGet( 532 base::HistogramBase* histogram = base::Histogram::FactoryGet(
532 histogram_name, min_value, max_value, num_buckets, 533 histogram_name, min_value, max_value, num_buckets,
533 base::HistogramBase::kUmaTargetedHistogramFlag); 534 base::HistogramBase::kUmaTargetedHistogramFlag);
534 return histogram; 535 return histogram;
535 } 536 }
OLDNEW
« no previous file with comments | « base/prefs/default_pref_store.cc ('k') | base/prefs/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698