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

Side by Side Diff: chrome/browser/services/gcm/gcm_product_util.cc

Issue 2111973002: Add support for GCM subtypes to desktop Instance ID implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid9push
Patch Set: Address review comments Created 4 years, 4 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
(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_service.h"
14 #include "components/version_info/version_info.h"
15
16 namespace gcm {
17
18 namespace {
19
20 std::string ToLowerAlphaNum(base::StringPiece in) {
21 std::string out;
22 out.reserve(in.size());
23 for (size_t i = 0; i < in.size(); i++) {
Peter Beverloo 2016/07/28 12:34:09 nit: can modernize and reduce indexed array access
johnme 2016/08/04 17:47:13 Done. Serve me right for copy-pasting from base/ :
24 if (base::IsAsciiAlpha(in[i]) || base::IsAsciiDigit(in[i]))
25 out.push_back(base::ToLowerASCII(in[i]));
26 }
27 return out;
28 }
29
30 } // namespace
31
32 // Returns a string like "com.chrome.stable.macosx" that should be used as the
33 // GCM category when an app_id is sent as a subtype instead of as a category.
34 // This is generated once, then remains fixed forever (even if e.g. the product
35 // name or channel change), since it must match existing Instance ID tokens.
36 std::string CategoryForSubtypes(PrefService* prefs) {
37 std::string category_for_subtypes =
38 prefs->GetString(prefs::kGCMCategoryForSubtypes);
39 if (!category_for_subtypes.empty())
40 return category_for_subtypes;
41
42 std::string product = ToLowerAlphaNum(PRODUCT_SHORTNAME_STRING);
43 std::string ns = product == "chromium" ? "org" : "com";
Peter Beverloo 2016/07/28 12:34:09 This still feels wrong to me, but I don't know wha
johnme 2016/08/04 17:47:14 Acknowledged. Since this is now in the chrome/ lay
44 std::string channel =
45 ToLowerAlphaNum(version_info::GetChannelString(chrome::GetChannel()));
46 std::string platform = ToLowerAlphaNum(version_info::GetOSType());
47 category_for_subtypes = ns + '.' + product + '.' + channel + '.' + platform;
48
49 prefs->SetString(prefs::kGCMCategoryForSubtypes, category_for_subtypes);
50 return category_for_subtypes;
51 }
52
53 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
54 registry->RegisterStringPref(prefs::kGCMCategoryForSubtypes,
55 std::string() /* default_value */);
56 }
57
58 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698