| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gcm/gcm_client.h" | 5 #include "google_apis/gcm/gcm_client.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "google_apis/gcm/gcm_client_impl.h" | |
| 9 | |
| 10 namespace gcm { | 7 namespace gcm { |
| 11 | 8 |
| 12 namespace { | |
| 13 | |
| 14 static base::LazyInstance<GCMClientImpl>::Leaky g_gcm_client = | |
| 15 LAZY_INSTANCE_INITIALIZER; | |
| 16 static GCMClient::TestingFactoryFunction g_gcm_client_factory = NULL; | |
| 17 static GCMClient* g_gcm_client_override = NULL; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 GCMClient::OutgoingMessage::OutgoingMessage() | 9 GCMClient::OutgoingMessage::OutgoingMessage() |
| 22 : time_to_live(0) { | 10 : time_to_live(0) { |
| 23 } | 11 } |
| 24 | 12 |
| 25 GCMClient::OutgoingMessage::~OutgoingMessage() { | 13 GCMClient::OutgoingMessage::~OutgoingMessage() { |
| 26 } | 14 } |
| 27 | 15 |
| 28 GCMClient::IncomingMessage::IncomingMessage() { | 16 GCMClient::IncomingMessage::IncomingMessage() { |
| 29 } | 17 } |
| 30 | 18 |
| 31 GCMClient::IncomingMessage::~IncomingMessage() { | 19 GCMClient::IncomingMessage::~IncomingMessage() { |
| 32 } | 20 } |
| 33 | 21 |
| 34 // static | 22 GCMClient::GCMClient() { |
| 35 GCMClient* GCMClient::Get() { | |
| 36 if (g_gcm_client_override) | |
| 37 return g_gcm_client_override; | |
| 38 if (g_gcm_client_factory) { | |
| 39 g_gcm_client_override = g_gcm_client_factory(); | |
| 40 return g_gcm_client_override; | |
| 41 } | |
| 42 return g_gcm_client.Pointer(); | |
| 43 } | 23 } |
| 44 | 24 |
| 45 // static | 25 GCMClient::~GCMClient() { |
| 46 void GCMClient::SetTestingFactory(TestingFactoryFunction factory) { | |
| 47 if (g_gcm_client_override) { | |
| 48 delete g_gcm_client_override; | |
| 49 g_gcm_client_override = NULL; | |
| 50 } | |
| 51 g_gcm_client_factory = factory; | |
| 52 } | 26 } |
| 53 | 27 |
| 54 } // namespace gcm | 28 } // namespace gcm |
| OLD | NEW |