| OLD | NEW |
| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 | 377 |
| 378 void ChromeToMobileService::OnIncomingNotification( | 378 void ChromeToMobileService::OnIncomingNotification( |
| 379 const syncer::ObjectIdPayloadMap& id_payloads, | 379 const syncer::ObjectIdPayloadMap& id_payloads, |
| 380 syncer::IncomingNotificationSource source) { | 380 syncer::IncomingNotificationSource source) { |
| 381 DCHECK_EQ(id_payloads.size(), 1U); | 381 DCHECK_EQ(id_payloads.size(), 1U); |
| 382 DCHECK_EQ(id_payloads.count(invalidation::ObjectId( | 382 DCHECK_EQ(id_payloads.count(invalidation::ObjectId( |
| 383 ipc::invalidation::ObjectSource::CHROME_COMPONENTS, | 383 ipc::invalidation::ObjectSource::CHROME_COMPONENTS, |
| 384 kSyncInvalidationObjectIdChromeToMobileDeviceList)), 1U); | 384 kSyncInvalidationObjectIdChromeToMobileDeviceList)), 1U); |
| 385 RequestDeviceSearch(); | 385 RequestDeviceSearch(); |
| 386 // TODO(msw|akalin): This may not necessarily mean notifications are enabled. |
| 387 OnNotificationsEnabled(); |
| 386 } | 388 } |
| 387 | 389 |
| 388 const std::string& ChromeToMobileService::GetAccessTokenForTest() const { | 390 const std::string& ChromeToMobileService::GetAccessTokenForTest() const { |
| 389 return access_token_; | 391 return access_token_; |
| 390 } | 392 } |
| 391 | 393 |
| 392 void ChromeToMobileService::SetAccessTokenForTest( | 394 void ChromeToMobileService::SetAccessTokenForTest( |
| 393 const std::string& access_token) { | 395 const std::string& access_token) { |
| 394 access_token_ = access_token; | 396 access_token_ = access_token; |
| 395 } | 397 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 access_token_fetcher_.reset( | 504 access_token_fetcher_.reset( |
| 503 new OAuth2AccessTokenFetcher(this, profile_->GetRequestContext())); | 505 new OAuth2AccessTokenFetcher(this, profile_->GetRequestContext())); |
| 504 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 506 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
| 505 access_token_fetcher_->Start(gaia_urls->oauth2_chrome_client_id(), | 507 access_token_fetcher_->Start(gaia_urls->oauth2_chrome_client_id(), |
| 506 gaia_urls->oauth2_chrome_client_secret(), | 508 gaia_urls->oauth2_chrome_client_secret(), |
| 507 token_service->GetOAuth2LoginRefreshToken(), | 509 token_service->GetOAuth2LoginRefreshToken(), |
| 508 std::vector<std::string>(1, kCloudPrintAuth)); | 510 std::vector<std::string>(1, kCloudPrintAuth)); |
| 509 } | 511 } |
| 510 | 512 |
| 511 void ChromeToMobileService::RequestDeviceSearch() { | 513 void ChromeToMobileService::RequestDeviceSearch() { |
| 512 DCHECK(sync_invalidation_enabled_); | |
| 513 if (access_token_.empty()) { | 514 if (access_token_.empty()) { |
| 514 // Enqueue this task to perform after obtaining an access token. | 515 // Enqueue this task to perform after obtaining an access token. |
| 515 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch, | 516 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch, |
| 516 weak_ptr_factory_.GetWeakPtr())); | 517 weak_ptr_factory_.GetWeakPtr())); |
| 517 RequestAccessToken(); | 518 RequestAccessToken(); |
| 518 return; | 519 return; |
| 519 } | 520 } |
| 520 | 521 |
| 521 LogMetric(DEVICES_REQUESTED); | 522 LogMetric(DEVICES_REQUESTED); |
| 522 | 523 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 600 |
| 600 // Ensure a second response is not sent after reporting failure below. | 601 // Ensure a second response is not sent after reporting failure below. |
| 601 request_observer_map_.erase(other); | 602 request_observer_map_.erase(other); |
| 602 break; | 603 break; |
| 603 } | 604 } |
| 604 } | 605 } |
| 605 | 606 |
| 606 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); | 607 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); |
| 607 observer->OnSendComplete(success); | 608 observer->OnSendComplete(success); |
| 608 } | 609 } |
| OLD | NEW |