Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / services / gcm / gcm_desktop_utils.cc
1 // Copyright 2014 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/services/gcm/gcm_desktop_utils.h"
6
7 #include "base/logging.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/common/chrome_version_info.h"
11 #include "components/gcm_driver/gcm_client.h"
12 #include "components/gcm_driver/gcm_client_factory.h"
13 #include "components/gcm_driver/gcm_driver.h"
14 #include "components/gcm_driver/gcm_driver_desktop.h"
15 #include "content/public/browser/browser_thread.h"
16
17 namespace gcm {
18
19 namespace {
20
21 GCMClient::ChromePlatform GetPlatform() {
22 #if defined(OS_WIN)
23   return GCMClient::PLATFORM_WIN;
24 #elif defined(OS_MACOSX)
25   return GCMClient::PLATFORM_MAC;
26 #elif defined(OS_IOS)
27   return GCMClient::PLATFORM_IOS;
28 #elif defined(OS_ANDROID)
29   return GCMClient::PLATFORM_ANDROID;
30 #elif defined(OS_CHROMEOS)
31   return GCMClient::PLATFORM_CROS;
32 #elif defined(OS_LINUX)
33   return GCMClient::PLATFORM_LINUX;
34 #else
35   // For all other platforms, return as LINUX.
36   return GCMClient::PLATFORM_LINUX;
37 #endif
38 }
39
40 GCMClient::ChromeChannel GetChannel() {
41   chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
42   switch (channel) {
43     case chrome::VersionInfo::CHANNEL_UNKNOWN:
44       return GCMClient::CHANNEL_UNKNOWN;
45     case chrome::VersionInfo::CHANNEL_CANARY:
46       return GCMClient::CHANNEL_CANARY;
47     case chrome::VersionInfo::CHANNEL_DEV:
48       return GCMClient::CHANNEL_DEV;
49     case chrome::VersionInfo::CHANNEL_BETA:
50       return GCMClient::CHANNEL_BETA;
51     case chrome::VersionInfo::CHANNEL_STABLE:
52       return GCMClient::CHANNEL_STABLE;
53     default:
54       NOTREACHED();
55       return GCMClient::CHANNEL_UNKNOWN;
56   }
57 }
58
59 std::string GetVersion() {
60   chrome::VersionInfo version_info;
61   return version_info.Version();
62 }
63
64 GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
65   GCMClient::ChromeBuildInfo chrome_build_info;
66   chrome_build_info.platform = GetPlatform();
67   chrome_build_info.channel = GetChannel();
68   chrome_build_info.version = GetVersion();
69   return chrome_build_info;
70 }
71
72 }  // namespace
73
74 scoped_ptr<GCMDriver> CreateGCMDriverDesktop(
75     scoped_ptr<GCMClientFactory> gcm_client_factory,
76     PrefService* prefs,
77     const base::FilePath& store_path,
78     const scoped_refptr<net::URLRequestContextGetter>& request_context) {
79   scoped_refptr<base::SequencedWorkerPool> worker_pool(
80       content::BrowserThread::GetBlockingPool());
81   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
82       worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
83           worker_pool->GetSequenceToken(),
84           base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
85   return scoped_ptr<GCMDriver>(new GCMDriverDesktop(
86       gcm_client_factory.Pass(),
87       GetChromeBuildInfo(),
88       prefs,
89       store_path,
90       request_context,
91       content::BrowserThread::GetMessageLoopProxyForThread(
92           content::BrowserThread::UI),
93       content::BrowserThread::GetMessageLoopProxyForThread(
94           content::BrowserThread::IO),
95       blocking_task_runner));
96 }
97
98 }  // namespace gcm