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

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: Address feedback 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 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
36
37 GCMClientImpl* client = g_gcm_client.Pointer();
38 if (!g_gcm_client_initialized) {
39 // TODO(jianli): get gcm store path.
40 base::FilePath gcm_store_path;
41 scoped_refptr<base::SequencedWorkerPool> worker_pool(
42 content::BrowserThread::GetBlockingPool());
43 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
44 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
45 worker_pool->GetSequenceToken(),
46 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
47 client->Initialize(gcm_store_path, blocking_task_runner);
48 g_gcm_client_initialized = true;
49 }
50 return client;
51 }
52
53 // static
54 void GCMClientFactory::SetTestingFactory(TestingFactoryFunction factory) {
55 if (g_gcm_client_override) {
56 delete g_gcm_client_override;
57 g_gcm_client_override = NULL;
58 }
59 g_gcm_client_factory = factory;
60 }
61
62 GCMClientFactory::GCMClientFactory() {
63 }
64
65 GCMClientFactory::~GCMClientFactory() {
66 }
67
68 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698