| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/prefs/tracked/interceptable_pref_filter.h" | 5 #include "components/user_prefs/tracked/interceptable_pref_filter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 | 8 |
| 9 InterceptablePrefFilter::InterceptablePrefFilter() {} | 9 InterceptablePrefFilter::InterceptablePrefFilter() { |
| 10 InterceptablePrefFilter::~InterceptablePrefFilter() {} | 10 } |
| 11 InterceptablePrefFilter::~InterceptablePrefFilter() { |
| 12 } |
| 11 | 13 |
| 12 void InterceptablePrefFilter::FilterOnLoad( | 14 void InterceptablePrefFilter::FilterOnLoad( |
| 13 const PostFilterOnLoadCallback& post_filter_on_load_callback, | 15 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
| 14 scoped_ptr<base::DictionaryValue> pref_store_contents) { | 16 scoped_ptr<base::DictionaryValue> pref_store_contents) { |
| 15 if (filter_on_load_interceptor_.is_null()) { | 17 if (filter_on_load_interceptor_.is_null()) { |
| 16 FinalizeFilterOnLoad(post_filter_on_load_callback, | 18 FinalizeFilterOnLoad(post_filter_on_load_callback, |
| 17 pref_store_contents.Pass(), | 19 pref_store_contents.Pass(), false); |
| 18 false); | |
| 19 } else { | 20 } else { |
| 20 // Note, in practice (in the implementation as it was in May 2014) it would | 21 // Note, in practice (in the implementation as it was in May 2014) it would |
| 21 // be okay to pass an unretained |this| pointer below, but in order to avoid | 22 // be okay to pass an unretained |this| pointer below, but in order to avoid |
| 22 // having to augment the API everywhere to explicitly enforce the ownership | 23 // having to augment the API everywhere to explicitly enforce the ownership |
| 23 // model as it happens to currently be: make the relationship simpler by | 24 // model as it happens to currently be: make the relationship simpler by |
| 24 // weakly binding the FinalizeFilterOnLoadCallback below to |this|. | 25 // weakly binding the FinalizeFilterOnLoadCallback below to |this|. |
| 25 const FinalizeFilterOnLoadCallback finalize_filter_on_load( | 26 const FinalizeFilterOnLoadCallback finalize_filter_on_load( |
| 26 base::Bind(&InterceptablePrefFilter::FinalizeFilterOnLoad, | 27 base::Bind(&InterceptablePrefFilter::FinalizeFilterOnLoad, AsWeakPtr(), |
| 27 AsWeakPtr(), | |
| 28 post_filter_on_load_callback)); | 28 post_filter_on_load_callback)); |
| 29 filter_on_load_interceptor_.Run(finalize_filter_on_load, | 29 filter_on_load_interceptor_.Run(finalize_filter_on_load, |
| 30 pref_store_contents.Pass()); | 30 pref_store_contents.Pass()); |
| 31 filter_on_load_interceptor_.Reset(); | 31 filter_on_load_interceptor_.Reset(); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 void InterceptablePrefFilter::InterceptNextFilterOnLoad( | 35 void InterceptablePrefFilter::InterceptNextFilterOnLoad( |
| 36 const FilterOnLoadInterceptor& filter_on_load_interceptor) { | 36 const FilterOnLoadInterceptor& filter_on_load_interceptor) { |
| 37 DCHECK(filter_on_load_interceptor_.is_null()); | 37 DCHECK(filter_on_load_interceptor_.is_null()); |
| 38 filter_on_load_interceptor_ = filter_on_load_interceptor; | 38 filter_on_load_interceptor_ = filter_on_load_interceptor; |
| 39 } | 39 } |
| OLD | NEW |