107b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org// Copyright 2014 The Chromium Authors. All rights reserved.
207b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org// Use of this source code is governed by a BSD-style license that can be
39be1d37a9a6561f135412db66806def9f82a29c1steveblock@chromium.org// found in the LICENSE file.
407b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
507b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "chrome/browser/sync/sync_error_notifier_factory_ash.h"
607b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
707b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "ash/shell.h"
87a9d1ab1b214d7342b5a6d3ae4837fd572a8f4d0evan@chromium.org#include "chrome/browser/browser_process.h"
907b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "chrome/browser/profiles/profile.h"
1007b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "chrome/browser/sync/profile_sync_service.h"
1107b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "chrome/browser/sync/profile_sync_service_factory.h"
1207b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "chrome/browser/sync/sync_error_notifier_ash.h"
1307b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org#include "components/keyed_service/content/browser_context_dependency_manager.h"
1407b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
1507b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.orgSyncErrorNotifierFactory::SyncErrorNotifierFactory()
16dc9d50a9c015fa86d8ffae123d63173cf5bd7b73torne@chromium.org    : BrowserContextKeyedServiceFactory(
17dc9d50a9c015fa86d8ffae123d63173cf5bd7b73torne@chromium.org        "SyncErrorNotifier",
1807b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org        BrowserContextDependencyManager::GetInstance()) {
1907b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org  DependsOn(ProfileSyncServiceFactory::GetInstance());
2007b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org}
218051f4242ca0291165aef138ab4b621eb3128d92thomasvl@chromium.org
2207b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.orgSyncErrorNotifierFactory::~SyncErrorNotifierFactory() {}
2307b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
247a9d1ab1b214d7342b5a6d3ae4837fd572a8f4d0evan@chromium.org// static
2507b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.orgSyncErrorNotifier* SyncErrorNotifierFactory::GetForProfile(
2607b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org    Profile* profile) {
2707b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org  return static_cast<SyncErrorNotifier*>(
2807b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org      GetInstance()->GetServiceForBrowserContext(profile, true));
2907b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org}
3007b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
31a7fd578d98e5fff82dfd51d8a8e41f8392ff38b7bradnelson@google.com// static
3207b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.orgSyncErrorNotifierFactory* SyncErrorNotifierFactory::GetInstance() {
337a9d1ab1b214d7342b5a6d3ae4837fd572a8f4d0evan@chromium.org  return Singleton<SyncErrorNotifierFactory>::get();
3407b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org}
3507b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
3607b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.orgKeyedService* SyncErrorNotifierFactory::BuildServiceInstanceFor(
3707b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org    content::BrowserContext* context) const {
388051f4242ca0291165aef138ab4b621eb3128d92thomasvl@chromium.org  if (!ash::Shell::HasInstance())
3907b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org    return NULL;
4007b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
4107b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org  Profile* profile = static_cast<Profile*>(context);
42a7fd578d98e5fff82dfd51d8a8e41f8392ff38b7bradnelson@google.com  ProfileSyncService* profile_sync_service =
4307b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org      ProfileSyncServiceFactory::GetForProfile(profile);
4407b131e8ffa26908c78fa6fdc54afaae01367febmmoss@chromium.org
45  if (!profile_sync_service)
46    return NULL;
47
48  SyncErrorController* sync_error_controller =
49      profile_sync_service->sync_error_controller();
50  if (!sync_error_controller)
51    return NULL;
52
53  return new SyncErrorNotifier(sync_error_controller, profile);
54}
55