OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/gcm_driver/instance_id/instance_id_driver.h" | 5 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
6 | 6 |
| 7 #include "base/metrics/field_trial.h" |
7 #include "components/gcm_driver/instance_id/instance_id.h" | 8 #include "components/gcm_driver/instance_id/instance_id.h" |
8 | 9 |
9 namespace instance_id { | 10 namespace instance_id { |
10 | 11 |
| 12 namespace { |
| 13 #if !defined(OS_ANDROID) |
| 14 const char kInstanceIDFieldTrialName[] = "InstanceID"; |
| 15 const char kInstanceIDFieldTrialEnabledGroupName[] = "Enabled"; |
| 16 #endif // !defined(OS_ANDROID) |
| 17 } // namespace |
| 18 |
| 19 // static |
| 20 bool InstanceIDDriver::IsInstanceIDEnabled() { |
| 21 #if defined(OS_ANDROID) |
| 22 return true; |
| 23 #else |
| 24 std::string group_name = |
| 25 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName); |
| 26 return group_name == kInstanceIDFieldTrialEnabledGroupName; |
| 27 #endif // defined(OS_ANDROID) |
| 28 } |
| 29 |
11 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) | 30 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) |
12 : gcm_driver_(gcm_driver), | 31 : gcm_driver_(gcm_driver), |
13 instance_id_map_deleter_(&instance_id_map_) { | 32 instance_id_map_deleter_(&instance_id_map_) { |
14 } | 33 } |
15 | 34 |
16 InstanceIDDriver::~InstanceIDDriver() { | 35 InstanceIDDriver::~InstanceIDDriver() { |
17 } | 36 } |
18 | 37 |
19 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { | 38 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { |
20 auto iter = instance_id_map_.find(app_id); | 39 auto iter = instance_id_map_.find(app_id); |
21 if (iter != instance_id_map_.end()) | 40 if (iter != instance_id_map_.end()) |
22 return iter->second; | 41 return iter->second; |
23 | 42 |
24 InstanceID* instance_id = InstanceID::Create(app_id, gcm_driver_); | 43 InstanceID* instance_id = InstanceID::Create(app_id, gcm_driver_); |
25 instance_id_map_[app_id] = instance_id; | 44 instance_id_map_[app_id] = instance_id; |
26 return instance_id; | 45 return instance_id; |
27 } | 46 } |
28 | 47 |
29 } // namespace instance_id | 48 } // namespace instance_id |
OLD | NEW |