app_sync_ui_state_factory.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/ui/ash/app_sync_ui_state_factory.h"
6
7#include "chrome/browser/profiles/profile.h"
8#include "chrome/browser/sync/profile_sync_service_factory.h"
9#include "chrome/browser/ui/ash/app_sync_ui_state.h"
10#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
11
12// static
13AppSyncUIState* AppSyncUIStateFactory::GetForProfile(Profile* profile) {
14  if (!AppSyncUIState::ShouldObserveAppSyncForProfile(profile))
15    return NULL;
16
17  return static_cast<AppSyncUIState*>(
18      GetInstance()->GetServiceForBrowserContext(profile, true));
19}
20
21// static
22AppSyncUIStateFactory* AppSyncUIStateFactory::GetInstance() {
23  return Singleton<AppSyncUIStateFactory>::get();
24}
25
26AppSyncUIStateFactory::AppSyncUIStateFactory()
27    : BrowserContextKeyedServiceFactory(
28        "AppSyncUIState",
29        BrowserContextDependencyManager::GetInstance()) {
30  DependsOn(ProfileSyncServiceFactory::GetInstance());
31}
32
33AppSyncUIStateFactory::~AppSyncUIStateFactory() {
34}
35
36BrowserContextKeyedService* AppSyncUIStateFactory::BuildServiceInstanceFor(
37    content::BrowserContext* context) const {
38  Profile* profile = static_cast<Profile*>(context);
39  DCHECK(AppSyncUIState::ShouldObserveAppSyncForProfile(profile));
40  return new AppSyncUIState(profile);
41}
42