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

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: Fix iOS compile 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 (char ch : in) {
24 if (base::IsAsciiAlpha(ch) || base::IsAsciiDigit(ch))
25 out.push_back(base::ToLowerASCII(ch));
26 }
27 return out;
28 }
29
30 } // namespace
31
32 std::string GetProductCategoryForSubtypes(PrefService* prefs) {
33 std::string product_category_for_subtypes =
34 prefs->GetString(prefs::kGCMProductCategoryForSubtypes);
35 if (!product_category_for_subtypes.empty())
36 return product_category_for_subtypes;
37
38 std::string product = ToLowerAlphaNum(PRODUCT_SHORTNAME_STRING);
39 std::string ns = product == "chromium" ? "org" : "com";
40 std::string channel =
41 ToLowerAlphaNum(version_info::GetChannelString(chrome::GetChannel()));
42 std::string platform = ToLowerAlphaNum(version_info::GetOSType());
43 product_category_for_subtypes =
44 ns + '.' + product + '.' + channel + '.' + platform;
45
46 prefs->SetString(prefs::kGCMProductCategoryForSubtypes,
47 product_category_for_subtypes);
48 return product_category_for_subtypes;
49 }
50
51 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
52 registry->RegisterStringPref(prefs::kGCMProductCategoryForSubtypes,
53 std::string() /* default_value */);
54 }
55
56 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698