Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / invalidation / ticl_invalidation_service.cc
index 6f2b561..e83c843 100644 (file)
@@ -7,6 +7,8 @@
 #include "base/command_line.h"
 #include "base/metrics/histogram.h"
 #include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/invalidation/gcm_network_channel_delegate_impl.h"
+#include "chrome/browser/invalidation/invalidation_logger.h"
 #include "chrome/browser/invalidation/invalidation_service_util.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/signin/about_signin_internals.h"
 #include "content/public/browser/notification_service.h"
 #include "google_apis/gaia/gaia_constants.h"
 #include "sync/notifier/gcm_network_channel_delegate.h"
+#include "sync/notifier/invalidation_util.h"
 #include "sync/notifier/invalidator.h"
 #include "sync/notifier/invalidator_state.h"
 #include "sync/notifier/non_blocking_invalidator.h"
+#include "sync/notifier/object_id_invalidation_map.h"
 
 static const char* kOAuth2Scopes[] = {
   GaiaConstants::kGoogleTalkOAuth2Scope
@@ -64,8 +68,8 @@ TiclInvalidationService::TiclInvalidationService(
       signin_manager_(signin),
       oauth2_token_service_(oauth2_token_service),
       invalidator_registrar_(new syncer::InvalidatorRegistrar()),
-      request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) {
-}
+      request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
+      logger_() {}
 
 TiclInvalidationService::~TiclInvalidationService() {
   DCHECK(CalledOnValidThread());
@@ -152,6 +156,10 @@ std::string TiclInvalidationService::GetInvalidatorClientId() const {
   return invalidator_storage_->GetInvalidatorClientId();
 }
 
+InvalidationLogger* TiclInvalidationService::GetInvalidationLogger() {
+  return &logger_;
+}
+
 void TiclInvalidationService::Observe(
     int type,
     const content::NotificationSource& source,
@@ -171,7 +179,7 @@ void TiclInvalidationService::RequestAccessToken() {
     oauth2_scopes.insert(kOAuth2Scopes[i]);
   // Invalidate previous token, otherwise token service will return the same
   // token again.
-  const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId();
+  const std::string& account_id = signin_manager_->GetAuthenticatedAccountId();
   oauth2_token_service_->InvalidateToken(account_id,
                                          oauth2_scopes,
                                          access_token_);
@@ -229,7 +237,7 @@ void TiclInvalidationService::OnGetTokenFailure(
 
 void TiclInvalidationService::OnRefreshTokenAvailable(
     const std::string& account_id) {
-  if (oauth2_token_service_->GetPrimaryAccountId() == account_id) {
+  if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
     if (!IsStarted() && IsReadyToStart()) {
       StartInvalidator(PUSH_CLIENT_CHANNEL);
     }
@@ -238,7 +246,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable(
 
 void TiclInvalidationService::OnRefreshTokenRevoked(
     const std::string& account_id) {
-  if (oauth2_token_service_->GetPrimaryAccountId() == account_id) {
+  if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
     access_token_.clear();
     if (IsStarted()) {
       UpdateInvalidatorCredentials();
@@ -265,11 +273,14 @@ void TiclInvalidationService::OnInvalidatorStateChange(
   } else {
     invalidator_registrar_->UpdateInvalidatorState(state);
   }
+  logger_.OnStateChange(state);
 }
 
 void TiclInvalidationService::OnIncomingInvalidation(
     const syncer::ObjectIdInvalidationMap& invalidation_map) {
   invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
+
+  logger_.OnInvalidation(invalidation_map);
 }
 
 void TiclInvalidationService::Shutdown() {
@@ -301,7 +312,7 @@ bool TiclInvalidationService::IsReadyToStart() {
   }
 
   if (!oauth2_token_service_->RefreshTokenIsAvailable(
-          oauth2_token_service_->GetPrimaryAccountId())) {
+          signin_manager_->GetAuthenticatedAccountId())) {
     DVLOG(2)
         << "Not starting TiclInvalidationServce: Waiting for refresh token.";
     return false;
@@ -343,9 +354,8 @@ void TiclInvalidationService::StartInvalidator(
       break;
     }
     case GCM_NETWORK_CHANNEL: {
-      // TODO(pavely): Pass NULL pointer for now. When GCMNetworkChannelDelegate
-      // is implemented it will be instantiated and passed here.
       scoped_ptr<syncer::GCMNetworkChannelDelegate> delegate;
+      delegate.reset(new GCMNetworkChannelDelegateImpl(profile_));
       network_channel_creator =
           syncer::NonBlockingInvalidator::MakeGCMNetworkChannelCreator(
               profile_->GetRequestContext(),