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

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

Issue 1889263002: Implement ping_freshness for update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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"
11 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "components/prefs/pref_registry_simple.h" 14 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
15 #include "components/prefs/scoped_user_pref_update.h" 16 #include "components/prefs/scoped_user_pref_update.h"
16 17
17 const char kPersistedDataPreference[] = "updateclientdata"; 18 const char kPersistedDataPreference[] = "updateclientdata";
18 const int kDateLastRollCallUnknown = -2; 19 const int kDateLastRollCallUnknown = -2;
20 const std::string kPingFreshnessUnknown = "";
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("apps." + id + ".dlrc", &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 kPingFreshnessUnknown;
49 std::string freshness = kPingFreshnessUnknown;
Sorin Jianu 2016/04/15 20:26:53 Is there a need to define kPingFreshnessUnknown at
waffles 2016/04/15 21:54:20 Done.
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("apps." + id + ".pf", &freshness))
55 return kPingFreshnessUnknown;
56 return "{" + freshness + "}";
Sorin Jianu 2016/04/15 20:26:53 if we need to format I suggest stringprintf, since
waffles 2016/04/15 21:54:20 Done.
57 }
58
43 void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids, 59 void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
44 int datenum) const { 60 int datenum) const {
45 DCHECK(thread_checker_.CalledOnValidThread()); 61 DCHECK(thread_checker_.CalledOnValidThread());
46 if (!pref_service_ || datenum < 0) 62 if (!pref_service_ || datenum < 0)
47 return; 63 return;
48 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); 64 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
49 for (auto id : ids) { 65 for (auto id : ids) {
50 // We assume ids do not contain '.' characters. 66 // We assume ids do not contain '.' characters.
51 DCHECK_EQ(std::string::npos, id.find('.')); 67 DCHECK_EQ(std::string::npos, id.find('.'));
52 update->SetInteger("apps." + id + ".dlrc", datenum); 68 update->SetInteger("apps." + id + ".dlrc", datenum);
69 update->SetString("apps." + id + ".pf", base::GenerateGUID());
53 } 70 }
54 } 71 }
55 72
56 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) { 73 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
57 registry->RegisterDictionaryPref(kPersistedDataPreference); 74 registry->RegisterDictionaryPref(kPersistedDataPreference);
58 } 75 }
59 76
60 } // namespace update_client 77 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698