| 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" |
| 11 #include "components/gcm_driver/instance_id/instance_id.h" | 11 #include "components/gcm_driver/instance_id/instance_id.h" |
| 12 #include "components/gcm_driver/instance_id/instance_id_factory.h" |
| 12 | 13 |
| 13 namespace instance_id { | 14 namespace instance_id { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 const char kInstanceIDFieldTrialName[] = "InstanceID"; | 17 const char kInstanceIDFieldTrialName[] = "InstanceID"; |
| 17 const char kInstanceIDFieldTrialDisabledGroupPrefix[] = "Disabled"; | 18 const char kInstanceIDFieldTrialDisabledGroupPrefix[] = "Disabled"; |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 bool InstanceIDDriver::IsInstanceIDEnabled() { | 22 bool InstanceIDDriver::IsInstanceIDEnabled() { |
| 22 std::string group_name = | 23 std::string group_name = |
| 23 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName); | 24 base::FieldTrialList::FindFullName(kInstanceIDFieldTrialName); |
| 24 return !base::StartsWith(group_name, kInstanceIDFieldTrialDisabledGroupPrefix, | 25 return !base::StartsWith(group_name, kInstanceIDFieldTrialDisabledGroupPrefix, |
| 25 base::CompareCase::INSENSITIVE_ASCII); | 26 base::CompareCase::INSENSITIVE_ASCII); |
| 26 } | 27 } |
| 27 | 28 |
| 28 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver) | 29 InstanceIDDriver::InstanceIDDriver(gcm::GCMDriver* gcm_driver, |
| 29 : gcm_driver_(gcm_driver) { | 30 InstanceIDFactory* factory) |
| 31 : gcm_driver_(gcm_driver), factory_(factory) { |
| 32 DCHECK(factory_); |
| 30 } | 33 } |
| 31 | 34 |
| 32 InstanceIDDriver::~InstanceIDDriver() { | 35 InstanceIDDriver::~InstanceIDDriver() { |
| 33 } | 36 } |
| 34 | 37 |
| 35 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { | 38 InstanceID* InstanceIDDriver::GetInstanceID(const std::string& app_id) { |
| 36 auto iter = instance_id_map_.find(app_id); | 39 auto iter = instance_id_map_.find(app_id); |
| 37 if (iter != instance_id_map_.end()) | 40 if (iter != instance_id_map_.end()) |
| 38 return iter->second.get(); | 41 return iter->second.get(); |
| 39 | 42 |
| 40 std::unique_ptr<InstanceID> instance_id = | 43 std::unique_ptr<InstanceID> instance_id = |
| 41 InstanceID::CreateInternal(app_id, gcm_driver_); | 44 factory_->Create(app_id, gcm_driver_); |
| 42 InstanceID* instance_id_ptr = instance_id.get(); | 45 InstanceID* instance_id_ptr = instance_id.get(); |
| 43 instance_id_map_.insert(std::make_pair(app_id, std::move(instance_id))); | 46 instance_id_map_.insert(std::make_pair(app_id, std::move(instance_id))); |
| 44 return instance_id_ptr; | 47 return instance_id_ptr; |
| 45 } | 48 } |
| 46 | 49 |
| 47 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { | 50 void InstanceIDDriver::RemoveInstanceID(const std::string& app_id) { |
| 48 instance_id_map_.erase(app_id); | 51 instance_id_map_.erase(app_id); |
| 49 } | 52 } |
| 50 | 53 |
| 51 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { | 54 bool InstanceIDDriver::ExistsInstanceID(const std::string& app_id) const { |
| 52 return instance_id_map_.find(app_id) != instance_id_map_.end(); | 55 return instance_id_map_.find(app_id) != instance_id_map_.end(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 } // namespace instance_id | 58 } // namespace instance_id |
| OLD | NEW |