| 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 "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "components/gcm_driver/gcm_driver.h" | 10 #include "components/gcm_driver/gcm_driver.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) | 28 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) |
| 29 : gcm_driver_(gcm_driver) { | 29 : gcm_driver_(gcm_driver) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 InstanceIDDriver::~InstanceIDDriver() { | 32 InstanceIDDriver::~InstanceIDDriver() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { | 35 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { |
| 36 return GetInstanceID(app_id, true /* use_subtype */); |
| 37 } |
| 38 |
| 39 InstanceID* InstanceIDDriver::GetInstanceIDForExtensions( |
| 40 const std::string& app_id) { |
| 41 return GetInstanceID(app_id, false /* use_subtype */); |
| 42 } |
| 43 |
| 44 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id, |
| 45 bool use_subtype) { |
| 36 auto iter = instance_id_map_.find(app_id); | 46 auto iter = instance_id_map_.find(app_id); |
| 37 if (iter != instance_id_map_.end()) | 47 if (iter != instance_id_map_.end()) |
| 38 return iter->second.get(); | 48 return iter->second.get(); |
| 39 | 49 |
| 40 std::unique_ptr<InstanceID> instance_id = | 50 std::unique_ptr<InstanceID> instance_id = |
| 41 InstanceID::Create(app_id, gcm_driver_); | 51 InstanceID::CreateInternal(app_id, use_subtype, gcm_driver_); |
| 42 InstanceID* instance_id_ptr = instance_id.get(); | 52 InstanceID* instance_id_ptr = instance_id.get(); |
| 43 instance_id_map_.insert(std::make_pair(app_id, std::move(instance_id))); | 53 instance_id_map_.insert(std::make_pair(app_id, std::move(instance_id))); |
| 44 return instance_id_ptr; | 54 return instance_id_ptr; |
| 45 } | 55 } |
| 46 | 56 |
| 47 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { | 57 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { |
| 48 instance_id_map_.erase(app_id); | 58 instance_id_map_.erase(app_id); |
| 49 } | 59 } |
| 50 | 60 |
| 51 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { | 61 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { |
| 52 return instance_id_map_.find(app_id) != instance_id_map_.end(); | 62 return instance_id_map_.find(app_id) != instance_id_map_.end(); |
| 53 } | 63 } |
| 54 | 64 |
| 55 } // namespace instance_id | 65 } // namespace instance_id |
| OLD | NEW |