OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/services/gcm/gcm_product_util.h" | |
6 | |
7 #include "base/strings/string_piece.h" | |
8 #include "base/strings/string_util.h" | |
9 #include "chrome/common/channel_info.h" | |
10 #include "chrome/common/chrome_version.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "components/pref_registry/pref_registry_syncable.h" | |
13 #include "components/prefs/pref_registry_simple.h" | |
14 #include "components/prefs/pref_service.h" | |
15 #include "components/version_info/version_info.h" | |
16 | |
17 namespace gcm { | |
18 | |
19 namespace { | |
20 | |
21 std::string ToLowerAlphaNum(base::StringPiece in) { | |
22 std::string out; | |
23 out.reserve(in.size()); | |
24 for (char ch : in) { | |
25 if (base::IsAsciiAlpha(ch) || base::IsAsciiDigit(ch)) | |
26 out.push_back(base::ToLowerASCII(ch)); | |
27 } | |
28 return out; | |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 std::string GetProductCategoryForSubtypes(PrefService* prefs) { | |
34 std::string product_category_for_subtypes = | |
35 prefs->GetString(prefs::kGCMProductCategoryForSubtypes); | |
jianli
2016/08/08 22:11:51
Do we really need to save to prefs store? It seems
johnme
2016/08/10 13:09:55
If the channel changes (e.g. because a user upgrad
| |
36 if (!product_category_for_subtypes.empty()) | |
37 return product_category_for_subtypes; | |
38 | |
39 std::string product = ToLowerAlphaNum(PRODUCT_SHORTNAME_STRING); | |
40 std::string ns = product == "chromium" ? "org" : "com"; | |
41 std::string channel = | |
42 ToLowerAlphaNum(version_info::GetChannelString(chrome::GetChannel())); | |
43 std::string platform = ToLowerAlphaNum(version_info::GetOSType()); | |
44 product_category_for_subtypes = | |
45 ns + '.' + product + '.' + channel + '.' + platform; | |
46 | |
47 prefs->SetString(prefs::kGCMProductCategoryForSubtypes, | |
48 product_category_for_subtypes); | |
49 return product_category_for_subtypes; | |
50 } | |
51 | |
52 void RegisterPrefs(PrefRegistrySimple* registry) { | |
53 registry->RegisterStringPref(prefs::kGCMProductCategoryForSubtypes, | |
54 std::string() /* default_value */); | |
55 } | |
56 | |
57 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | |
58 RegisterPrefs(registry); | |
59 } | |
60 | |
61 } // namespace gcm | |
OLD | NEW |