Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: components/update_client/persisted_data.cc

Issue 1899043002: Implement ping_freshness for update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/update_client/persisted_data.h" 5 #include "components/update_client/persisted_data.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/guid.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/stringprintf.h"
11 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
12 #include "base/values.h" 14 #include "base/values.h"
13 #include "components/prefs/pref_registry_simple.h" 15 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/pref_service.h" 16 #include "components/prefs/pref_service.h"
15 #include "components/prefs/scoped_user_pref_update.h" 17 #include "components/prefs/scoped_user_pref_update.h"
16 18
17 const char kPersistedDataPreference[] = "updateclientdata"; 19 const char kPersistedDataPreference[] = "updateclientdata";
18 const int kDateLastRollCallUnknown = -2; 20 const int kDateLastRollCallUnknown = -2;
19 21
20 namespace update_client { 22 namespace update_client {
21 23
22 PersistedData::PersistedData(PrefService* pref_service) 24 PersistedData::PersistedData(PrefService* pref_service)
23 : pref_service_(pref_service) {} 25 : pref_service_(pref_service) {}
24 26
25 PersistedData::~PersistedData() { 27 PersistedData::~PersistedData() {
26 DCHECK(thread_checker_.CalledOnValidThread()); 28 DCHECK(thread_checker_.CalledOnValidThread());
27 } 29 }
28 30
29 int PersistedData::GetDateLastRollCall(const std::string& id) const { 31 int PersistedData::GetDateLastRollCall(const std::string& id) const {
30 DCHECK(thread_checker_.CalledOnValidThread()); 32 DCHECK(thread_checker_.CalledOnValidThread());
31 if (!pref_service_) 33 if (!pref_service_)
32 return kDateLastRollCallUnknown; 34 return kDateLastRollCallUnknown;
33 int dlrc = kDateLastRollCallUnknown; 35 int dlrc = kDateLastRollCallUnknown;
34 const base::DictionaryValue* dict = 36 const base::DictionaryValue* dict =
35 pref_service_->GetDictionary(kPersistedDataPreference); 37 pref_service_->GetDictionary(kPersistedDataPreference);
36 // We assume ids do not contain '.' characters. 38 // We assume ids do not contain '.' characters.
37 DCHECK_EQ(std::string::npos, id.find('.')); 39 DCHECK_EQ(std::string::npos, id.find('.'));
38 if (!dict->GetInteger("apps." + id + ".dlrc", &dlrc)) 40 if (!dict->GetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), &dlrc))
39 return kDateLastRollCallUnknown; 41 return kDateLastRollCallUnknown;
40 return dlrc; 42 return dlrc;
41 } 43 }
42 44
45 std::string PersistedData::GetPingFreshness(const std::string& id) const {
46 DCHECK(thread_checker_.CalledOnValidThread());
47 if (!pref_service_)
48 return std::string();
49 std::string freshness;
50 const base::DictionaryValue* dict =
51 pref_service_->GetDictionary(kPersistedDataPreference);
52 // We assume ids do not contain '.' characters.
53 DCHECK_EQ(std::string::npos, id.find('.'));
54 if (!dict->GetString(base::StringPrintf("apps.%s.pf", id.c_str()),
55 &freshness))
56 return std::string();
57 return base::StringPrintf("{%s}", freshness.c_str());
58 }
59
43 void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids, 60 void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
44 int datenum) const { 61 int datenum) {
45 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
46 if (!pref_service_ || datenum < 0) 63 if (!pref_service_ || datenum < 0)
47 return; 64 return;
48 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); 65 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
49 for (auto id : ids) { 66 for (auto id : ids) {
50 // We assume ids do not contain '.' characters. 67 // We assume ids do not contain '.' characters.
51 DCHECK_EQ(std::string::npos, id.find('.')); 68 DCHECK_EQ(std::string::npos, id.find('.'));
52 update->SetInteger("apps." + id + ".dlrc", datenum); 69 update->SetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), datenum);
70 update->SetString(base::StringPrintf("apps.%s.pf", id.c_str()),
71 base::GenerateGUID());
53 } 72 }
54 } 73 }
55 74
56 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) { 75 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
57 registry->RegisterDictionaryPref(kPersistedDataPreference); 76 registry->RegisterDictionaryPref(kPersistedDataPreference);
58 } 77 }
59 78
60 } // namespace update_client 79 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/persisted_data.h ('k') | components/update_client/persisted_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698