Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / sync_notifier / chrome_notifier_service_factory.cc
1 // Copyright (c) 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.
4
5 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
6
7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
10 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service_factory.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/chrome_version_info.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14
15 namespace notifier {
16
17 // static
18 ChromeNotifierService* ChromeNotifierServiceFactory::GetForProfile(
19     Profile* profile, Profile::ServiceAccessType service_access_type) {
20   return static_cast<ChromeNotifierService*>(
21       GetInstance()->GetServiceForBrowserContext(profile, true));
22 }
23
24 // static
25 ChromeNotifierServiceFactory* ChromeNotifierServiceFactory::GetInstance() {
26   return Singleton<ChromeNotifierServiceFactory>::get();
27 }
28
29 // static
30 bool ChromeNotifierServiceFactory::UseSyncedNotifications(
31     CommandLine* command_line) {
32   if (command_line->HasSwitch(switches::kDisableSyncSyncedNotifications))
33     return false;
34   if (command_line->HasSwitch(switches::kEnableSyncSyncedNotifications))
35     return true;
36
37   // enable it by default for canary and dev
38   chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
39   if (channel == chrome::VersionInfo::CHANNEL_UNKNOWN ||
40       channel == chrome::VersionInfo::CHANNEL_DEV ||
41       channel == chrome::VersionInfo::CHANNEL_CANARY)
42     return true;
43
44   return false;
45 }
46
47 ChromeNotifierServiceFactory::ChromeNotifierServiceFactory()
48     : BrowserContextKeyedServiceFactory(
49           "ChromeNotifierService",
50           BrowserContextDependencyManager::GetInstance()) {
51   // Mark this service as depending on the SyncedNotificationAppInfoService.
52   // Marking it provides a guarantee that the other service will alwasys be
53   // running whenever the ChromeNotifierServiceFactory is.
54   DependsOn(SyncedNotificationAppInfoServiceFactory::GetInstance());
55 }
56
57 ChromeNotifierServiceFactory::~ChromeNotifierServiceFactory() {
58 }
59
60 KeyedService* ChromeNotifierServiceFactory::BuildServiceInstanceFor(
61     content::BrowserContext* profile) const {
62   NotificationUIManager* notification_manager =
63       g_browser_process->notification_ui_manager();
64   ChromeNotifierService* chrome_notifier_service =
65       new ChromeNotifierService(static_cast<Profile*>(profile),
66                                 notification_manager);
67   return chrome_notifier_service;
68 }
69
70 }  // namespace notifier