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 3// found in the LICENSE file. 4 5#include "chrome/browser/prefs/interceptable_pref_filter.h" 6 7#include "base/bind.h" 8 9InterceptablePrefFilter::InterceptablePrefFilter() {} 10InterceptablePrefFilter::~InterceptablePrefFilter() {} 11 12void InterceptablePrefFilter::FilterOnLoad( 13 const PostFilterOnLoadCallback& post_filter_on_load_callback, 14 scoped_ptr<base::DictionaryValue> pref_store_contents) { 15 if (filter_on_load_interceptor_.is_null()) { 16 FinalizeFilterOnLoad(post_filter_on_load_callback, 17 pref_store_contents.Pass(), 18 false); 19 } else { 20 // 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 // 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 // weakly binding the FinalizeFilterOnLoadCallback below to |this|. 25 const FinalizeFilterOnLoadCallback finalize_filter_on_load( 26 base::Bind(&InterceptablePrefFilter::FinalizeFilterOnLoad, 27 AsWeakPtr(), 28 post_filter_on_load_callback)); 29 filter_on_load_interceptor_.Run(finalize_filter_on_load, 30 pref_store_contents.Pass()); 31 filter_on_load_interceptor_.Reset(); 32 } 33} 34 35void InterceptablePrefFilter::InterceptNextFilterOnLoad( 36 const FilterOnLoadInterceptor& filter_on_load_interceptor) { 37 DCHECK(filter_on_load_interceptor_.is_null()); 38 filter_on_load_interceptor_ = filter_on_load_interceptor; 39} 40