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

Side by Side Diff: chrome/browser/chrome_to_mobile_service.cc

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chrome_to_mobile_service.h" 5 #include "chrome/browser/chrome_to_mobile_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ChromeToMobileService::ChromeToMobileService(Profile* profile) 176 ChromeToMobileService::ChromeToMobileService(Profile* profile)
177 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 177 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
178 profile_(profile), 178 profile_(profile),
179 sync_invalidation_enabled_(false) { 179 sync_invalidation_enabled_(false) {
180 // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183 180 // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183
181 ProfileSyncService* profile_sync_service = 181 ProfileSyncService* profile_sync_service =
182 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 182 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL;
183 if (profile_sync_service) { 183 if (profile_sync_service) {
184 CloudPrintURL cloud_print_url(profile_); 184 CloudPrintURL cloud_print_url(profile_);
185 cloud_print_url_ = cloud_print_url.GetCloudPrintServiceURL(); 185 cloud_print_url_ = cloud_print_url.GetCloudPrintServiceURL();
186 sync_invalidation_enabled_ =
187 (profile_sync_service->GetInvalidatorState() ==
188 syncer::INVALIDATIONS_ENABLED);
186 // Register for cloud print device list invalidation notifications. 189 // Register for cloud print device list invalidation notifications.
187 // TODO(msw|akalin): Initialize |sync_invalidation_enabled_| properly.
188 profile_sync_service->RegisterInvalidationHandler(this); 190 profile_sync_service->RegisterInvalidationHandler(this);
189 syncer::ObjectIdSet ids; 191 syncer::ObjectIdSet ids;
190 ids.insert(invalidation::ObjectId( 192 ids.insert(invalidation::ObjectId(
191 ipc::invalidation::ObjectSource::CHROME_COMPONENTS, 193 ipc::invalidation::ObjectSource::CHROME_COMPONENTS,
192 kSyncInvalidationObjectIdChromeToMobileDeviceList)); 194 kSyncInvalidationObjectIdChromeToMobileDeviceList));
193 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); 195 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids);
194 } 196 }
195 } 197 }
196 198
197 ChromeToMobileService::~ChromeToMobileService() { 199 ChromeToMobileService::~ChromeToMobileService() {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 void ChromeToMobileService::OnGetTokenFailure( 349 void ChromeToMobileService::OnGetTokenFailure(
348 const GoogleServiceAuthError& error) { 350 const GoogleServiceAuthError& error) {
349 access_token_fetcher_.reset(); 351 access_token_fetcher_.reset();
350 auth_retry_timer_.Stop(); 352 auth_retry_timer_.Stop();
351 353
352 auth_retry_timer_.Start( 354 auth_retry_timer_.Start(
353 FROM_HERE, base::TimeDelta::FromHours(kAuthRetryDelayHours), 355 FROM_HERE, base::TimeDelta::FromHours(kAuthRetryDelayHours),
354 this, &ChromeToMobileService::RequestAccessToken); 356 this, &ChromeToMobileService::RequestAccessToken);
355 } 357 }
356 358
357 void ChromeToMobileService::OnNotificationsEnabled() { 359 void ChromeToMobileService::OnInvalidatorStateChange(
358 sync_invalidation_enabled_ = true; 360 syncer::InvalidatorState state) {
361 sync_invalidation_enabled_ = (state == syncer::INVALIDATIONS_ENABLED);
359 UpdateCommandState(); 362 UpdateCommandState();
360 } 363 }
361 364
362 void ChromeToMobileService::OnNotificationsDisabled( 365 void ChromeToMobileService::OnIncomingInvalidation(
363 syncer::NotificationsDisabledReason reason) {
364 sync_invalidation_enabled_ = false;
365 UpdateCommandState();
366 }
367
368 void ChromeToMobileService::OnIncomingNotification(
369 const syncer::ObjectIdStateMap& id_state_map, 366 const syncer::ObjectIdStateMap& id_state_map,
370 syncer::IncomingNotificationSource source) { 367 syncer::IncomingInvalidationSource source) {
371 DCHECK_EQ(1U, id_state_map.size()); 368 DCHECK_EQ(1U, id_state_map.size());
372 DCHECK_EQ(1U, id_state_map.count(invalidation::ObjectId( 369 DCHECK_EQ(1U, id_state_map.count(invalidation::ObjectId(
373 ipc::invalidation::ObjectSource::CHROME_COMPONENTS, 370 ipc::invalidation::ObjectSource::CHROME_COMPONENTS,
374 kSyncInvalidationObjectIdChromeToMobileDeviceList))); 371 kSyncInvalidationObjectIdChromeToMobileDeviceList)));
375 RequestDeviceSearch(); 372 RequestDeviceSearch();
376 // TODO(msw|akalin): This may not necessarily mean notifications are enabled.
377 OnNotificationsEnabled();
378 } 373 }
379 374
380 const std::string& ChromeToMobileService::GetAccessTokenForTest() const { 375 const std::string& ChromeToMobileService::GetAccessTokenForTest() const {
381 return access_token_; 376 return access_token_;
382 } 377 }
383 378
384 void ChromeToMobileService::SetAccessTokenForTest( 379 void ChromeToMobileService::SetAccessTokenForTest(
385 const std::string& access_token) { 380 const std::string& access_token) {
386 access_token_ = access_token; 381 access_token_ = access_token;
387 } 382 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 587
593 // Report failure below and ignore the second response. 588 // Report failure below and ignore the second response.
594 request_observer_map_.erase(other); 589 request_observer_map_.erase(other);
595 break; 590 break;
596 } 591 }
597 } 592 }
598 593
599 if (observer.get()) 594 if (observer.get())
600 observer->OnSendComplete(success); 595 observer->OnSendComplete(success);
601 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698