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

Unified 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 to land 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/gcm_client_factory.cc
diff --git a/chrome/browser/services/gcm/gcm_client_factory.cc b/chrome/browser/services/gcm/gcm_client_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e0d94d119e281e6e569b0db5a187c674e82cafd8
--- /dev/null
+++ b/chrome/browser/services/gcm/gcm_client_factory.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/services/gcm/gcm_client_factory.h"
+
+#include "base/files/file_path.h"
+#include "base/lazy_instance.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "content/public/browser/browser_thread.h"
+#include "google_apis/gcm/gcm_client_impl.h"
+
+namespace gcm {
+
+namespace {
+
+static base::LazyInstance<GCMClientImpl>::Leaky g_gcm_client =
+ LAZY_INSTANCE_INITIALIZER;
+static bool g_gcm_client_initialized = false;
+static GCMClientFactory::TestingFactoryFunction g_gcm_client_factory = NULL;
+static GCMClient* g_gcm_client_override = NULL;
+
+} // namespace
+
+
+// static
+GCMClient* GCMClientFactory::GetClient() {
+ if (g_gcm_client_override)
+ return g_gcm_client_override;
+ if (g_gcm_client_factory) {
+ g_gcm_client_override = g_gcm_client_factory();
+ return g_gcm_client_override;
+ }
+
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+
+ GCMClientImpl* client = g_gcm_client.Pointer();
+ if (!g_gcm_client_initialized) {
+ // TODO(jianli): get gcm store path.
+ base::FilePath gcm_store_path;
+ scoped_refptr<base::SequencedWorkerPool> worker_pool(
+ content::BrowserThread::GetBlockingPool());
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
+ worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ worker_pool->GetSequenceToken(),
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
+ client->Initialize(gcm_store_path, blocking_task_runner);
+ g_gcm_client_initialized = true;
+ }
+ return client;
+}
+
+// static
+void GCMClientFactory::SetTestingFactory(TestingFactoryFunction factory) {
+ if (g_gcm_client_override) {
+ delete g_gcm_client_override;
+ g_gcm_client_override = NULL;
+ }
+ g_gcm_client_factory = factory;
+}
+
+GCMClientFactory::GCMClientFactory() {
+}
+
+GCMClientFactory::~GCMClientFactory() {
+}
+
+} // namespace gcm
« no previous file with comments | « chrome/browser/services/gcm/gcm_client_factory.h ('k') | chrome/browser/services/gcm/gcm_profile_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698