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

Side by Side Diff: google_apis/gcm/engine/mcs_client.cc

Issue 1124783002: [GCM] Wiring heartbeat interval calls to GCMDriver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@store-heartbeat-gcm
Patch Set: Addressing final feedback and fixing formatting Created 5 years, 7 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
« no previous file with comments | « google_apis/gcm/engine/mcs_client.h ('k') | google_apis/gcm/engine/mcs_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "google_apis/gcm/engine/mcs_client.h" 5 #include "google_apis/gcm/engine/mcs_client.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 if (packet_info->tag == kDataMessageStanzaTag) { 270 if (packet_info->tag == kDataMessageStanzaTag) {
271 mcs_proto::DataMessageStanza* data_message = 271 mcs_proto::DataMessageStanza* data_message =
272 reinterpret_cast<mcs_proto::DataMessageStanza*>( 272 reinterpret_cast<mcs_proto::DataMessageStanza*>(
273 packet_info->protobuf.get()); 273 packet_info->protobuf.get());
274 CollapseKey collapse_key(*data_message); 274 CollapseKey collapse_key(*data_message);
275 if (collapse_key.IsValid()) 275 if (collapse_key.IsValid())
276 collapse_key_map_[collapse_key] = packet_info; 276 collapse_key_map_[collapse_key] = packet_info;
277 } 277 }
278 } 278 }
279
280 // Establish if there is any custom client interval persisted from the last
281 // run and set it on the heartbeat manager.
282 custom_heartbeat_intervals_.swap(load_result->heartbeat_intervals);
283 int min_interval_ms = GetMinHeartbeatIntervalMs();
284 heartbeat_manager_.SetClientHeartbeatIntervalMs(min_interval_ms);
279 } 285 }
280 286
281 void MCSClient::Login(uint64 android_id, uint64 security_token) { 287 void MCSClient::Login(uint64 android_id, uint64 security_token) {
282 DCHECK_EQ(state_, LOADED); 288 DCHECK_EQ(state_, LOADED);
283 DCHECK(android_id_ == 0 || android_id_ == android_id); 289 DCHECK(android_id_ == 0 || android_id_ == android_id);
284 DCHECK(security_token_ == 0 || security_token_ == security_token); 290 DCHECK(security_token_ == 0 || security_token_ == security_token);
285 291
286 if (android_id != android_id_ && security_token != security_token_) { 292 if (android_id != android_id_ && security_token != security_token_) {
287 DCHECK(android_id); 293 DCHECK(android_id);
288 DCHECK(security_token); 294 DCHECK(security_token);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 void MCSClient::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { 379 void MCSClient::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) {
374 heartbeat_manager_.UpdateHeartbeatTimer(timer.Pass()); 380 heartbeat_manager_.UpdateHeartbeatTimer(timer.Pass());
375 } 381 }
376 382
377 void MCSClient::AddHeartbeatInterval(const std::string& scope, 383 void MCSClient::AddHeartbeatInterval(const std::string& scope,
378 int interval_ms) { 384 int interval_ms) {
379 if (!heartbeat_manager_.IsValidClientHeartbeatInterval(interval_ms)) 385 if (!heartbeat_manager_.IsValidClientHeartbeatInterval(interval_ms))
380 return; 386 return;
381 387
382 custom_heartbeat_intervals_[scope] = interval_ms; 388 custom_heartbeat_intervals_[scope] = interval_ms;
383 // TODO(fgorski): Save in the gcm store as well. 389 gcm_store_->AddHeartbeatInterval(scope, interval_ms,
390 base::Bind(&MCSClient::OnGCMUpdateFinished,
391 weak_ptr_factory_.GetWeakPtr()));
384 392
385 int min_interval_ms = GetMinCustomHeartbeatInterval(); 393 int min_interval_ms = GetMinHeartbeatIntervalMs();
386 heartbeat_manager_.SetClientHeartbeatIntervalMs(min_interval_ms); 394 heartbeat_manager_.SetClientHeartbeatIntervalMs(min_interval_ms);
387 } 395 }
388 396
389 void MCSClient::RemoveHeartbeatInterval(const std::string& scope) { 397 void MCSClient::RemoveHeartbeatInterval(const std::string& scope) {
390 custom_heartbeat_intervals_.erase(scope); 398 custom_heartbeat_intervals_.erase(scope);
391 int min_interval = GetMinCustomHeartbeatInterval(); 399 gcm_store_->RemoveHeartbeatInterval(
400 scope, base::Bind(&MCSClient::OnGCMUpdateFinished,
401 weak_ptr_factory_.GetWeakPtr()));
402
403 int min_interval = GetMinHeartbeatIntervalMs();
392 heartbeat_manager_.SetClientHeartbeatIntervalMs(min_interval); 404 heartbeat_manager_.SetClientHeartbeatIntervalMs(min_interval);
393 } 405 }
394 406
395 int MCSClient::GetMinCustomHeartbeatInterval() { 407 int MCSClient::GetMinHeartbeatIntervalMs() {
396 if (custom_heartbeat_intervals_.empty()) 408 if (custom_heartbeat_intervals_.empty())
397 return kNoCustomHeartbeat; 409 return kNoCustomHeartbeat;
398 410
399 int min_interval = custom_heartbeat_intervals_.begin()->second; 411 int min_interval = custom_heartbeat_intervals_.begin()->second;
400 for (std::map<std::string, int>::const_iterator it = 412 for (std::map<std::string, int>::const_iterator it =
401 custom_heartbeat_intervals_.begin(); 413 custom_heartbeat_intervals_.begin();
402 it != custom_heartbeat_intervals_.end(); 414 it != custom_heartbeat_intervals_.end();
403 ++it) { 415 ++it) {
404 if (it->second < min_interval) 416 if (it->second < min_interval)
405 min_interval = it->second; 417 min_interval = it->second;
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 reinterpret_cast<mcs_proto::DataMessageStanza*>(packet->protobuf.get()); 962 reinterpret_cast<mcs_proto::DataMessageStanza*>(packet->protobuf.get());
951 CollapseKey collapse_key(*data_message); 963 CollapseKey collapse_key(*data_message);
952 if (collapse_key.IsValid()) 964 if (collapse_key.IsValid())
953 collapse_key_map_.erase(collapse_key); 965 collapse_key_map_.erase(collapse_key);
954 } 966 }
955 967
956 return packet; 968 return packet;
957 } 969 }
958 970
959 } // namespace gcm 971 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/mcs_client.h ('k') | google_apis/gcm/engine/mcs_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698