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/sync_file_system/sync_file_system_test_util.h" 6 7#include "base/memory/scoped_ptr.h" 8#include "base/run_loop.h" 9#include "chrome/browser/sync_file_system/remote_file_sync_service.h" 10#include "chrome/browser/sync_file_system/sync_status_code.h" 11#include "content/public/test/test_utils.h" 12#include "google_apis/drive/gdata_errorcode.h" 13 14using content::BrowserThread; 15 16namespace sync_file_system { 17 18namespace drive_backend { 19class MetadataDatabase; 20} // drive_backend 21 22template <typename R> 23void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result) { 24 DCHECK(result_out); 25 DCHECK(run_loop); 26 *result_out = result; 27 run_loop->Quit(); 28} 29 30template <typename R> base::Callback<void(R)> 31AssignAndQuitCallback(base::RunLoop* run_loop, R* result) { 32 return base::Bind(&AssignAndQuit<R>, run_loop, base::Unretained(result)); 33} 34 35template <typename Arg, typename Param> 36void ReceiveResult1(bool* done, Arg* arg_out, Param arg) { 37 EXPECT_FALSE(*done); 38 *done = true; 39 *arg_out = base::internal::CallbackForward(arg); 40} 41 42template <typename Arg> 43base::Callback<void(typename TypeTraits<Arg>::ParamType)> 44CreateResultReceiver(Arg* arg_out) { 45 typedef typename TypeTraits<Arg>::ParamType Param; 46 return base::Bind(&ReceiveResult1<Arg, Param>, 47 base::Owned(new bool(false)), arg_out); 48} 49 50// Instantiate versions we know callers will need. 51template base::Callback<void(SyncStatusCode)> 52AssignAndQuitCallback(base::RunLoop*, SyncStatusCode*); 53 54#define INSTANTIATE_RECEIVER(type) \ 55 template base::Callback<void(type)> CreateResultReceiver(type*); 56INSTANTIATE_RECEIVER(SyncStatusCode); 57INSTANTIATE_RECEIVER(google_apis::GDataErrorCode); 58INSTANTIATE_RECEIVER(scoped_ptr<RemoteFileSyncService::OriginStatusMap>); 59#undef INSTANTIATE_RECEIVER 60 61} // namespace sync_file_system 62