| 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 "base/metrics/field_trial.h" |
| 8 #include "components/gcm_driver/instance_id/instance_id.h" | 8 #include "components/gcm_driver/instance_id/instance_id.h" |
| 9 | 9 |
| 10 namespace instance_id { | 10 namespace instance_id { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Not implemented yet. | 22 // Not implemented yet. |
| 23 return false; | 23 return false; |
| 24 #else | 24 #else |
| 25 std::string group_name = | 25 std::string group_name = |
| 26 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName); | 26 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName); |
| 27 return group_name == kInstanceIDFieldTrialEnabledGroupName; | 27 return group_name == kInstanceIDFieldTrialEnabledGroupName; |
| 28 #endif // defined(OS_ANDROID) | 28 #endif // defined(OS_ANDROID) |
| 29 } | 29 } |
| 30 | 30 |
| 31 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) | 31 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) |
| 32 : gcm_driver_(gcm_driver), | 32 : gcm_driver_(gcm_driver) { |
| 33 instance_id_map_deleter_(&instance_id_map_) { | |
| 34 } | 33 } |
| 35 | 34 |
| 36 InstanceIDDriver::~InstanceIDDriver() { | 35 InstanceIDDriver::~InstanceIDDriver() { |
| 37 } | 36 } |
| 38 | 37 |
| 39 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { | 38 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { |
| 40 auto iter = instance_id_map_.find(app_id); | 39 auto iter = instance_id_map_.find(app_id); |
| 41 if (iter != instance_id_map_.end()) | 40 if (iter != instance_id_map_.end()) |
| 42 return iter->second; | 41 return iter->second; |
| 43 | 42 |
| 44 InstanceID* instance_id = InstanceID::Create(app_id, gcm_driver_); | 43 scoped_ptr<InstanceID> instance_id = InstanceID::Create(app_id, gcm_driver_); |
| 45 instance_id_map_[app_id] = instance_id; | 44 InstanceID* instance_id_ptr = instance_id.get(); |
| 46 return instance_id; | 45 instance_id_map_.insert(app_id, instance_id.Pass()); |
| 46 return instance_id_ptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { | 49 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { |
| 50 auto iter = instance_id_map_.find(app_id); | 50 instance_id_map_.erase(app_id); |
| 51 if (iter == instance_id_map_.end()) | |
| 52 return; | |
| 53 delete iter->second; | |
| 54 instance_id_map_.erase(iter); | |
| 55 } | 51 } |
| 56 | 52 |
| 57 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { | 53 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { |
| 58 return instance_id_map_.find(app_id) != instance_id_map_.end(); | 54 return instance_id_map_.find(app_id) != instance_id_map_.end(); |
| 59 } | 55 } |
| 60 | 56 |
| 61 } // namespace instance_id | 57 } // namespace instance_id |
| OLD | NEW |