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

Side by Side Diff: components/gcm_driver/gcm_desktop_utils.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 most of peter's concerns Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gcm_driver/gcm_desktop_utils.h" 5 #include "components/gcm_driver/gcm_desktop_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h"
11 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "components/gcm_driver/gcm_client.h"
13 #include "components/gcm_driver/gcm_client_factory.h" 16 #include "components/gcm_driver/gcm_client_factory.h"
14 #include "components/gcm_driver/gcm_driver.h" 17 #include "components/gcm_driver/gcm_driver.h"
15 #include "components/gcm_driver/gcm_driver_desktop.h" 18 #include "components/gcm_driver/gcm_driver_desktop.h"
19 #include "components/gcm_driver/pref_names.h"
20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/prefs/pref_service.h"
16 #include "components/sync_driver/sync_util.h" 22 #include "components/sync_driver/sync_util.h"
23 #include "components/version_info/version_info.h"
17 #include "url/gurl.h" 24 #include "url/gurl.h"
18 25
19 namespace gcm { 26 namespace gcm {
20 27
21 namespace { 28 namespace {
22 29
23 const char kChannelStatusRelativePath[] = "/experimentstatus"; 30 const char kChannelStatusRelativePath[] = "/experimentstatus";
24 31
25 GCMClient::ChromePlatform GetPlatform() { 32 GCMClient::ChromePlatform GetPlatform() {
26 #if defined(OS_WIN) 33 #if defined(OS_WIN)
(...skipping 29 matching lines...) Expand all
56 default: 63 default:
57 NOTREACHED(); 64 NOTREACHED();
58 return GCMClient::CHANNEL_UNKNOWN; 65 return GCMClient::CHANNEL_UNKNOWN;
59 } 66 }
60 } 67 }
61 68
62 std::string GetVersion() { 69 std::string GetVersion() {
63 return version_info::GetVersionNumber(); 70 return version_info::GetVersionNumber();
64 } 71 }
65 72
66 GCMClient::ChromeBuildInfo GetChromeBuildInfo(version_info::Channel channel) { 73 std::string ToLowerAlphaNum(base::StringPiece in) {
74 std::string out;
75 out.reserve(in.size());
76 for (size_t i = 0; i < in.size(); i++) {
77 if (base::IsAsciiAlpha(in[i]) || base::IsAsciiDigit(in[i]))
78 out.push_back(base::ToLowerASCII(in[i]));
79 }
80 return out;
81 }
82
83 // Returns a string like "com.chrome.stable.macosx" that should be used as the
84 // GCM category when an app_id is sent as a subtype instead of as a category.
85 // This is generated once, then remains fixed forever (even if e.g. the product
86 // name or channel change), since it must match existing Instance ID tokens.
87 std::string CategoryForSubtypes(PrefService* prefs,
88 const std::string& product_shortname,
89 version_info::Channel channel_info) {
90 std::string category_for_subtypes =
91 prefs->GetString(prefs::kCategoryForSubtypes);
92 if (!category_for_subtypes.empty())
93 return category_for_subtypes;
94
95 std::string product = ToLowerAlphaNum(product_shortname);
96 std::string ns = product == "chromium" ? "org" : "com";
Peter Beverloo 2016/07/22 12:17:03 This really feels like the wrong layer to make thi
johnme 2016/07/26 17:11:55 Done.
97 std::string channel =
98 ToLowerAlphaNum(version_info::GetChannelString(channel_info));
99 std::string platform = ToLowerAlphaNum(version_info::GetOSType());
100 category_for_subtypes = ns + '.' + product + '.' + channel + '.' + platform;
101
102 prefs->SetString(prefs::kCategoryForSubtypes, category_for_subtypes);
103 return category_for_subtypes;
104 }
105
106 GCMClient::ChromeBuildInfo GetChromeBuildInfo(
107 PrefService* prefs,
108 const std::string& product_shortname,
109 version_info::Channel channel) {
67 GCMClient::ChromeBuildInfo chrome_build_info; 110 GCMClient::ChromeBuildInfo chrome_build_info;
68 chrome_build_info.platform = GetPlatform(); 111 chrome_build_info.platform = GetPlatform();
69 chrome_build_info.channel = GetChannel(channel); 112 chrome_build_info.channel = GetChannel(channel);
70 chrome_build_info.version = GetVersion(); 113 chrome_build_info.version = GetVersion();
114 chrome_build_info.category_for_subtypes =
115 CategoryForSubtypes(prefs, product_shortname, channel);
71 return chrome_build_info; 116 return chrome_build_info;
72 } 117 }
73 118
74 std::string GetChannelStatusRequestUrl(version_info::Channel channel) { 119 std::string GetChannelStatusRequestUrl(version_info::Channel channel) {
75 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), 120 GURL sync_url(GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
76 channel)); 121 channel));
77 return sync_url.spec() + kChannelStatusRelativePath; 122 return sync_url.spec() + kChannelStatusRelativePath;
78 } 123 }
79 124
80 std::string GetUserAgent(version_info::Channel channel) { 125 std::string GetUserAgent(version_info::Channel channel) {
81 // TODO(pavely): Fix hardcoded is_tablet value in following call to 126 // TODO(pavely): Fix hardcoded is_tablet value in following call to
82 // MakeUserAgentForSync. Current implementation returns iPhone UserAgent for 127 // MakeUserAgentForSync. Current implementation returns iPhone UserAgent for
83 // iPad devices. 128 // iPad devices.
84 return MakeUserAgentForSync(channel, false); 129 return MakeUserAgentForSync(channel, false);
85 } 130 }
86 131
87 } // namespace 132 } // namespace
88 133
134 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
135 registry->RegisterStringPref(prefs::kCategoryForSubtypes,
136 std::string() /* default_value */);
137 }
138
89 std::unique_ptr<GCMDriver> CreateGCMDriverDesktop( 139 std::unique_ptr<GCMDriver> CreateGCMDriverDesktop(
90 std::unique_ptr<GCMClientFactory> gcm_client_factory, 140 std::unique_ptr<GCMClientFactory> gcm_client_factory,
91 PrefService* prefs, 141 PrefService* prefs,
92 const base::FilePath& store_path, 142 const base::FilePath& store_path,
93 const scoped_refptr<net::URLRequestContextGetter>& request_context, 143 const scoped_refptr<net::URLRequestContextGetter>& request_context,
144 const std::string& product_shortname,
94 version_info::Channel channel, 145 version_info::Channel channel,
95 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner, 146 const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
96 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 147 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
97 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { 148 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) {
98 return std::unique_ptr<GCMDriver>(new GCMDriverDesktop( 149 return std::unique_ptr<GCMDriver>(new GCMDriverDesktop(
99 std::move(gcm_client_factory), GetChromeBuildInfo(channel), 150 std::move(gcm_client_factory),
151 GetChromeBuildInfo(prefs, product_shortname, channel),
100 GetChannelStatusRequestUrl(channel), GetUserAgent(channel), prefs, 152 GetChannelStatusRequestUrl(channel), GetUserAgent(channel), prefs,
101 store_path, request_context, ui_task_runner, io_task_runner, 153 store_path, request_context, ui_task_runner, io_task_runner,
102 blocking_task_runner)); 154 blocking_task_runner));
103 } 155 }
104 156
105 } // namespace gcm 157 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698