1 // Copyright 2013 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.
5 #include "chrome/browser/drive/drive_notification_manager_factory.h"
7 #include "base/logging.h"
8 #include "chrome/browser/drive/drive_notification_manager.h"
9 #include "chrome/browser/invalidation/invalidation_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/browser/sync/profile_sync_service_factory.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 DriveNotificationManager
*
19 DriveNotificationManagerFactory::FindForBrowserContext(
20 content::BrowserContext
* context
) {
21 return static_cast<DriveNotificationManager
*>(
22 GetInstance()->GetServiceForBrowserContext(context
, false));
26 DriveNotificationManager
*
27 DriveNotificationManagerFactory::GetForBrowserContext(
28 content::BrowserContext
* context
) {
29 if (!ProfileSyncService::IsSyncEnabled())
31 if (!invalidation::InvalidationServiceFactory::GetForProfile(
32 Profile::FromBrowserContext(context
))) {
33 // Do not create a DriveNotificationManager for |context|s that do not
34 // support invalidation.
38 return static_cast<DriveNotificationManager
*>(
39 GetInstance()->GetServiceForBrowserContext(context
, true));
43 DriveNotificationManagerFactory
*
44 DriveNotificationManagerFactory::GetInstance() {
45 return Singleton
<DriveNotificationManagerFactory
>::get();
48 DriveNotificationManagerFactory::DriveNotificationManagerFactory()
49 : BrowserContextKeyedServiceFactory(
50 "DriveNotificationManager",
51 BrowserContextDependencyManager::GetInstance()) {
52 DependsOn(ProfileSyncServiceFactory::GetInstance());
53 DependsOn(invalidation::InvalidationServiceFactory::GetInstance());
56 DriveNotificationManagerFactory::~DriveNotificationManagerFactory() {}
58 KeyedService
* DriveNotificationManagerFactory::BuildServiceInstanceFor(
59 content::BrowserContext
* context
) const {
60 invalidation::InvalidationService
* invalidation_service
=
61 invalidation::InvalidationServiceFactory::GetForProfile(
62 Profile::FromBrowserContext(context
));
63 DCHECK(invalidation_service
);
64 return new DriveNotificationManager(invalidation_service
);