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 "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
6
7#include "base/run_loop.h"
8#include "chrome/browser/browser_process.h"
9#include "chrome/browser/profiles/profile_manager.h"
10#include "chrome/browser/ui/app_list/app_list_service.h"
11#include "chrome/browser/ui/app_list/app_list_service_impl.h"
12#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
13#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
14
15namespace test {
16
17namespace {
18
19class CreateProfileHelper {
20 public:
21  CreateProfileHelper() : profile_(NULL) {}
22
23  Profile* CreateAsync() {
24    ProfileManager* profile_manager = g_browser_process->profile_manager();
25    base::FilePath temp_profile_dir =
26        profile_manager->user_data_dir().AppendASCII("Profile 1");
27    profile_manager->CreateProfileAsync(
28        temp_profile_dir,
29        base::Bind(&CreateProfileHelper::OnProfileCreated,
30                   base::Unretained(this)),
31        base::string16(),
32        base::string16(),
33        std::string());
34    run_loop_.Run();
35    return profile_;
36  }
37
38 private:
39  void OnProfileCreated(Profile* profile, Profile::CreateStatus status) {
40    if (status == Profile::CREATE_STATUS_INITIALIZED) {
41      profile_ = profile;
42      run_loop_.Quit();
43    }
44  }
45
46  base::RunLoop run_loop_;
47  Profile* profile_;
48
49  DISALLOW_COPY_AND_ASSIGN(CreateProfileHelper);
50};
51
52}  // namespace
53
54app_list::AppListModel* GetAppListModel(AppListService* service) {
55  return app_list::AppListSyncableServiceFactory::GetForProfile(
56      service->GetCurrentAppListProfile())->model();
57}
58
59AppListService* GetAppListService() {
60  // TODO(tapted): Consider testing ash explicitly on the win-ash trybot.
61  return AppListService::Get(chrome::GetActiveDesktop());
62}
63
64AppListServiceImpl* GetAppListServiceImpl() {
65  // AppListServiceImpl is the only subclass of AppListService, which has pure
66  // virtuals. So this must either be NULL, or an AppListServiceImpl.
67  return static_cast<AppListServiceImpl*>(GetAppListService());
68}
69
70Profile* CreateSecondProfileAsync() {
71  CreateProfileHelper helper;
72  return helper.CreateAsync();
73}
74
75}  // namespace test
76