| 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 <string> |
| 8 #include <vector> |
| 9 |
| 7 #include "base/base64.h" | 10 #include "base/base64.h" |
| 8 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 12 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 15 #if !defined(OS_ANDROID) | 18 #if !defined(OS_ANDROID) |
| 16 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 19 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
| 17 #endif | 20 #endif |
| 18 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/state_store.h" | 22 #include "chrome/browser/extensions/state_store.h" |
| 20 #include "chrome/browser/services/gcm/gcm_client_factory.h" | 23 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
| 21 #include "chrome/browser/services/gcm/gcm_event_router.h" | 24 #include "chrome/browser/services/gcm/gcm_event_router.h" |
| 25 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 22 #include "chrome/browser/signin/signin_manager.h" | 27 #include "chrome/browser/signin/signin_manager.h" |
| 23 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 24 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| 27 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 28 #include "components/user_prefs/pref_registry_syncable.h" | 33 #include "components/user_prefs/pref_registry_syncable.h" |
| 29 #include "components/webdata/encryptor/encryptor.h" | 34 #include "components/webdata/encryptor/encryptor.h" |
| 30 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 virtual void OnMessageReceived( | 252 virtual void OnMessageReceived( |
| 248 const std::string& app_id, | 253 const std::string& app_id, |
| 249 const GCMClient::IncomingMessage& message) OVERRIDE; | 254 const GCMClient::IncomingMessage& message) OVERRIDE; |
| 250 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 255 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; |
| 251 virtual void OnMessageSendError(const std::string& app_id, | 256 virtual void OnMessageSendError(const std::string& app_id, |
| 252 const std::string& message_id, | 257 const std::string& message_id, |
| 253 GCMClient::Result result) OVERRIDE; | 258 GCMClient::Result result) OVERRIDE; |
| 254 virtual void OnGCMReady() OVERRIDE; | 259 virtual void OnGCMReady() OVERRIDE; |
| 255 | 260 |
| 256 // Called on IO thread. | 261 // Called on IO thread. |
| 257 void Initialize( | 262 void Initialize(GCMClientFactory* gcm_client_factory, |
| 258 GCMClientFactory* gcm_client_factory, | 263 const base::FilePath& store_path, |
| 259 const base::FilePath& store_path, | 264 const std::vector<std::string>& account_ids, |
| 260 const scoped_refptr<net::URLRequestContextGetter>& | 265 const scoped_refptr<net::URLRequestContextGetter>& |
| 261 url_request_context_getter); | 266 url_request_context_getter); |
| 262 void Reset(); | 267 void Reset(); |
| 263 void CheckOut(); | 268 void CheckOut(); |
| 264 void Register(const std::string& app_id, | 269 void Register(const std::string& app_id, |
| 265 const std::vector<std::string>& sender_ids, | 270 const std::vector<std::string>& sender_ids, |
| 266 const std::string& cert); | 271 const std::string& cert); |
| 267 void Unregister(const std::string& app_id); | 272 void Unregister(const std::string& app_id); |
| 268 void Send(const std::string& app_id, | 273 void Send(const std::string& app_id, |
| 269 const std::string& receiver_id, | 274 const std::string& receiver_id, |
| 270 const GCMClient::OutgoingMessage& message); | 275 const GCMClient::OutgoingMessage& message); |
| 271 | 276 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 283 : service_(service) { | 288 : service_(service) { |
| 284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 289 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 285 } | 290 } |
| 286 | 291 |
| 287 GCMProfileService::IOWorker::~IOWorker() { | 292 GCMProfileService::IOWorker::~IOWorker() { |
| 288 } | 293 } |
| 289 | 294 |
| 290 void GCMProfileService::IOWorker::Initialize( | 295 void GCMProfileService::IOWorker::Initialize( |
| 291 GCMClientFactory* gcm_client_factory, | 296 GCMClientFactory* gcm_client_factory, |
| 292 const base::FilePath& store_path, | 297 const base::FilePath& store_path, |
| 298 const std::vector<std::string>& account_ids, |
| 293 const scoped_refptr<net::URLRequestContextGetter>& | 299 const scoped_refptr<net::URLRequestContextGetter>& |
| 294 url_request_context_getter) { | 300 url_request_context_getter) { |
| 295 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 296 | 302 |
| 297 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); | 303 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); |
| 298 | 304 |
| 299 checkin_proto::ChromeBuildProto chrome_build_proto; | 305 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 300 chrome_build_proto.set_platform(GetPlatform()); | 306 chrome_build_proto.set_platform(GetPlatform()); |
| 301 chrome_build_proto.set_chrome_version(GetVersion()); | 307 chrome_build_proto.set_chrome_version(GetVersion()); |
| 302 chrome_build_proto.set_channel(GetChannel()); | 308 chrome_build_proto.set_channel(GetChannel()); |
| 303 | 309 |
| 304 scoped_refptr<base::SequencedWorkerPool> worker_pool( | 310 scoped_refptr<base::SequencedWorkerPool> worker_pool( |
| 305 content::BrowserThread::GetBlockingPool()); | 311 content::BrowserThread::GetBlockingPool()); |
| 306 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 312 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
| 307 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 313 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 308 worker_pool->GetSequenceToken(), | 314 worker_pool->GetSequenceToken(), |
| 309 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 315 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 310 | 316 |
| 311 gcm_client_->Initialize(chrome_build_proto, | 317 gcm_client_->Initialize(chrome_build_proto, |
| 312 store_path, | 318 store_path, |
| 319 account_ids, |
| 313 blocking_task_runner, | 320 blocking_task_runner, |
| 314 url_request_context_getter, | 321 url_request_context_getter, |
| 315 this); | 322 this); |
| 316 | 323 |
| 317 content::BrowserThread::PostTask( | 324 content::BrowserThread::PostTask( |
| 318 content::BrowserThread::UI, | 325 content::BrowserThread::UI, |
| 319 FROM_HERE, | 326 FROM_HERE, |
| 320 base::Bind(&GCMProfileService::FinishInitializationOnUI, | 327 base::Bind(&GCMProfileService::FinishInitializationOnUI, |
| 321 service_, | 328 service_, |
| 322 gcm_client_->IsReady())); | 329 gcm_client_->IsReady())); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 void GCMProfileService::CheckIn(const std::string& username) { | 715 void GCMProfileService::CheckIn(const std::string& username) { |
| 709 DCHECK(!username.empty() && username_.empty()); | 716 DCHECK(!username.empty() && username_.empty()); |
| 710 username_ = username; | 717 username_ = username; |
| 711 | 718 |
| 712 DCHECK(!delayed_task_controller_); | 719 DCHECK(!delayed_task_controller_); |
| 713 delayed_task_controller_.reset(new DelayedTaskController); | 720 delayed_task_controller_.reset(new DelayedTaskController); |
| 714 | 721 |
| 715 // Load all register apps. | 722 // Load all register apps. |
| 716 ReadRegisteredAppIDs(); | 723 ReadRegisteredAppIDs(); |
| 717 | 724 |
| 725 // Get the list of available accounts. |
| 726 std::vector<std::string> account_ids = |
| 727 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts(); |
| 728 |
| 718 // Let the IO thread create and initialize GCMClient. | 729 // Let the IO thread create and initialize GCMClient. |
| 719 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 730 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 720 profile_->GetRequestContext(); | 731 profile_->GetRequestContext(); |
| 721 content::BrowserThread::PostTask( | 732 content::BrowserThread::PostTask( |
| 722 content::BrowserThread::IO, | 733 content::BrowserThread::IO, |
| 723 FROM_HERE, | 734 FROM_HERE, |
| 724 base::Bind(&GCMProfileService::IOWorker::Initialize, | 735 base::Bind(&GCMProfileService::IOWorker::Initialize, |
| 725 io_worker_, | 736 io_worker_, |
| 726 gcm_client_factory_.get(), | 737 gcm_client_factory_.get(), |
| 727 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 738 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 739 account_ids, |
| 728 url_request_context_getter)); | 740 url_request_context_getter)); |
| 729 } | 741 } |
| 730 | 742 |
| 731 void GCMProfileService::CheckOut() { | 743 void GCMProfileService::CheckOut() { |
| 732 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 744 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 733 | 745 |
| 734 DCHECK(!username_.empty()); | 746 DCHECK(!username_.empty()); |
| 735 username_.clear(); | 747 username_.clear(); |
| 736 | 748 |
| 737 // Remove persisted data from app's state store. | 749 // Remove persisted data from app's state store. |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 | 1040 |
| 1029 return true; | 1041 return true; |
| 1030 } | 1042 } |
| 1031 | 1043 |
| 1032 // static | 1044 // static |
| 1033 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1045 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
| 1034 return kRegistrationKey; | 1046 return kRegistrationKey; |
| 1035 } | 1047 } |
| 1036 | 1048 |
| 1037 } // namespace gcm | 1049 } // namespace gcm |
| OLD | NEW |