Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/services/gcm/gcm_client_factory.cc

Issue 135903005: [GCM] Reland: Introduce GCMClientFactory to create GCMClient for GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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_client_factory.h"
6
7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "google_apis/gcm/gcm_client_impl.h"
12
13 namespace gcm {
14
15 namespace {
16
17 static base::LazyInstance<GCMClientImpl>::Leaky g_gcm_client =
18 LAZY_INSTANCE_INITIALIZER;
19 static bool g_gcm_client_initialized = false;
20 static GCMClientFactory::TestingFactoryFunction g_gcm_client_factory = NULL;
21 static GCMClient* g_gcm_client_override = NULL;
22
23 } // namespace
24
25
26 // static
27 GCMClient* GCMClientFactory::GetClient() {
28 if (g_gcm_client_override)
29 return g_gcm_client_override;
30 if (g_gcm_client_factory) {
31 g_gcm_client_override = g_gcm_client_factory();
32 return g_gcm_client_override;
33 }
34
35 GCMClientImpl* client = g_gcm_client.Pointer();
Nicolas Zea 2014/01/16 23:47:36 The GCM client expects to live on the IO thread. D
jianli 2014/01/17 00:43:54 GCMClientFactory::GetClient is expected to be call
36 if (!g_gcm_client_initialized) {
37 // TODO(jianli): get gcm store path.
38 base::FilePath gcm_store_path;
39 scoped_refptr<base::SequencedWorkerPool> worker_pool(
40 content::BrowserThread::GetBlockingPool());
41 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
42 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
43 worker_pool->GetSequenceToken(),
44 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
45 client->Initialize(gcm_store_path, blocking_task_runner);
46 g_gcm_client_initialized = true;
47 }
48 return client;
49 }
50
51 // static
52 void GCMClientFactory::SetTestingFactory(TestingFactoryFunction factory) {
53 if (g_gcm_client_override) {
54 delete g_gcm_client_override;
55 g_gcm_client_override = NULL;
56 }
57 g_gcm_client_factory = factory;
58 }
59
60 GCMClientFactory::GCMClientFactory() {
61 }
62
63 GCMClientFactory::~GCMClientFactory() {
64 }
65
66 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698