Retrieve chrome build info in GCMProfileService, instead of GCMDriver
Since GCMDriver is going to be moved into component, it cannot access
chrome build info. So we now let GCMProfileService retrieve and pass
it.
Also change to define build info in GCMClient, instead of relying on
the one defined in proto buffer generated file.
BUG=356716
TEST=existing tests
Patch
Review URL: https://codereview.chromium.org/293053014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272453 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/services/gcm/fake_gcm_client.cc b/chrome/browser/services/gcm/fake_gcm_client.cc
index 914dbee6..679d366 100644
--- a/chrome/browser/services/gcm/fake_gcm_client.cc
+++ b/chrome/browser/services/gcm/fake_gcm_client.cc
@@ -30,7 +30,7 @@
}
void FakeGCMClient::Initialize(
- const checkin_proto::ChromeBuildProto& chrome_build_proto,
+ const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
diff --git a/chrome/browser/services/gcm/fake_gcm_client.h b/chrome/browser/services/gcm/fake_gcm_client.h
index 20e12cd..a059046 100644
--- a/chrome/browser/services/gcm/fake_gcm_client.h
+++ b/chrome/browser/services/gcm/fake_gcm_client.h
@@ -37,7 +37,7 @@
// Overridden from GCMClient:
// Called on IO thread.
virtual void Initialize(
- const checkin_proto::ChromeBuildProto& chrome_build_proto,
+ const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
diff --git a/chrome/browser/services/gcm/gcm_driver.cc b/chrome/browser/services/gcm/gcm_driver.cc
index 96c21f4..50ca9dc 100644
--- a/chrome/browser/services/gcm/gcm_driver.cc
+++ b/chrome/browser/services/gcm/gcm_driver.cc
@@ -18,56 +18,10 @@
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/system_encryptor.h"
#include "google_apis/gaia/oauth2_token_service.h"
-#include "google_apis/gcm/protocol/android_checkin.pb.h"
#include "net/url_request/url_request_context_getter.h"
namespace gcm {
-namespace {
-
-checkin_proto::ChromeBuildProto_Platform GetPlatform() {
-#if defined(OS_WIN)
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN;
-#elif defined(OS_MACOSX)
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC;
-#elif defined(OS_IOS)
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS;
-#elif defined(OS_CHROMEOS)
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS;
-#elif defined(OS_LINUX)
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
-#else
- // For all other platforms, return as LINUX.
- return checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
-#endif
-}
-
-std::string GetVersion() {
- chrome::VersionInfo version_info;
- return version_info.Version();
-}
-
-checkin_proto::ChromeBuildProto_Channel GetChannel() {
- chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
- switch (channel) {
- case chrome::VersionInfo::CHANNEL_UNKNOWN:
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
- case chrome::VersionInfo::CHANNEL_CANARY:
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY;
- case chrome::VersionInfo::CHANNEL_DEV:
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV;
- case chrome::VersionInfo::CHANNEL_BETA:
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA;
- case chrome::VersionInfo::CHANNEL_STABLE:
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE;
- default:
- NOTREACHED();
- return checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
- }
-}
-
-} // namespace
-
// Helper class to save tasks to run until we're ready to execute them.
class GCMDriver::DelayedTaskController {
public:
@@ -152,6 +106,7 @@
// Called on IO thread.
void Initialize(
scoped_ptr<GCMClientFactory> gcm_client_factory,
+ const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
@@ -196,6 +151,7 @@
void GCMDriver::IOWorker::Initialize(
scoped_ptr<GCMClientFactory> gcm_client_factory,
+ const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
@@ -204,12 +160,7 @@
gcm_client_ = gcm_client_factory->BuildInstance();
- checkin_proto::ChromeBuildProto chrome_build_proto;
- chrome_build_proto.set_platform(GetPlatform());
- chrome_build_proto.set_chrome_version(GetVersion());
- chrome_build_proto.set_channel(GetChannel());
-
- gcm_client_->Initialize(chrome_build_proto,
+ gcm_client_->Initialize(chrome_build_info,
store_path,
account_ids,
blocking_task_runner,
@@ -369,6 +320,7 @@
GCMDriver::GCMDriver(
scoped_ptr<GCMClientFactory> gcm_client_factory,
scoped_ptr<IdentityProvider> identity_provider,
+ const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
@@ -394,6 +346,7 @@
base::Bind(&GCMDriver::IOWorker::Initialize,
base::Unretained(io_worker_.get()),
base::Passed(&gcm_client_factory),
+ chrome_build_info,
store_path,
account_ids,
request_context,
diff --git a/chrome/browser/services/gcm/gcm_driver.h b/chrome/browser/services/gcm/gcm_driver.h
index 3e4f5cd1..b7ae2297 100644
--- a/chrome/browser/services/gcm/gcm_driver.h
+++ b/chrome/browser/services/gcm/gcm_driver.h
@@ -52,6 +52,7 @@
GCMDriver(
scoped_ptr<GCMClientFactory> gcm_client_factory,
scoped_ptr<IdentityProvider> identity_provider,
+ const GCMClient::ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const scoped_refptr<net::URLRequestContextGetter>& request_context,
const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
diff --git a/chrome/browser/services/gcm/gcm_driver_unittest.cc b/chrome/browser/services/gcm/gcm_driver_unittest.cc
index cd74a534..420e8dd6 100644
--- a/chrome/browser/services/gcm/gcm_driver_unittest.cc
+++ b/chrome/browser/services/gcm/gcm_driver_unittest.cc
@@ -197,6 +197,7 @@
base::MessageLoopProxy::current(),
io_thread_.message_loop_proxy())).Pass(),
identity_provider_owner_.PassAs<IdentityProvider>(),
+ GCMClient::ChromeBuildInfo(),
temp_dir_.path(),
request_context,
base::MessageLoopProxy::current(),
diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc
index eeda16cd..9429a513 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -10,6 +10,7 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/services/gcm/gcm_driver.h"
+#include "chrome/browser/services/gcm/gcm_utils.h"
#include "chrome/browser/signin/profile_identity_provider.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
@@ -101,6 +102,7 @@
SigninManagerFactory::GetForProfile(profile_),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
login_ui_service)),
+ GetChromeBuildInfo(),
profile_->GetPath().Append(chrome::kGCMStoreDirname),
profile_->GetRequestContext(),
content::BrowserThread::GetMessageLoopProxyForThread(
diff --git a/chrome/browser/services/gcm/gcm_utils.cc b/chrome/browser/services/gcm/gcm_utils.cc
new file mode 100644
index 0000000..803e210
--- /dev/null
+++ b/chrome/browser/services/gcm/gcm_utils.cc
@@ -0,0 +1,67 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/services/gcm/gcm_utils.h"
+
+#include "base/logging.h"
+#include "chrome/common/chrome_version_info.h"
+
+namespace gcm {
+
+namespace {
+
+GCMClient::ChromePlatform GetPlatform() {
+#if defined(OS_WIN)
+ return GCMClient::PLATFORM_WIN;
+#elif defined(OS_MACOSX)
+ return GCMClient::PLATFORM_MAC;
+#elif defined(OS_IOS)
+ return GCMClient::PLATFORM_IOS;
+#elif defined(OS_ANDROID)
+ return GCMClient::PLATFORM_ANDROID;
+#elif defined(OS_CHROMEOS)
+ return GCMClient::PLATFORM_CROS;
+#elif defined(OS_LINUX)
+ return GCMClient::PLATFORM_LINUX;
+#else
+ // For all other platforms, return as LINUX.
+ return GCMClient::PLATFORM_LINUX;
+#endif
+}
+
+GCMClient::ChromeChannel GetChannel() {
+ chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
+ switch (channel) {
+ case chrome::VersionInfo::CHANNEL_UNKNOWN:
+ return GCMClient::CHANNEL_UNKNOWN;
+ case chrome::VersionInfo::CHANNEL_CANARY:
+ return GCMClient::CHANNEL_CANARY;
+ case chrome::VersionInfo::CHANNEL_DEV:
+ return GCMClient::CHANNEL_DEV;
+ case chrome::VersionInfo::CHANNEL_BETA:
+ return GCMClient::CHANNEL_BETA;
+ case chrome::VersionInfo::CHANNEL_STABLE:
+ return GCMClient::CHANNEL_STABLE;
+ default:
+ NOTREACHED();
+ return GCMClient::CHANNEL_UNKNOWN;
+ }
+}
+
+std::string GetVersion() {
+ chrome::VersionInfo version_info;
+ return version_info.Version();
+}
+
+} // namespace
+
+GCMClient::ChromeBuildInfo GetChromeBuildInfo() {
+ GCMClient::ChromeBuildInfo chrome_build_info;
+ chrome_build_info.platform = GetPlatform();
+ chrome_build_info.channel = GetChannel();
+ chrome_build_info.version = GetVersion();
+ return chrome_build_info;
+}
+
+} // namespace gcm
diff --git a/chrome/browser/services/gcm/gcm_utils.h b/chrome/browser/services/gcm/gcm_utils.h
new file mode 100644
index 0000000..942dc8b
--- /dev/null
+++ b/chrome/browser/services/gcm/gcm_utils.h
@@ -0,0 +1,17 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SERVICES_GCM_GCM_UTILS_H_
+#define CHROME_BROWSER_SERVICES_GCM_GCM_UTILS_H_
+
+#include "google_apis/gcm/gcm_client.h"
+
+namespace gcm {
+
+// Returns the chrome build info that is passed to GCM.
+GCMClient::ChromeBuildInfo GetChromeBuildInfo();
+
+} // namespace gcm
+
+#endif // CHROME_BROWSER_SERVICES_GCM_GCM_UTILS_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index e191450..0a7684a 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2004,6 +2004,8 @@
'browser/services/gcm/gcm_profile_service.h',
'browser/services/gcm/gcm_profile_service_factory.cc',
'browser/services/gcm/gcm_profile_service_factory.h',
+ 'browser/services/gcm/gcm_utils.cc',
+ 'browser/services/gcm/gcm_utils.h',
'browser/service_process/service_process_control.cc',
'browser/service_process/service_process_control_mac.mm',
'browser/service_process/service_process_control.h',
diff --git a/google_apis/gcm/gcm_client.cc b/google_apis/gcm/gcm_client.cc
index dd2a316..93a2d07d 100644
--- a/google_apis/gcm/gcm_client.cc
+++ b/google_apis/gcm/gcm_client.cc
@@ -6,6 +6,14 @@
namespace gcm {
+GCMClient::ChromeBuildInfo::ChromeBuildInfo()
+ : platform(PLATFORM_UNKNOWN),
+ channel(CHANNEL_UNKNOWN) {
+}
+
+GCMClient::ChromeBuildInfo::~ChromeBuildInfo() {
+}
+
GCMClient::OutgoingMessage::OutgoingMessage()
: time_to_live(kMaximumTTL) {
}
diff --git a/google_apis/gcm/gcm_client.h b/google_apis/gcm/gcm_client.h
index 178b18f1..02111c8 100644
--- a/google_apis/gcm/gcm_client.h
+++ b/google_apis/gcm/gcm_client.h
@@ -20,10 +20,6 @@
class SequencedTaskRunner;
}
-namespace checkin_proto {
-class ChromeBuildProto;
-}
-
namespace net {
class URLRequestContextGetter;
}
@@ -58,6 +54,33 @@
UNKNOWN_ERROR
};
+ enum ChromePlatform {
+ PLATFORM_WIN,
+ PLATFORM_MAC,
+ PLATFORM_LINUX,
+ PLATFORM_CROS,
+ PLATFORM_IOS,
+ PLATFORM_ANDROID,
+ PLATFORM_UNKNOWN
+ };
+
+ enum ChromeChannel {
+ CHANNEL_STABLE,
+ CHANNEL_BETA,
+ CHANNEL_DEV,
+ CHANNEL_CANARY,
+ CHANNEL_UNKNOWN
+ };
+
+ struct GCM_EXPORT ChromeBuildInfo {
+ ChromeBuildInfo();
+ ~ChromeBuildInfo();
+
+ ChromePlatform platform;
+ ChromeChannel channel;
+ std::string version;
+ };
+
// Message data consisting of key-value pairs.
typedef std::map<std::string, std::string> MessageData;
@@ -173,7 +196,7 @@
// Begins initialization of the GCM Client. This will not trigger a
// connection.
- // |chrome_build_proto|: chrome info, i.e., version, channel and etc.
+ // |chrome_build_info|: chrome info, i.e., version, channel and etc.
// |store_path|: path to the GCM store.
// |account_ids|: account IDs to be related to the device when checking in.
// |blocking_task_runner|: for running blocking file tasks.
@@ -181,7 +204,7 @@
// |delegate|: the delegate whose methods will be called asynchronously in
// response to events and messages.
virtual void Initialize(
- const checkin_proto::ChromeBuildProto& chrome_build_proto,
+ const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc
index 3225454..b5a3ae6 100644
--- a/google_apis/gcm/gcm_client_impl.cc
+++ b/google_apis/gcm/gcm_client_impl.cc
@@ -21,6 +21,7 @@
#include "google_apis/gcm/engine/connection_factory_impl.h"
#include "google_apis/gcm/engine/gcm_store_impl.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
+#include "google_apis/gcm/protocol/checkin.pb.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/http/http_network_session.h"
#include "net/url_request/url_request_context.h"
@@ -115,6 +116,67 @@
return GCMClientImpl::UNKNOWN_ERROR;
}
+void ToCheckinProtoVersion(
+ const GCMClient::ChromeBuildInfo& chrome_build_info,
+ checkin_proto::ChromeBuildProto* android_build_info) {
+ checkin_proto::ChromeBuildProto_Platform platform;
+ switch (chrome_build_info.platform) {
+ case GCMClient::PLATFORM_WIN:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN;
+ break;
+ case GCMClient::PLATFORM_MAC:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC;
+ break;
+ case GCMClient::PLATFORM_LINUX:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
+ break;
+ case GCMClient::PLATFORM_IOS:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS;
+ break;
+ case GCMClient::PLATFORM_ANDROID:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_ANDROID;
+ break;
+ case GCMClient::PLATFORM_CROS:
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS;
+ break;
+ case GCMClient::PLATFORM_UNKNOWN:
+ // For unknown platform, return as LINUX.
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
+ break;
+ default:
+ NOTREACHED();
+ platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
+ break;
+ }
+ android_build_info->set_platform(platform);
+
+ checkin_proto::ChromeBuildProto_Channel channel;
+ switch (chrome_build_info.channel) {
+ case GCMClient::CHANNEL_STABLE:
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE;
+ break;
+ case GCMClient::CHANNEL_BETA:
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA;
+ break;
+ case GCMClient::CHANNEL_DEV:
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV;
+ break;
+ case GCMClient::CHANNEL_CANARY:
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY;
+ break;
+ case GCMClient::CHANNEL_UNKNOWN:
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
+ break;
+ default:
+ NOTREACHED();
+ channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
+ break;
+ }
+ android_build_info->set_channel(channel);
+
+ android_build_info->set_chrome_version(chrome_build_info.version);
+}
+
MessageType DecodeMessageType(const std::string& value) {
if (kMessageTypeDeletedMessagesKey == value)
return DELETED_MESSAGES;
@@ -201,7 +263,7 @@
}
void GCMClientImpl::Initialize(
- const checkin_proto::ChromeBuildProto& chrome_build_proto,
+ const ChromeBuildInfo& chrome_build_info,
const base::FilePath& path,
const std::vector<std::string>& account_ids,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
@@ -220,7 +282,7 @@
DCHECK(network_session_params);
network_session_ = new net::HttpNetworkSession(*network_session_params);
- chrome_build_proto_.CopyFrom(chrome_build_proto);
+ chrome_build_info_ = chrome_build_info;
account_ids_ = account_ids;
gcm_store_.reset(
@@ -280,7 +342,7 @@
net_log_.net_log(),
&recorder_);
mcs_client_ = internals_builder_->BuildMCSClient(
- chrome_build_proto_.chrome_version(),
+ chrome_build_info_.version,
clock_.get(),
connection_factory_.get(),
gcm_store_.get(),
@@ -333,11 +395,13 @@
if (checkin_request_.get())
return;
+ checkin_proto::ChromeBuildProto chrome_build_proto;
+ ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto);
CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id,
device_checkin_info_.secret,
gservices_settings_.digest(),
account_ids_,
- chrome_build_proto_);
+ chrome_build_proto);
checkin_request_.reset(
new CheckinRequest(gservices_settings_.GetCheckinURL(),
request_info,
diff --git a/google_apis/gcm/gcm_client_impl.h b/google_apis/gcm/gcm_client_impl.h
index 5c4c84a..e2f1b02 100644
--- a/google_apis/gcm/gcm_client_impl.h
+++ b/google_apis/gcm/gcm_client_impl.h
@@ -81,7 +81,7 @@
// Overridden from GCMClient:
virtual void Initialize(
- const checkin_proto::ChromeBuildProto& chrome_build_proto,
+ const ChromeBuildInfo& chrome_build_info,
const base::FilePath& store_path,
const std::vector<std::string>& account_ids,
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
@@ -249,7 +249,7 @@
// Information about the chrome build.
// TODO(fgorski): Check if it can be passed in constructor and made const.
- checkin_proto::ChromeBuildProto chrome_build_proto_;
+ ChromeBuildInfo chrome_build_info_;
// Persistent data store for keeping device credentials, messages and user to
// serial number mappings.
diff --git a/google_apis/gcm/gcm_client_impl_unittest.cc b/google_apis/gcm/gcm_client_impl_unittest.cc
index 6280370..8da4887c 100644
--- a/google_apis/gcm/gcm_client_impl_unittest.cc
+++ b/google_apis/gcm/gcm_client_impl_unittest.cc
@@ -444,8 +444,8 @@
clock()->Advance(base::TimeDelta::FromMilliseconds(1));
// Actual initialization.
- checkin_proto::ChromeBuildProto chrome_build_proto;
- gcm_client_->Initialize(chrome_build_proto,
+ GCMClient::ChromeBuildInfo chrome_build_info;
+ gcm_client_->Initialize(chrome_build_info,
temp_directory_.path(),
std::vector<std::string>(),
message_loop_.message_loop_proxy(),