Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[GCM] Updating GCM Status Syncer to the new Experiment Status pb
Browse files Browse the repository at this point in the history
BUG=421210

Review URL: https://codereview.chromium.org/635093002

Cr-Commit-Position: refs/heads/master@{#298771}
  • Loading branch information
fgorski authored and Commit bot committed Oct 9, 2014
1 parent e06223d commit 3689f8d
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion components/gcm_driver.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'../base/base.gyp:base',
'../google_apis/gcm/gcm.gyp:gcm',
'../net/net.gyp:net',
'../sync/sync.gyp:sync_proto',
],
'include_dirs': [
'..',
Expand Down Expand Up @@ -53,7 +54,6 @@
'gcm_driver/gcm_driver_desktop.h',
'gcm_driver/gcm_stats_recorder_impl.cc',
'gcm_driver/gcm_stats_recorder_impl.h',
'gcm_driver/proto/gcm_channel_status.proto',
'gcm_driver/system_encryptor.cc',
'gcm_driver/system_encryptor.h',
],
Expand Down
2 changes: 1 addition & 1 deletion components/gcm_driver/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ static_library("gcm_driver") {

deps = [
"//base",
"//components/gcm_driver/proto",
"//components/os_crypt",
"//google_apis/gcm",
"//net",
"//sync/protocol",
]

if (is_android) {
Expand Down
1 change: 1 addition & 0 deletions components/gcm_driver/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include_rules = [
"+google_apis/gcm",
"+jni",
"+net",
"+sync/protocol",
]
13 changes: 7 additions & 6 deletions components/gcm_driver/gcm_channel_status_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "components/gcm_driver/gcm_backoff_policy.h"
#include "components/gcm_driver/proto/gcm_channel_status.pb.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
#include "sync/protocol/experiment_status.pb.h"
#include "url/gurl.h"

namespace gcm {
Expand Down Expand Up @@ -55,7 +55,7 @@ void GCMChannelStatusRequest::Start() {

GURL request_url(kGCMChannelStatusRequestURL);

gcm_proto::ExperimentStatusRequest proto_data;
sync_pb::ExperimentStatusRequest proto_data;
proto_data.add_experiment_name(kGCMChannelTag);
std::string upload_data;
DCHECK(proto_data.SerializeToString(&upload_data));
Expand Down Expand Up @@ -96,16 +96,17 @@ bool GCMChannelStatusRequest::ParseResponse(const net::URLFetcher* source) {
return false;
}

gcm_proto::ExperimentStatusResponse response_proto;
sync_pb::ExperimentStatusResponse response_proto;
if (!response_proto.ParseFromString(response_string)) {
LOG(ERROR) << "GCM channel response failed to be parse as proto.";
return false;
}

bool enabled = true;
if (response_proto.has_gcm_channel() &&
response_proto.gcm_channel().has_enabled()) {
enabled = response_proto.gcm_channel().enabled();
if (response_proto.experiment_size() == 1 &&
response_proto.experiment(0).has_gcm_channel() &&
response_proto.experiment(0).gcm_channel().has_enabled()) {
enabled = response_proto.experiment(0).gcm_channel().enabled();
}

int poll_interval_seconds;
Expand Down
13 changes: 9 additions & 4 deletions components/gcm_driver/gcm_channel_status_request_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#include "base/message_loop/message_loop.h"
#include "components/gcm_driver/gcm_channel_status_request.h"
#include "components/gcm_driver/proto/gcm_channel_status.pb.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "sync/protocol/experiment_status.pb.h"
#include "sync/protocol/experiments_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gcm {
Expand Down Expand Up @@ -69,9 +70,13 @@ void GCMChannelStatusRequestTest::SetResponseStatusAndString(

void GCMChannelStatusRequestTest::SetResponseProtoData(
GCMStatus status, int poll_interval_seconds) {
gcm_proto::ExperimentStatusResponse response_proto;
if (status != NOT_SPECIFIED)
response_proto.mutable_gcm_channel()->set_enabled(status == GCM_ENABLED);
sync_pb::ExperimentStatusResponse response_proto;
if (status != NOT_SPECIFIED) {
sync_pb::ExperimentsSpecifics* experiment_specifics =
response_proto.add_experiment();
experiment_specifics->mutable_gcm_channel()->set_enabled(status ==
GCM_ENABLED);
}

// Zero |poll_interval_seconds| means the optional field is not set.
if (poll_interval_seconds)
Expand Down
9 changes: 6 additions & 3 deletions components/gcm_driver/gcm_driver_desktop_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_connection_observer.h"
#include "components/gcm_driver/proto/gcm_channel_status.pb.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
#include "sync/protocol/experiment_status.pb.h"
#include "sync/protocol/experiments_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gcm {
Expand Down Expand Up @@ -1020,8 +1021,10 @@ void GCMChannelStatusSyncerTest::SetUp() {

void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest(
bool enabled, int poll_interval_seconds) {
gcm_proto::ExperimentStatusResponse response_proto;
response_proto.mutable_gcm_channel()->set_enabled(enabled);
sync_pb::ExperimentStatusResponse response_proto;
sync_pb::ExperimentsSpecifics* experiment_specifics =
response_proto.add_experiment();
experiment_specifics->mutable_gcm_channel()->set_enabled(enabled);

if (poll_interval_seconds)
response_proto.set_poll_interval_seconds(poll_interval_seconds);
Expand Down
11 changes: 0 additions & 11 deletions components/gcm_driver/proto/BUILD.gn

This file was deleted.

1 change: 1 addition & 0 deletions sync/protocol/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ proto_library("protocol") {
"dictionary_specifics.proto",
"encryption.proto",
"enhanced_bookmark_specifics.proto",
"experiment_status.proto",
"experiments_specifics.proto",
"extension_setting_specifics.proto",
"extension_specifics.proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package gcm_proto;
package sync_pb;

// Flags for enabling the GCM feature.
message GcmChannelFlags {
optional bool enabled = 1;
}
import "experiments_specifics.proto";

// This request allows an unauthenticated client to check the status of the
// experiments which do not require user authentication. The status of an
Expand All @@ -29,6 +26,11 @@ message ExperimentStatusResponse {
// Minimal time to wait before issuing another request.
optional int32 poll_interval_seconds = 1 [default = 3600];

// This flag is returned if and only if the client asks for gcm_channel.
optional GcmChannelFlags gcm_channel = 2;
// The experiments that the client has asked for, with each experiment
// containing exactly one experiment flag. The client can inspect the
// embedded flag to obtain the experiment status. Note that the number of
// experiments should be less than or equal to the number of experiment_name
// sent in the request since it is possible that there is no experiment
// matching an experiment_name.
repeated ExperimentsSpecifics experiment = 2;
}
1 change: 1 addition & 0 deletions sync/sync.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@
'protocol/dictionary_specifics.proto',
'protocol/encryption.proto',
'protocol/enhanced_bookmark_specifics.proto',
'protocol/experiment_status.proto',
'protocol/experiments_specifics.proto',
'protocol/extension_setting_specifics.proto',
'protocol/extension_specifics.proto',
Expand Down

0 comments on commit 3689f8d

Please sign in to comment.