OLD | NEW |
---|---|
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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 250 } |
251 | 251 |
252 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const { | 252 PersistentPrefStore::PrefReadError JsonPrefStore::GetReadError() const { |
253 DCHECK(CalledOnValidThread()); | 253 DCHECK(CalledOnValidThread()); |
254 | 254 |
255 return read_error_; | 255 return read_error_; |
256 } | 256 } |
257 | 257 |
258 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { | 258 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { |
259 DCHECK(CalledOnValidThread()); | 259 DCHECK(CalledOnValidThread()); |
260 | 260 DCHECK(!path_.empty()); |
Bernhard Bauer
2015/01/07 11:01:03
Can we do this check at construction time?
Daniel Bratell
2015/01/07 13:44:34
Done.
| |
261 if (path_.empty()) { | |
262 scoped_ptr<ReadResult> no_file_result; | |
263 no_file_result->error = PREF_READ_ERROR_FILE_NOT_SPECIFIED; | |
264 OnFileRead(no_file_result.Pass()); | |
265 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; | |
266 } | |
267 | 261 |
268 OnFileRead(ReadPrefsFromDisk(path_, alternate_path_)); | 262 OnFileRead(ReadPrefsFromDisk(path_, alternate_path_)); |
269 return filtering_in_progress_ ? PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE | 263 return filtering_in_progress_ ? PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE |
270 : read_error_; | 264 : read_error_; |
271 } | 265 } |
272 | 266 |
273 void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate) { | 267 void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate) { |
274 DCHECK(CalledOnValidThread()); | 268 DCHECK(CalledOnValidThread()); |
269 DCHECK(!path_.empty()); | |
275 | 270 |
276 initialized_ = false; | 271 initialized_ = false; |
277 error_delegate_.reset(error_delegate); | 272 error_delegate_.reset(error_delegate); |
278 if (path_.empty()) { | |
279 scoped_ptr<ReadResult> no_file_result; | |
280 no_file_result->error = PREF_READ_ERROR_FILE_NOT_SPECIFIED; | |
281 OnFileRead(no_file_result.Pass()); | |
282 return; | |
283 } | |
284 | 273 |
285 // Weakly binds the read task so that it doesn't kick in during shutdown. | 274 // Weakly binds the read task so that it doesn't kick in during shutdown. |
286 base::PostTaskAndReplyWithResult( | 275 base::PostTaskAndReplyWithResult( |
287 sequenced_task_runner_.get(), | 276 sequenced_task_runner_.get(), |
288 FROM_HERE, | 277 FROM_HERE, |
289 base::Bind(&ReadPrefsFromDisk, path_, alternate_path_), | 278 base::Bind(&ReadPrefsFromDisk, path_, alternate_path_), |
290 base::Bind(&JsonPrefStore::OnFileRead, AsWeakPtr())); | 279 base::Bind(&JsonPrefStore::OnFileRead, AsWeakPtr())); |
291 } | 280 } |
292 | 281 |
293 void JsonPrefStore::CommitPendingWrite() { | 282 void JsonPrefStore::CommitPendingWrite() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 | 425 |
437 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) | 426 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) |
438 error_delegate_->OnError(read_error_); | 427 error_delegate_->OnError(read_error_); |
439 | 428 |
440 FOR_EACH_OBSERVER(PrefStore::Observer, | 429 FOR_EACH_OBSERVER(PrefStore::Observer, |
441 observers_, | 430 observers_, |
442 OnInitializationCompleted(true)); | 431 OnInitializationCompleted(true)); |
443 | 432 |
444 return; | 433 return; |
445 } | 434 } |
OLD | NEW |