1 // Copyright 2013 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 "base/prefs/pref_service.h" 6 #include "chrome/browser/android/prerender_condition_platform.h" 7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/common/pref_names.h" 10 11 namespace android { 12 13 namespace { 14 15 const char kAllowPrerender[] = "allow-prerender"; 16 17 class BooleanWrapper : public base::SupportsUserData::Data { 18 public: BooleanWrapper(bool b)19 explicit BooleanWrapper(bool b) : m_b(b) { } ~BooleanWrapper()20 virtual ~BooleanWrapper() { } 21 operator bool() const22 operator bool() const { return m_b; } 23 private: 24 bool m_b; 25 DISALLOW_COPY_AND_ASSIGN(BooleanWrapper); 26 }; 27 28 } // namespace 29 PrerenderConditionPlatform(content::BrowserContext * context)30PrerenderConditionPlatform::PrerenderConditionPlatform( 31 content::BrowserContext* context) 32 : context_(context) {} 33 ~PrerenderConditionPlatform()34PrerenderConditionPlatform::~PrerenderConditionPlatform() {} 35 CanPrerender() const36bool PrerenderConditionPlatform::CanPrerender() const { 37 base::SupportsUserData::Data* data = context_->GetUserData(kAllowPrerender); 38 if (!data) 39 return true; 40 BooleanWrapper* b = static_cast<BooleanWrapper*>(data); 41 return *b; 42 } 43 SetEnabled(content::BrowserContext * context,bool enabled)44void PrerenderConditionPlatform::SetEnabled(content::BrowserContext* context, 45 bool enabled) { 46 BooleanWrapper* wrapper = new BooleanWrapper(enabled); 47 context->SetUserData(kAllowPrerender, wrapper); 48 } 49 50 } // namespace android 51