1 // Copyright (c) 2012 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 // The methods in this file belong conceptually to rlz_lib.cc. However, some 6 // programs depend on rlz only to call ClearAllProductEvents(), so this file 7 // contains this in fairly self-contained form to make it easier for linkers 8 // to strip away most of rlz. In particular, this file should not reference any 9 // symbols defined in financial_ping.cc. 10 11 #include "rlz/lib/rlz_lib.h" 12 13 #include "base/lazy_instance.h" 14 #include "rlz/lib/assert.h" 15 #include "rlz/lib/rlz_value_store.h" 16 17 namespace rlz_lib { 18 ClearAllProductEvents(Product product)19bool ClearAllProductEvents(Product product) { 20 rlz_lib::ScopedRlzValueStoreLock lock; 21 rlz_lib::RlzValueStore* store = lock.GetStore(); 22 if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess)) 23 return false; 24 25 bool result; 26 result = store->ClearAllProductEvents(product); 27 result &= store->ClearAllStatefulEvents(product); 28 return result; 29 } 30 ClearProductState(Product product,const AccessPoint * access_points)31void ClearProductState(Product product, const AccessPoint* access_points) { 32 rlz_lib::ScopedRlzValueStoreLock lock; 33 rlz_lib::RlzValueStore* store = lock.GetStore(); 34 if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess)) 35 return; 36 37 // Delete all product specific state. 38 VERIFY(ClearAllProductEvents(product)); 39 VERIFY(store->ClearPingTime(product)); 40 41 // Delete all RLZ's for access points being uninstalled. 42 if (access_points) { 43 for (int i = 0; access_points[i] != NO_ACCESS_POINT; i++) { 44 VERIFY(store->ClearAccessPointRlz(access_points[i])); 45 } 46 } 47 48 store->CollectGarbage(); 49 } 50 51 static base::LazyInstance<std::string>::Leaky g_supplemental_branding; 52 SupplementaryBranding(const char * brand)53SupplementaryBranding::SupplementaryBranding(const char* brand) 54 : lock_(new ScopedRlzValueStoreLock) { 55 if (!lock_->GetStore()) 56 return; 57 58 if (!g_supplemental_branding.Get().empty()) { 59 ASSERT_STRING("ProductBranding: existing brand is not empty"); 60 return; 61 } 62 63 if (brand == NULL || brand[0] == 0) { 64 ASSERT_STRING("ProductBranding: new brand is empty"); 65 return; 66 } 67 68 g_supplemental_branding.Get() = brand; 69 } 70 ~SupplementaryBranding()71SupplementaryBranding::~SupplementaryBranding() { 72 if (lock_->GetStore()) 73 g_supplemental_branding.Get().clear(); 74 delete lock_; 75 } 76 77 // static GetBrand()78const std::string& SupplementaryBranding::GetBrand() { 79 return g_supplemental_branding.Get(); 80 } 81 82 } // namespace rlz_lib 83