1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ 6 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ 7 #pragma once 8 9 #include "base/basictypes.h" 10 #include "base/message_loop.h" 11 #include "chrome/browser/webdata/web_data_service.h" 12 #include "content/browser/browser_thread.h" 13 14 template <class T> 15 class AutofillWebDataServiceConsumer: public WebDataServiceConsumer { 16 public: AutofillWebDataServiceConsumer()17 AutofillWebDataServiceConsumer() : handle_(0) {} ~AutofillWebDataServiceConsumer()18 virtual ~AutofillWebDataServiceConsumer() {} 19 OnWebDataServiceRequestDone(WebDataService::Handle handle,const WDTypedResult * result)20 virtual void OnWebDataServiceRequestDone(WebDataService::Handle handle, 21 const WDTypedResult* result) { 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 23 handle_ = handle; 24 const WDResult<T>* wrapped_result = 25 static_cast<const WDResult<T>*>(result); 26 result_ = wrapped_result->GetValue(); 27 28 MessageLoop::current()->Quit(); 29 } 30 handle()31 WebDataService::Handle handle() { return handle_; } result()32 T& result() { return result_; } 33 34 private: 35 WebDataService::Handle handle_; 36 T result_; 37 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataServiceConsumer); 38 }; 39 40 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_TEST_UTIL_H__ 41