15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/ash/app_sync_ui_state_factory.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/profile.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/sync/profile_sync_service_factory.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/ash/app_sync_ui_state.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_dependency_manager.h"
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "extensions/browser/extension_registry_factory.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AppSyncUIState* AppSyncUIStateFactory::GetForProfile(Profile* profile) {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!AppSyncUIState::ShouldObserveAppSyncForProfile(profile))
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return NULL;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return static_cast<AppSyncUIState*>(
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      GetInstance()->GetServiceForBrowserContext(profile, true));
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AppSyncUIStateFactory* AppSyncUIStateFactory::GetInstance() {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Singleton<AppSyncUIStateFactory>::get();
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AppSyncUIStateFactory::AppSyncUIStateFactory()
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    : BrowserContextKeyedServiceFactory(
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        "AppSyncUIState",
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        BrowserContextDependencyManager::GetInstance()) {
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DependsOn(ProfileSyncServiceFactory::GetInstance());
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AppSyncUIStateFactory::~AppSyncUIStateFactory() {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* AppSyncUIStateFactory::BuildServiceInstanceFor(
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    content::BrowserContext* context) const {
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Profile* profile = static_cast<Profile*>(context);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(AppSyncUIState::ShouldObserveAppSyncForProfile(profile));
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new AppSyncUIState(profile);
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
44