app_sync_ui_state_factory.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/profiles/profile_dependency_manager.h"
9#include "chrome/browser/sync/profile_sync_service_factory.h"
10#include "chrome/browser/ui/ash/app_sync_ui_state.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()->GetServiceForProfile(profile, true));
19}
20
21// static
22AppSyncUIStateFactory* AppSyncUIStateFactory::GetInstance() {
23  return Singleton<AppSyncUIStateFactory>::get();
24}
25
26AppSyncUIStateFactory::AppSyncUIStateFactory()
27    : ProfileKeyedServiceFactory("AppSyncUIState",
28                                 ProfileDependencyManager::GetInstance()) {
29  DependsOn(ProfileSyncServiceFactory::GetInstance());
30}
31
32AppSyncUIStateFactory::~AppSyncUIStateFactory() {
33}
34
35ProfileKeyedService* AppSyncUIStateFactory::BuildServiceInstanceFor(
36    content::BrowserContext* context) const {
37  Profile* profile = static_cast<Profile*>(context);
38  DCHECK(AppSyncUIState::ShouldObserveAppSyncForProfile(profile));
39  return new AppSyncUIState(profile);
40}
41