themes_helper.cc revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright (c) 2011 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/test/integration/themes_helper.h"
6
7#include "base/logging.h"
8#include "base/strings/string_number_conversions.h"
9#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
10#include "chrome/browser/sync/test/integration/sync_extension_helper.h"
11#include "chrome/browser/themes/theme_service.h"
12#include "chrome/browser/themes/theme_service_factory.h"
13#include "extensions/common/extension.h"
14#include "extensions/common/id_util.h"
15#include "extensions/common/manifest.h"
16
17using sync_datatype_helper::test;
18
19namespace {
20
21// Make a name to pass to an extension helper.
22std::string MakeName(int index) {
23  return "faketheme" + base::IntToString(index);
24}
25
26ThemeService* GetThemeService(Profile* profile) {
27  return ThemeServiceFactory::GetForProfile(profile);
28}
29
30}  // namespace
31
32namespace themes_helper {
33
34std::string GetCustomTheme(int index) {
35  return extensions::id_util::GenerateId(MakeName(index));
36}
37
38std::string GetThemeID(Profile* profile) {
39  return GetThemeService(profile)->GetThemeID();
40}
41
42bool UsingCustomTheme(Profile* profile) {
43  return GetThemeID(profile) != ThemeService::kDefaultThemeID;
44}
45
46bool UsingDefaultTheme(Profile* profile) {
47  return GetThemeService(profile)->UsingDefaultTheme();
48}
49
50bool UsingNativeTheme(Profile* profile) {
51  return GetThemeService(profile)->UsingNativeTheme();
52}
53
54bool ThemeIsPendingInstall(Profile* profile, const std::string& id) {
55  return SyncExtensionHelper::GetInstance()->
56      IsExtensionPendingInstallForSync(profile, id);
57}
58
59bool HasOrWillHaveCustomTheme(Profile* profile, const std::string& id) {
60  return (GetThemeID(profile) == id) || ThemeIsPendingInstall(profile, id);
61}
62
63void UseCustomTheme(Profile* profile, int index) {
64  SyncExtensionHelper::GetInstance()->InstallExtension(
65      profile, MakeName(index), extensions::Manifest::TYPE_THEME);
66}
67
68void UseDefaultTheme(Profile* profile) {
69  GetThemeService(profile)->UseDefaultTheme();
70}
71
72void UseNativeTheme(Profile* profile) {
73  // TODO(akalin): Fix this inconsistent naming in the theme service.
74  GetThemeService(profile)->SetNativeTheme();
75}
76
77}  // namespace themes_helper
78