Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/services/gcm/gcm_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.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/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 const std::string& app_id, | 248 const std::string& app_id, |
| 249 const GCMClient::IncomingMessage& message) OVERRIDE; | 249 const GCMClient::IncomingMessage& message) OVERRIDE; |
| 250 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 250 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| 251 virtual void OnMessageSendError(const std::string& app_id, | 251 virtual void OnMessageSendError(const std::string& app_id, |
| 252 const std::string& message_id, | 252 const std::string& message_id, |
| 253 GCMClient::Result result) OVERRIDE; | 253 GCMClient::Result result) OVERRIDE; |
| 254 virtual void OnGCMReady() OVERRIDE; | 254 virtual void OnGCMReady() OVERRIDE; |
| 255 | 255 |
| 256 // Called on IO thread. | 256 // Called on IO thread. |
| 257 void Initialize( | 257 void Initialize( |
| 258 GCMClientFactory* gcm_client_factory, | 258 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 259 const base::FilePath& store_path, | 259 const base::FilePath& store_path, |
| 260 const scoped_refptr<net::URLRequestContextGetter>& | 260 const scoped_refptr<net::URLRequestContextGetter>& |
| 261 url_request_context_getter); | 261 url_request_context_getter); |
| 262 void Reset(); | 262 void Reset(); |
| 263 void CheckIn(); | |
| 263 void CheckOut(); | 264 void CheckOut(); |
| 264 void Register(const std::string& app_id, | 265 void Register(const std::string& app_id, |
| 265 const std::vector<std::string>& sender_ids, | 266 const std::vector<std::string>& sender_ids, |
| 266 const std::string& cert); | 267 const std::string& cert); |
| 267 void Unregister(const std::string& app_id); | 268 void Unregister(const std::string& app_id); |
| 268 void Send(const std::string& app_id, | 269 void Send(const std::string& app_id, |
| 269 const std::string& receiver_id, | 270 const std::string& receiver_id, |
| 270 const GCMClient::OutgoingMessage& message); | 271 const GCMClient::OutgoingMessage& message); |
| 271 | 272 |
| 273 // For testing purpose. Can be called from UI thread. Use with care. | |
| 274 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | |
| 275 | |
| 272 private: | 276 private: |
| 273 friend class base::RefCountedThreadSafe<IOWorker>; | 277 friend class base::RefCountedThreadSafe<IOWorker>; |
| 274 virtual ~IOWorker(); | 278 virtual ~IOWorker(); |
| 275 | 279 |
| 276 const base::WeakPtr<GCMProfileService> service_; | 280 const base::WeakPtr<GCMProfileService> service_; |
| 277 | 281 |
| 278 scoped_ptr<GCMClient> gcm_client_; | 282 scoped_ptr<GCMClient> gcm_client_; |
| 279 }; | 283 }; |
| 280 | 284 |
| 281 GCMProfileService::IOWorker::IOWorker( | 285 GCMProfileService::IOWorker::IOWorker( |
| 282 const base::WeakPtr<GCMProfileService>& service) | 286 const base::WeakPtr<GCMProfileService>& service) |
| 283 : service_(service) { | 287 : service_(service) { |
| 284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 288 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 285 } | 289 } |
| 286 | 290 |
| 287 GCMProfileService::IOWorker::~IOWorker() { | 291 GCMProfileService::IOWorker::~IOWorker() { |
| 288 } | 292 } |
| 289 | 293 |
| 290 void GCMProfileService::IOWorker::Initialize( | 294 void GCMProfileService::IOWorker::Initialize( |
| 291 GCMClientFactory* gcm_client_factory, | 295 scoped_ptr<GCMClientFactory> gcm_client_factory, |
| 292 const base::FilePath& store_path, | 296 const base::FilePath& store_path, |
| 293 const scoped_refptr<net::URLRequestContextGetter>& | 297 const scoped_refptr<net::URLRequestContextGetter>& |
| 294 url_request_context_getter) { | 298 url_request_context_getter) { |
| 295 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 299 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 296 | 300 |
| 297 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); | 301 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); |
| 298 | 302 |
| 299 checkin_proto::ChromeBuildProto chrome_build_proto; | 303 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 300 chrome_build_proto.set_platform(GetPlatform()); | 304 chrome_build_proto.set_platform(GetPlatform()); |
| 301 chrome_build_proto.set_chrome_version(GetVersion()); | 305 chrome_build_proto.set_chrome_version(GetVersion()); |
| 302 chrome_build_proto.set_channel(GetChannel()); | 306 chrome_build_proto.set_channel(GetChannel()); |
| 303 | 307 |
| 304 scoped_refptr<base::SequencedWorkerPool> worker_pool( | 308 scoped_refptr<base::SequencedWorkerPool> worker_pool( |
| 305 content::BrowserThread::GetBlockingPool()); | 309 content::BrowserThread::GetBlockingPool()); |
| 306 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 310 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
| 307 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 311 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 308 worker_pool->GetSequenceToken(), | 312 worker_pool->GetSequenceToken(), |
| 309 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 313 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 310 | 314 |
| 311 gcm_client_->Initialize(chrome_build_proto, | 315 gcm_client_->Initialize(chrome_build_proto, |
| 312 store_path, | 316 store_path, |
| 313 blocking_task_runner, | 317 blocking_task_runner, |
| 314 url_request_context_getter, | 318 url_request_context_getter, |
| 315 this); | 319 this); |
| 316 | 320 |
| 317 content::BrowserThread::PostTask( | 321 content::BrowserThread::PostTask( |
| 318 content::BrowserThread::UI, | 322 content::BrowserThread::UI, |
| 319 FROM_HERE, | 323 FROM_HERE, |
| 320 base::Bind(&GCMProfileService::FinishInitializationOnUI, | 324 base::Bind(&GCMProfileService::FinishInitializationOnUI, service_)); |
| 321 service_, | |
| 322 gcm_client_->IsReady())); | |
| 323 } | 325 } |
| 324 | 326 |
| 325 void GCMProfileService::IOWorker::Reset() { | 327 void GCMProfileService::IOWorker::Reset() { |
| 326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 328 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 327 | 329 |
| 328 // GCMClient instance must be destroyed from the same thread where it was | 330 // GCMClient instance must be destroyed from the same thread where it was |
| 329 // created. | 331 // created. |
| 330 gcm_client_.reset(); | 332 gcm_client_.reset(); |
| 331 } | 333 } |
| 332 | 334 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 } | 412 } |
| 411 | 413 |
| 412 void GCMProfileService::IOWorker::OnGCMReady() { | 414 void GCMProfileService::IOWorker::OnGCMReady() { |
| 413 content::BrowserThread::PostTask( | 415 content::BrowserThread::PostTask( |
| 414 content::BrowserThread::UI, | 416 content::BrowserThread::UI, |
| 415 FROM_HERE, | 417 FROM_HERE, |
| 416 base::Bind(&GCMProfileService::GCMClientReady, | 418 base::Bind(&GCMProfileService::GCMClientReady, |
| 417 service_)); | 419 service_)); |
| 418 } | 420 } |
| 419 | 421 |
| 422 void GCMProfileService::IOWorker::CheckIn() { | |
| 423 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 424 | |
| 425 gcm_client_->CheckIn(); | |
| 426 } | |
| 427 | |
| 420 void GCMProfileService::IOWorker::CheckOut() { | 428 void GCMProfileService::IOWorker::CheckOut() { |
| 421 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 429 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 422 | 430 |
| 423 gcm_client_->CheckOut(); | 431 gcm_client_->CheckOut(); |
| 424 gcm_client_.reset(); | |
| 425 } | 432 } |
| 426 | 433 |
| 427 void GCMProfileService::IOWorker::Register( | 434 void GCMProfileService::IOWorker::Register( |
| 428 const std::string& app_id, | 435 const std::string& app_id, |
| 429 const std::vector<std::string>& sender_ids, | 436 const std::vector<std::string>& sender_ids, |
| 430 const std::string& cert) { | 437 const std::string& cert) { |
| 431 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 438 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 432 | 439 |
| 433 gcm_client_->Register(app_id, cert, sender_ids); | 440 gcm_client_->Register(app_id, cert, sender_ids); |
| 434 } | 441 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 testing_delegate_(NULL), | 505 testing_delegate_(NULL), |
| 499 weak_ptr_factory_(this) { | 506 weak_ptr_factory_(this) { |
| 500 DCHECK(!profile->IsOffTheRecord()); | 507 DCHECK(!profile->IsOffTheRecord()); |
| 501 } | 508 } |
| 502 | 509 |
| 503 GCMProfileService::~GCMProfileService() { | 510 GCMProfileService::~GCMProfileService() { |
| 504 } | 511 } |
| 505 | 512 |
| 506 void GCMProfileService::Initialize( | 513 void GCMProfileService::Initialize( |
| 507 scoped_ptr<GCMClientFactory> gcm_client_factory) { | 514 scoped_ptr<GCMClientFactory> gcm_client_factory) { |
| 508 gcm_client_factory_ = gcm_client_factory.Pass(); | |
| 509 | |
| 510 // This has to be done first since CheckIn depends on it. | |
| 511 io_worker_ = new IOWorker(weak_ptr_factory_.GetWeakPtr()); | |
| 512 | |
| 513 #if !defined(OS_ANDROID) | |
| 514 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); | |
| 515 #endif | |
| 516 | |
| 517 registrar_.Add(this, | 515 registrar_.Add(this, |
| 518 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 516 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 519 content::Source<Profile>(profile_)); | 517 content::Source<Profile>(profile_)); |
| 520 registrar_.Add(this, | 518 registrar_.Add(this, |
| 521 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 519 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 522 content::Source<Profile>(profile_)); | 520 content::Source<Profile>(profile_)); |
| 523 registrar_.Add(this, | 521 registrar_.Add(this, |
| 524 chrome::NOTIFICATION_PROFILE_DESTROYED, | 522 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 525 content::Source<Profile>(profile_)); | 523 content::Source<Profile>(profile_)); |
| 526 // TODO(jianli): move extension specific logic out of GCMProfileService. | 524 // TODO(jianli): move extension specific logic out of GCMProfileService. |
| 527 registrar_.Add(this, | 525 registrar_.Add(this, |
| 528 chrome:: NOTIFICATION_EXTENSION_UNINSTALLED, | 526 chrome:: NOTIFICATION_EXTENSION_UNINSTALLED, |
| 529 content::Source<Profile>(profile_)); | 527 content::Source<Profile>(profile_)); |
| 530 | 528 |
| 531 // In case that the profile has been signed in before GCMProfileService is | 529 // Create and initialize the GCMClient. Note that this does not initiate the |
|
Nicolas Zea
2014/02/21 18:43:33
Initializing the client will result in connecting
jianli
2014/02/21 20:24:06
I have moved the GCMStore loading logic out of GCM
| |
| 532 // created. | 530 // GCM check-in. |
| 533 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_); | 531 io_worker_ = new IOWorker(weak_ptr_factory_.GetWeakPtr()); |
| 534 if (manager) { | 532 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 535 std::string username = manager->GetAuthenticatedUsername(); | 533 profile_->GetRequestContext(); |
| 536 if (!username.empty()) | 534 content::BrowserThread::PostTask( |
| 537 CheckIn(username); | 535 content::BrowserThread::IO, |
| 538 } | 536 FROM_HERE, |
| 537 base::Bind(&GCMProfileService::IOWorker::Initialize, | |
| 538 io_worker_, | |
| 539 base::Passed(&gcm_client_factory), | |
| 540 profile_->GetPath().Append(chrome::kGCMStoreDirname), | |
| 541 url_request_context_getter)); | |
| 539 } | 542 } |
| 540 | 543 |
| 541 void GCMProfileService::Register(const std::string& app_id, | 544 void GCMProfileService::Register(const std::string& app_id, |
| 542 const std::vector<std::string>& sender_ids, | 545 const std::vector<std::string>& sender_ids, |
| 543 const std::string& cert, | 546 const std::string& cert, |
| 544 RegisterCallback callback) { | 547 RegisterCallback callback) { |
| 545 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 548 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 546 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null()); | 549 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null()); |
| 547 | 550 |
| 551 // Ensure that check-in has been done. | |
| 552 EnsureCheckedIn(); | |
| 553 | |
| 548 // If the profile was not signed in, bail out. | 554 // If the profile was not signed in, bail out. |
| 549 if (username_.empty()) { | 555 if (username_.empty()) { |
| 550 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN); | 556 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN); |
| 551 return; | 557 return; |
| 552 } | 558 } |
| 553 | 559 |
| 554 // If previous register operation is still in progress, bail out. | 560 // If previous register operation is still in progress, bail out. |
| 555 if (register_callbacks_.find(app_id) != register_callbacks_.end()) { | 561 if (register_callbacks_.find(app_id) != register_callbacks_.end()) { |
| 556 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); | 562 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); |
| 557 return; | 563 return; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 cert)); | 629 cert)); |
| 624 } | 630 } |
| 625 | 631 |
| 626 void GCMProfileService::Send(const std::string& app_id, | 632 void GCMProfileService::Send(const std::string& app_id, |
| 627 const std::string& receiver_id, | 633 const std::string& receiver_id, |
| 628 const GCMClient::OutgoingMessage& message, | 634 const GCMClient::OutgoingMessage& message, |
| 629 SendCallback callback) { | 635 SendCallback callback) { |
| 630 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 636 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 631 DCHECK(!app_id.empty() && !receiver_id.empty() && !callback.is_null()); | 637 DCHECK(!app_id.empty() && !receiver_id.empty() && !callback.is_null()); |
| 632 | 638 |
| 639 // Ensure that check-in has been done. | |
| 640 EnsureCheckedIn(); | |
| 641 | |
| 633 // If the profile was not signed in, bail out. | 642 // If the profile was not signed in, bail out. |
| 634 if (username_.empty()) { | 643 if (username_.empty()) { |
| 635 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN); | 644 callback.Run(std::string(), GCMClient::NOT_SIGNED_IN); |
| 636 return; | 645 return; |
| 637 } | 646 } |
| 638 | 647 |
| 639 // If the message with send ID is still in progress, bail out. | 648 // If the message with send ID is still in progress, bail out. |
| 640 std::pair<std::string, std::string> key(app_id, message.id); | 649 std::pair<std::string, std::string> key(app_id, message.id); |
| 641 if (send_callbacks_.find(key) != send_callbacks_.end()) { | 650 if (send_callbacks_.find(key) != send_callbacks_.end()) { |
| 642 callback.Run(message.id, GCMClient::INVALID_PARAMETER); | 651 callback.Run(message.id, GCMClient::INVALID_PARAMETER); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 667 content::BrowserThread::PostTask( | 676 content::BrowserThread::PostTask( |
| 668 content::BrowserThread::IO, | 677 content::BrowserThread::IO, |
| 669 FROM_HERE, | 678 FROM_HERE, |
| 670 base::Bind(&GCMProfileService::IOWorker::Send, | 679 base::Bind(&GCMProfileService::IOWorker::Send, |
| 671 io_worker_, | 680 io_worker_, |
| 672 app_id, | 681 app_id, |
| 673 receiver_id, | 682 receiver_id, |
| 674 message)); | 683 message)); |
| 675 } | 684 } |
| 676 | 685 |
| 686 GCMClient* GCMProfileService::GetGCMClientForTesting() const { | |
| 687 return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL; | |
| 688 } | |
| 689 | |
| 677 void GCMProfileService::Observe(int type, | 690 void GCMProfileService::Observe(int type, |
| 678 const content::NotificationSource& source, | 691 const content::NotificationSource& source, |
| 679 const content::NotificationDetails& details) { | 692 const content::NotificationDetails& details) { |
| 680 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 693 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 681 | 694 |
| 682 switch (type) { | 695 switch (type) { |
| 683 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 696 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
| 684 const GoogleServiceSigninSuccessDetails* signin_details = | 697 if (IsGCMChannelEnabled()) |
| 685 content::Details<GoogleServiceSigninSuccessDetails>(details).ptr(); | 698 EnsureCheckedIn(); |
| 686 // This could be called multiple times when the password changed. | |
| 687 if (username_ != signin_details->username) | |
| 688 CheckIn(signin_details->username); | |
| 689 break; | 699 break; |
| 690 } | 700 } |
| 691 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 701 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
| 692 CheckOut(); | 702 CheckOut(); |
| 693 break; | 703 break; |
| 694 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 704 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
| 695 ResetGCMClient(); | 705 ResetGCMClient(); |
| 696 break; | 706 break; |
| 697 case chrome:: NOTIFICATION_EXTENSION_UNINSTALLED: { | 707 case chrome:: NOTIFICATION_EXTENSION_UNINSTALLED: |
| 698 extensions::Extension* extension = | 708 if (!username_.empty()) { |
| 699 content::Details<extensions::Extension>(details).ptr(); | 709 extensions::Extension* extension = |
| 700 Unregister(extension->id()); | 710 content::Details<extensions::Extension>(details).ptr(); |
| 711 Unregister(extension->id()); | |
| 712 } | |
| 701 break; | 713 break; |
| 702 } | |
| 703 default: | 714 default: |
| 704 NOTREACHED(); | 715 NOTREACHED(); |
| 705 } | 716 } |
| 706 } | 717 } |
| 707 | 718 |
| 708 void GCMProfileService::CheckIn(const std::string& username) { | 719 bool GCMProfileService::IsGCMChannelEnabled() const { |
| 709 DCHECK(!username.empty() && username_.empty()); | 720 const base::Value* gcm_enabled_value = |
| 721 profile_->GetPrefs()->GetUserPrefValue(prefs::kGCMChannelEnabled); | |
| 722 bool gcm_enabled = false; | |
| 723 return gcm_enabled_value && | |
| 724 gcm_enabled_value->GetAsBoolean(&gcm_enabled) && | |
| 725 gcm_enabled; | |
| 726 } | |
| 727 | |
| 728 void GCMProfileService::EnsureCheckedIn() { | |
| 729 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_); | |
| 730 if (!manager) | |
| 731 return; | |
| 732 std::string username = manager->GetAuthenticatedUsername(); | |
| 733 if (username.empty()) | |
| 734 return; | |
| 735 | |
| 736 // CheckIn could be called more than once when: | |
| 737 // 1) The password changes. | |
| 738 // 2) Register/send function calls it to ensure CheckIn is done. | |
| 739 if (username_ == username) | |
| 740 return; | |
| 710 username_ = username; | 741 username_ = username; |
| 711 | 742 |
| 743 #if !defined(OS_ANDROID) | |
| 744 if (!js_event_router_) | |
| 745 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); | |
| 746 #endif | |
| 747 | |
| 712 DCHECK(!delayed_task_controller_); | 748 DCHECK(!delayed_task_controller_); |
| 713 delayed_task_controller_.reset(new DelayedTaskController); | 749 delayed_task_controller_.reset(new DelayedTaskController); |
| 714 | 750 |
| 715 // Load all register apps. | 751 // Load all the registered apps. |
| 716 ReadRegisteredAppIDs(); | 752 ReadRegisteredAppIDs(); |
| 717 | 753 |
| 718 // Let the IO thread create and initialize GCMClient. | 754 // Initiate the GCM check-in. |
| 719 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | |
| 720 profile_->GetRequestContext(); | |
| 721 content::BrowserThread::PostTask( | 755 content::BrowserThread::PostTask( |
| 722 content::BrowserThread::IO, | 756 content::BrowserThread::IO, |
| 723 FROM_HERE, | 757 FROM_HERE, |
| 724 base::Bind(&GCMProfileService::IOWorker::Initialize, | 758 base::Bind(&GCMProfileService::IOWorker::CheckIn, io_worker_)); |
| 725 io_worker_, | |
| 726 gcm_client_factory_.get(), | |
| 727 profile_->GetPath().Append(chrome::kGCMStoreDirname), | |
| 728 url_request_context_getter)); | |
| 729 } | 759 } |
| 730 | 760 |
| 731 void GCMProfileService::CheckOut() { | 761 void GCMProfileService::CheckOut() { |
| 732 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 762 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 733 | 763 |
| 734 DCHECK(!username_.empty()); | 764 // We still proceed with the check-out logic even if the check-in is not |
| 765 // initiated in the current session. This will make sure that all the | |
| 766 // persisted data written previously will get purged. | |
| 735 username_.clear(); | 767 username_.clear(); |
| 736 | 768 |
| 737 // Remove persisted data from app's state store. | 769 // Remove persisted data from app's state store. |
| 738 for (RegistrationInfoMap::const_iterator iter = | 770 for (RegistrationInfoMap::const_iterator iter = |
| 739 registration_info_map_.begin(); | 771 registration_info_map_.begin(); |
| 740 iter != registration_info_map_.end(); ++iter) { | 772 iter != registration_info_map_.end(); ++iter) { |
| 741 DeleteRegistrationInfo(iter->first); | 773 DeleteRegistrationInfo(iter->first); |
| 742 } | 774 } |
| 743 | 775 |
| 744 // Remove persisted data from prefs store. | 776 // Remove persisted data from prefs store. |
| 745 profile_->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); | |
| 746 profile_->GetPrefs()->ClearPref(prefs::kGCMRegisteredAppIDs); | 777 profile_->GetPrefs()->ClearPref(prefs::kGCMRegisteredAppIDs); |
| 747 | 778 |
| 748 gcm_client_ready_ = false; | 779 gcm_client_ready_ = false; |
| 749 delayed_task_controller_.reset(); | 780 delayed_task_controller_.reset(); |
| 750 register_callbacks_.clear(); | 781 register_callbacks_.clear(); |
| 751 send_callbacks_.clear(); | 782 send_callbacks_.clear(); |
| 752 registration_info_map_.clear(); | 783 registration_info_map_.clear(); |
| 753 | 784 |
| 754 content::BrowserThread::PostTask( | 785 content::BrowserThread::PostTask( |
| 755 content::BrowserThread::IO, | 786 content::BrowserThread::IO, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 GCMClient::Result result) { | 912 GCMClient::Result result) { |
| 882 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 913 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 883 | 914 |
| 884 // Drop the event if signed out. | 915 // Drop the event if signed out. |
| 885 if (username_.empty()) | 916 if (username_.empty()) |
| 886 return; | 917 return; |
| 887 | 918 |
| 888 GetEventRouter(app_id)->OnSendError(app_id, message_id, result); | 919 GetEventRouter(app_id)->OnSendError(app_id, message_id, result); |
| 889 } | 920 } |
| 890 | 921 |
| 891 void GCMProfileService::FinishInitializationOnUI(bool ready) { | 922 void GCMProfileService::FinishInitializationOnUI() { |
| 892 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 923 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 893 | 924 |
| 894 gcm_client_ready_ = ready; | 925 // Initiates the check-in if the rollout signal indicates yes. |
| 895 if (gcm_client_ready_) | 926 if (IsGCMChannelEnabled()) |
| 896 delayed_task_controller_->SetGCMReady(); | 927 EnsureCheckedIn(); |
| 897 } | 928 } |
| 898 | 929 |
| 899 void GCMProfileService::GCMClientReady() { | 930 void GCMProfileService::GCMClientReady() { |
| 900 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 931 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 901 | 932 |
| 902 if (gcm_client_ready_) | 933 if (gcm_client_ready_) |
| 903 return; | 934 return; |
| 904 gcm_client_ready_ = true; | 935 gcm_client_ready_ = true; |
| 905 | 936 |
| 906 delayed_task_controller_->SetGCMReady(); | 937 delayed_task_controller_->SetGCMReady(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 | 1059 |
| 1029 return true; | 1060 return true; |
| 1030 } | 1061 } |
| 1031 | 1062 |
| 1032 // static | 1063 // static |
| 1033 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1064 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
| 1034 return kRegistrationKey; | 1065 return kRegistrationKey; |
| 1035 } | 1066 } |
| 1036 | 1067 |
| 1037 } // namespace gcm | 1068 } // namespace gcm |
| OLD | NEW |