OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/garbled_text_test_helper.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/garbled_text_service.h" |
| 10 #include "chrome/browser/garbled_text_url_tracker.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 void CreateTrackerOnIOThread(GarbledTextServiceParams* params, |
| 17 const BooleanPrefMember* enabled, |
| 18 scoped_ptr<GarbledTextURLTracker>* tracker) { |
| 19 *tracker = params->CreateTracker(*enabled).Pass(); |
| 20 } |
| 21 |
| 22 } // anonymous namespace |
| 23 |
| 24 GarbledTextTestHelper::GarbledTextTestHelper(Profile* profile) |
| 25 : profile_(profile) { |
| 26 } |
| 27 |
| 28 GarbledTextTestHelper::~GarbledTextTestHelper() { |
| 29 } |
| 30 |
| 31 void GarbledTextTestHelper::Initialize() { |
| 32 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 33 content::BrowserThread::PostTask( |
| 34 content::BrowserThread::UI, |
| 35 FROM_HERE, |
| 36 base::Bind(&GarbledTextTestHelper::Initialize, |
| 37 base::Unretained(this))); |
| 38 MessageLoop::current()->RunAllPending(); |
| 39 return; |
| 40 } |
| 41 |
| 42 GarbledTextServiceFactory::GetInstance()-> |
| 43 RegisterUserPrefs(profile()->GetPrefs()); |
| 44 enabled_.Init(prefs::kEnableAutoGarbledTextFix, profile()->GetPrefs(), NULL); |
| 45 enabled_.MoveToThread(content::BrowserThread::IO); |
| 46 |
| 47 content::BrowserThread::PostTask( |
| 48 content::BrowserThread::IO, |
| 49 FROM_HERE, |
| 50 base::Bind(&CreateTrackerOnIOThread, |
| 51 base::Owned(new GarbledTextServiceParams( |
| 52 profile()->GetPrefs(), service())), |
| 53 &enabled_, &tracker_)); |
| 54 MessageLoop::current()->RunAllPending(); |
| 55 } |
| 56 |
| 57 GarbledTextService* GarbledTextTestHelper::service() { |
| 58 return GarbledTextServiceFactory::GetForProfile(profile()); |
| 59 } |
OLD | NEW |