1 // Copyright 2019 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. 4 5 #include "rlz/lib/supplementary_branding.h" 6 7 #include <string> 8 9 #include "base/no_destructor.h" 10 #include "rlz/lib/assert.h" 11 #include "rlz/lib/rlz_value_store.h" 12 13 namespace rlz_lib { 14 15 namespace { 16 GetSupplementaryBrandingStorage()17std::string& GetSupplementaryBrandingStorage() { 18 static base::NoDestructor<std::string> instance; 19 return *instance; 20 } 21 22 } // namespace 23 SupplementaryBranding(const char * brand)24SupplementaryBranding::SupplementaryBranding(const char* brand) 25 : lock_(new ScopedRlzValueStoreLock) { 26 if (!lock_->GetStore()) 27 return; 28 29 auto& supplementary_brand = GetSupplementaryBrandingStorage(); 30 if (!supplementary_brand.empty()) { 31 ASSERT_STRING("ProductBranding: existing brand is not empty"); 32 return; 33 } 34 35 if (brand == nullptr || brand[0] == 0) { 36 ASSERT_STRING("ProductBranding: new brand is empty"); 37 return; 38 } 39 40 supplementary_brand = brand; 41 } 42 ~SupplementaryBranding()43SupplementaryBranding::~SupplementaryBranding() { 44 if (lock_->GetStore()) 45 GetSupplementaryBrandingStorage().clear(); 46 delete lock_; 47 } 48 49 // static GetBrand()50const std::string& SupplementaryBranding::GetBrand() { 51 return GetSupplementaryBrandingStorage(); 52 } 53 54 } // namespace rlz_lib 55