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

Side by Side Diff: components/gcm_driver/gcm_client_impl.cc

Issue 530253002: Add GCMChannelStatusRequest to talk with server for all users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gn build Created 6 years, 3 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_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/time/default_clock.h" 16 #include "base/time/default_clock.h"
17 #include "components/gcm_driver/gcm_backoff_policy.h"
17 #include "google_apis/gcm/base/encryptor.h" 18 #include "google_apis/gcm/base/encryptor.h"
18 #include "google_apis/gcm/base/mcs_message.h" 19 #include "google_apis/gcm/base/mcs_message.h"
19 #include "google_apis/gcm/base/mcs_util.h" 20 #include "google_apis/gcm/base/mcs_util.h"
20 #include "google_apis/gcm/engine/checkin_request.h" 21 #include "google_apis/gcm/engine/checkin_request.h"
21 #include "google_apis/gcm/engine/connection_factory_impl.h" 22 #include "google_apis/gcm/engine/connection_factory_impl.h"
22 #include "google_apis/gcm/engine/gcm_store_impl.h" 23 #include "google_apis/gcm/engine/gcm_store_impl.h"
23 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" 24 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
24 #include "google_apis/gcm/protocol/checkin.pb.h" 25 #include "google_apis/gcm/protocol/checkin.pb.h"
25 #include "google_apis/gcm/protocol/mcs.pb.h" 26 #include "google_apis/gcm/protocol/mcs.pb.h"
26 #include "net/http/http_network_session.h" 27 #include "net/http/http_network_session.h"
27 #include "net/http/http_transaction_factory.h" 28 #include "net/http/http_transaction_factory.h"
28 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
29 #include "url/gurl.h" 30 #include "url/gurl.h"
30 31
31 namespace gcm { 32 namespace gcm {
32 33
33 namespace { 34 namespace {
34 35
35 // Backoff policy. Shared across reconnection logic and checkin/(un)registration
36 // retries.
37 // Note: In order to ensure a minimum of 20 seconds between server errors (for
38 // server reasons), we have a 30s +- 10s (33%) jitter initial backoff.
39 // TODO(zea): consider sharing/synchronizing the scheduling of backoff retries
40 // themselves.
41 const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
42 // Number of initial errors (in sequence) to ignore before applying
43 // exponential back-off rules.
44 0,
45
46 // Initial delay for exponential back-off in ms.
47 30 * 1000, // 30 seconds.
48
49 // Factor by which the waiting time will be multiplied.
50 2,
51
52 // Fuzzing percentage. ex: 10% will spread requests randomly
53 // between 90%-100% of the calculated time.
54 0.33, // 33%.
55
56 // Maximum amount of time we are willing to delay our request in ms.
57 10 * 60 * 1000, // 10 minutes.
58
59 // Time to keep an entry from being discarded even when it
60 // has no significant state, -1 to never discard.
61 -1,
62
63 // Don't use initial delay unless the last request was an error.
64 false,
65 };
66
67 // Indicates a message type of the received message. 36 // Indicates a message type of the received message.
68 enum MessageType { 37 enum MessageType {
69 UNKNOWN, // Undetermined type. 38 UNKNOWN, // Undetermined type.
70 DATA_MESSAGE, // Regular data message. 39 DATA_MESSAGE, // Regular data message.
71 DELETED_MESSAGES, // Messages were deleted on the server. 40 DELETED_MESSAGES, // Messages were deleted on the server.
72 SEND_ERROR, // Error sending a message. 41 SEND_ERROR, // Error sending a message.
73 }; 42 };
74 43
75 enum OutgoingMessageTTLCategory { 44 enum OutgoingMessageTTLCategory {
76 TTL_ZERO, 45 TTL_ZERO,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 StartCheckin(); 334 StartCheckin();
366 } 335 }
367 336
368 void GCMClientImpl::InitializeMCSClient( 337 void GCMClientImpl::InitializeMCSClient(
369 scoped_ptr<GCMStore::LoadResult> result) { 338 scoped_ptr<GCMStore::LoadResult> result) {
370 std::vector<GURL> endpoints; 339 std::vector<GURL> endpoints;
371 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint()); 340 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint());
372 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint()); 341 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint());
373 connection_factory_ = internals_builder_->BuildConnectionFactory( 342 connection_factory_ = internals_builder_->BuildConnectionFactory(
374 endpoints, 343 endpoints,
375 kDefaultBackoffPolicy, 344 GetGCMBackoffPolicy(),
376 network_session_, 345 network_session_,
377 url_request_context_getter_->GetURLRequestContext() 346 url_request_context_getter_->GetURLRequestContext()
378 ->http_transaction_factory() 347 ->http_transaction_factory()
379 ->GetSession(), 348 ->GetSession(),
380 net_log_.net_log(), 349 net_log_.net_log(),
381 &recorder_); 350 &recorder_);
382 connection_factory_->SetConnectionListener(this); 351 connection_factory_->SetConnectionListener(this);
383 mcs_client_ = internals_builder_->BuildMCSClient( 352 mcs_client_ = internals_builder_->BuildMCSClient(
384 chrome_build_info_.version, 353 chrome_build_info_.version,
385 clock_.get(), 354 clock_.get(),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 checkin_proto::ChromeBuildProto chrome_build_proto; 460 checkin_proto::ChromeBuildProto chrome_build_proto;
492 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); 461 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto);
493 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, 462 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id,
494 device_checkin_info_.secret, 463 device_checkin_info_.secret,
495 device_checkin_info_.account_tokens, 464 device_checkin_info_.account_tokens,
496 gservices_settings_.digest(), 465 gservices_settings_.digest(),
497 chrome_build_proto); 466 chrome_build_proto);
498 checkin_request_.reset( 467 checkin_request_.reset(
499 new CheckinRequest(gservices_settings_.GetCheckinURL(), 468 new CheckinRequest(gservices_settings_.GetCheckinURL(),
500 request_info, 469 request_info,
501 kDefaultBackoffPolicy, 470 GetGCMBackoffPolicy(),
502 base::Bind(&GCMClientImpl::OnCheckinCompleted, 471 base::Bind(&GCMClientImpl::OnCheckinCompleted,
503 weak_ptr_factory_.GetWeakPtr()), 472 weak_ptr_factory_.GetWeakPtr()),
504 url_request_context_getter_.get(), 473 url_request_context_getter_.get(),
505 &recorder_)); 474 &recorder_));
506 // Taking a snapshot of the accounts count here, as there might be an asynch 475 // Taking a snapshot of the accounts count here, as there might be an asynch
507 // update of the account tokens while checkin is in progress. 476 // update of the account tokens while checkin is in progress.
508 device_checkin_info_.SnapshotCheckinAccounts(); 477 device_checkin_info_.SnapshotCheckinAccounts();
509 checkin_request_->Start(); 478 checkin_request_->Start();
510 } 479 }
511 480
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 RegistrationRequest::RequestInfo request_info( 607 RegistrationRequest::RequestInfo request_info(
639 device_checkin_info_.android_id, 608 device_checkin_info_.android_id,
640 device_checkin_info_.secret, 609 device_checkin_info_.secret,
641 app_id, 610 app_id,
642 sender_ids); 611 sender_ids);
643 DCHECK_EQ(0u, pending_registration_requests_.count(app_id)); 612 DCHECK_EQ(0u, pending_registration_requests_.count(app_id));
644 613
645 RegistrationRequest* registration_request = 614 RegistrationRequest* registration_request =
646 new RegistrationRequest(gservices_settings_.GetRegistrationURL(), 615 new RegistrationRequest(gservices_settings_.GetRegistrationURL(),
647 request_info, 616 request_info,
648 kDefaultBackoffPolicy, 617 GetGCMBackoffPolicy(),
649 base::Bind(&GCMClientImpl::OnRegisterCompleted, 618 base::Bind(&GCMClientImpl::OnRegisterCompleted,
650 weak_ptr_factory_.GetWeakPtr(), 619 weak_ptr_factory_.GetWeakPtr(),
651 app_id, 620 app_id,
652 sender_ids), 621 sender_ids),
653 kMaxRegistrationRetries, 622 kMaxRegistrationRetries,
654 url_request_context_getter_, 623 url_request_context_getter_,
655 &recorder_); 624 &recorder_);
656 pending_registration_requests_[app_id] = registration_request; 625 pending_registration_requests_[app_id] = registration_request;
657 registration_request->Start(); 626 registration_request->Start();
658 } 627 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 weak_ptr_factory_.GetWeakPtr())); 682 weak_ptr_factory_.GetWeakPtr()));
714 683
715 UnregistrationRequest::RequestInfo request_info( 684 UnregistrationRequest::RequestInfo request_info(
716 device_checkin_info_.android_id, 685 device_checkin_info_.android_id,
717 device_checkin_info_.secret, 686 device_checkin_info_.secret,
718 app_id); 687 app_id);
719 688
720 UnregistrationRequest* unregistration_request = new UnregistrationRequest( 689 UnregistrationRequest* unregistration_request = new UnregistrationRequest(
721 gservices_settings_.GetRegistrationURL(), 690 gservices_settings_.GetRegistrationURL(),
722 request_info, 691 request_info,
723 kDefaultBackoffPolicy, 692 GetGCMBackoffPolicy(),
724 base::Bind(&GCMClientImpl::OnUnregisterCompleted, 693 base::Bind(&GCMClientImpl::OnUnregisterCompleted,
725 weak_ptr_factory_.GetWeakPtr(), 694 weak_ptr_factory_.GetWeakPtr(),
726 app_id), 695 app_id),
727 url_request_context_getter_, 696 url_request_context_getter_,
728 &recorder_); 697 &recorder_);
729 pending_unregistration_requests_[app_id] = unregistration_request; 698 pending_unregistration_requests_[app_id] = unregistration_request;
730 unregistration_request->Start(); 699 unregistration_request->Start();
731 } 700 }
732 701
733 void GCMClientImpl::OnUnregisterCompleted( 702 void GCMClientImpl::OnUnregisterCompleted(
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 953
985 recorder_.RecordIncomingSendError( 954 recorder_.RecordIncomingSendError(
986 data_message_stanza.category(), 955 data_message_stanza.category(),
987 data_message_stanza.to(), 956 data_message_stanza.to(),
988 data_message_stanza.id()); 957 data_message_stanza.id());
989 delegate_->OnMessageSendError(data_message_stanza.category(), 958 delegate_->OnMessageSendError(data_message_stanza.category(),
990 send_error_details); 959 send_error_details);
991 } 960 }
992 961
993 } // namespace gcm 962 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_channel_status_request_unittest.cc ('k') | components/gcm_driver/proto/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698