1 // Copyright 2015 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.
5 #include "components/gcm_driver/instance_id/instance_id_driver.h"
7 #include "base/metrics/field_trial.h"
8 #include "components/gcm_driver/instance_id/instance_id.h"
10 namespace instance_id
{
13 #if !defined(OS_ANDROID)
14 const char kInstanceIDFieldTrialName
[] = "InstanceID";
15 const char kInstanceIDFieldTrialEnabledGroupName
[] = "Enabled";
16 #endif // !defined(OS_ANDROID)
20 bool InstanceIDDriver::IsInstanceIDEnabled() {
21 #if defined(OS_ANDROID)
22 // Not implemented yet.
25 std::string group_name
=
26 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName
);
27 return group_name
== kInstanceIDFieldTrialEnabledGroupName
;
28 #endif // defined(OS_ANDROID)
31 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver
* gcm_driver
)
32 : gcm_driver_(gcm_driver
) {
35 InstanceIDDriver::~InstanceIDDriver() {
38 InstanceID
* InstanceIDDriver::GetInstanceID(const std::string
& app_id
) {
39 auto iter
= instance_id_map_
.find(app_id
);
40 if (iter
!= instance_id_map_
.end())
43 scoped_ptr
<InstanceID
> instance_id
= InstanceID::Create(app_id
, gcm_driver_
);
44 InstanceID
* instance_id_ptr
= instance_id
.get();
45 instance_id_map_
.insert(app_id
, instance_id
.Pass());
46 return instance_id_ptr
;
49 void InstanceIDDriver::RemoveInstanceID(const std::string
& app_id
) {
50 instance_id_map_
.erase(app_id
);
53 bool InstanceIDDriver::ExistsInstanceID(const std::string
& app_id
) const {
54 return instance_id_map_
.find(app_id
) != instance_id_map_
.end();
57 } // namespace instance_id