| 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 initialized_ = false; | 274 initialized_ = false; |
| 275 error_delegate_.reset(error_delegate); | 275 error_delegate_.reset(error_delegate); |
| 276 if (path_.empty()) { | 276 if (path_.empty()) { |
| 277 scoped_ptr<ReadResult> no_file_result; | 277 scoped_ptr<ReadResult> no_file_result; |
| 278 no_file_result->error = PREF_READ_ERROR_FILE_NOT_SPECIFIED; | 278 no_file_result->error = PREF_READ_ERROR_FILE_NOT_SPECIFIED; |
| 279 OnFileRead(no_file_result.Pass()); | 279 OnFileRead(no_file_result.Pass()); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Weakly binds the read task so that it doesn't kick in during shutdown. |
| 283 base::PostTaskAndReplyWithResult( | 284 base::PostTaskAndReplyWithResult( |
| 284 sequenced_task_runner_, | 285 sequenced_task_runner_, |
| 285 FROM_HERE, | 286 FROM_HERE, |
| 286 base::Bind(&ReadPrefsFromDisk, path_, alternate_path_), | 287 base::Bind(&ReadPrefsFromDisk, path_, alternate_path_), |
| 287 base::Bind(&JsonPrefStore::OnFileRead, this)); | 288 base::Bind(&JsonPrefStore::OnFileRead, AsWeakPtr())); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void JsonPrefStore::CommitPendingWrite() { | 291 void JsonPrefStore::CommitPendingWrite() { |
| 291 DCHECK(CalledOnValidThread()); | 292 DCHECK(CalledOnValidThread()); |
| 292 | 293 |
| 293 if (writer_.HasPendingWrite() && !read_only_) | 294 if (writer_.HasPendingWrite() && !read_only_) |
| 294 writer_.DoScheduledWrite(); | 295 writer_.DoScheduledWrite(); |
| 295 } | 296 } |
| 296 | 297 |
| 297 void JsonPrefStore::ReportValueChanged(const std::string& key) { | 298 void JsonPrefStore::ReportValueChanged(const std::string& key) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 case PREF_READ_ERROR_MAX_ENUM: | 360 case PREF_READ_ERROR_MAX_ENUM: |
| 360 NOTREACHED(); | 361 NOTREACHED(); |
| 361 break; | 362 break; |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 | 365 |
| 365 if (pref_filter_) { | 366 if (pref_filter_) { |
| 366 filtering_in_progress_ = true; | 367 filtering_in_progress_ = true; |
| 367 const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback( | 368 const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback( |
| 368 base::Bind( | 369 base::Bind( |
| 369 &JsonPrefStore::FinalizeFileRead, this, initialization_successful)); | 370 &JsonPrefStore::FinalizeFileRead, AsWeakPtr(), |
| 371 initialization_successful)); |
| 370 pref_filter_->FilterOnLoad(post_filter_on_load_callback, | 372 pref_filter_->FilterOnLoad(post_filter_on_load_callback, |
| 371 unfiltered_prefs.Pass()); | 373 unfiltered_prefs.Pass()); |
| 372 } else { | 374 } else { |
| 373 FinalizeFileRead(initialization_successful, unfiltered_prefs.Pass(), false); | 375 FinalizeFileRead(initialization_successful, unfiltered_prefs.Pass(), false); |
| 374 } | 376 } |
| 375 } | 377 } |
| 376 | 378 |
| 377 JsonPrefStore::~JsonPrefStore() { | 379 JsonPrefStore::~JsonPrefStore() { |
| 378 CommitPendingWrite(); | 380 CommitPendingWrite(); |
| 379 } | 381 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 434 |
| 433 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) | 435 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) |
| 434 error_delegate_->OnError(read_error_); | 436 error_delegate_->OnError(read_error_); |
| 435 | 437 |
| 436 FOR_EACH_OBSERVER(PrefStore::Observer, | 438 FOR_EACH_OBSERVER(PrefStore::Observer, |
| 437 observers_, | 439 observers_, |
| 438 OnInitializationCompleted(true)); | 440 OnInitializationCompleted(true)); |
| 439 | 441 |
| 440 return; | 442 return; |
| 441 } | 443 } |
| OLD | NEW |