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

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 171513004: [GCM] Adding a list of accounts present on the client to checkin request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
258 GCMClientFactory* gcm_client_factory, 263 GCMClientFactory* gcm_client_factory,
259 const base::FilePath& store_path, 264 const base::FilePath& store_path,
265 const std::vector<std::string>& account_ids,
260 const scoped_refptr<net::URLRequestContextGetter>& 266 const scoped_refptr<net::URLRequestContextGetter>&
261 url_request_context_getter); 267 url_request_context_getter);
262 void Reset(); 268 void Reset();
263 void CheckOut(); 269 void CheckOut();
264 void Register(const std::string& app_id, 270 void Register(const std::string& app_id,
265 const std::vector<std::string>& sender_ids, 271 const std::vector<std::string>& sender_ids,
266 const std::string& cert); 272 const std::string& cert);
267 void Unregister(const std::string& app_id); 273 void Unregister(const std::string& app_id);
268 void Send(const std::string& app_id, 274 void Send(const std::string& app_id,
269 const std::string& receiver_id, 275 const std::string& receiver_id,
(...skipping 13 matching lines...) Expand all
283 : service_(service) { 289 : service_(service) {
284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 290 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
285 } 291 }
286 292
287 GCMProfileService::IOWorker::~IOWorker() { 293 GCMProfileService::IOWorker::~IOWorker() {
288 } 294 }
289 295
290 void GCMProfileService::IOWorker::Initialize( 296 void GCMProfileService::IOWorker::Initialize(
291 GCMClientFactory* gcm_client_factory, 297 GCMClientFactory* gcm_client_factory,
292 const base::FilePath& store_path, 298 const base::FilePath& store_path,
299 const std::vector<std::string>& account_ids,
293 const scoped_refptr<net::URLRequestContextGetter>& 300 const scoped_refptr<net::URLRequestContextGetter>&
294 url_request_context_getter) { 301 url_request_context_getter) {
295 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 302 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
296 303
297 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); 304 gcm_client_ = gcm_client_factory->BuildInstance().Pass();
298 305
299 checkin_proto::ChromeBuildProto chrome_build_proto; 306 checkin_proto::ChromeBuildProto chrome_build_proto;
300 chrome_build_proto.set_platform(GetPlatform()); 307 chrome_build_proto.set_platform(GetPlatform());
301 chrome_build_proto.set_chrome_version(GetVersion()); 308 chrome_build_proto.set_chrome_version(GetVersion());
302 chrome_build_proto.set_channel(GetChannel()); 309 chrome_build_proto.set_channel(GetChannel());
303 310
304 scoped_refptr<base::SequencedWorkerPool> worker_pool( 311 scoped_refptr<base::SequencedWorkerPool> worker_pool(
305 content::BrowserThread::GetBlockingPool()); 312 content::BrowserThread::GetBlockingPool());
306 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 313 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
307 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 314 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
308 worker_pool->GetSequenceToken(), 315 worker_pool->GetSequenceToken(),
309 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 316 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
310 317
311 gcm_client_->Initialize(chrome_build_proto, 318 gcm_client_->Initialize(chrome_build_proto,
312 store_path, 319 store_path,
320 account_ids,
313 blocking_task_runner, 321 blocking_task_runner,
314 url_request_context_getter, 322 url_request_context_getter,
315 this); 323 this);
316 324
317 content::BrowserThread::PostTask( 325 content::BrowserThread::PostTask(
318 content::BrowserThread::UI, 326 content::BrowserThread::UI,
319 FROM_HERE, 327 FROM_HERE,
320 base::Bind(&GCMProfileService::FinishInitializationOnUI, 328 base::Bind(&GCMProfileService::FinishInitializationOnUI,
321 service_, 329 service_,
322 gcm_client_->IsReady())); 330 gcm_client_->IsReady()));
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 void GCMProfileService::CheckIn(const std::string& username) { 716 void GCMProfileService::CheckIn(const std::string& username) {
709 DCHECK(!username.empty() && username_.empty()); 717 DCHECK(!username.empty() && username_.empty());
710 username_ = username; 718 username_ = username;
711 719
712 DCHECK(!delayed_task_controller_); 720 DCHECK(!delayed_task_controller_);
713 delayed_task_controller_.reset(new DelayedTaskController); 721 delayed_task_controller_.reset(new DelayedTaskController);
714 722
715 // Load all register apps. 723 // Load all register apps.
716 ReadRegisteredAppIDs(); 724 ReadRegisteredAppIDs();
717 725
726 // Get the list of avialable accounts.
jianli 2014/02/19 01:18:12 nit: typo for available
fgorski 2014/02/19 19:00:25 Done.
727 std::vector<std::string> account_ids =
728 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts();
729
718 // Let the IO thread create and initialize GCMClient. 730 // Let the IO thread create and initialize GCMClient.
719 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 731 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
720 profile_->GetRequestContext(); 732 profile_->GetRequestContext();
721 content::BrowserThread::PostTask( 733 content::BrowserThread::PostTask(
722 content::BrowserThread::IO, 734 content::BrowserThread::IO,
723 FROM_HERE, 735 FROM_HERE,
724 base::Bind(&GCMProfileService::IOWorker::Initialize, 736 base::Bind(&GCMProfileService::IOWorker::Initialize,
725 io_worker_, 737 io_worker_,
726 gcm_client_factory_.get(), 738 gcm_client_factory_.get(),
727 profile_->GetPath().Append(chrome::kGCMStoreDirname), 739 profile_->GetPath().Append(chrome::kGCMStoreDirname),
740 account_ids,
728 url_request_context_getter)); 741 url_request_context_getter));
729 } 742 }
730 743
731 void GCMProfileService::CheckOut() { 744 void GCMProfileService::CheckOut() {
732 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 745 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
733 746
734 DCHECK(!username_.empty()); 747 DCHECK(!username_.empty());
735 username_.clear(); 748 username_.clear();
736 749
737 // Remove persisted data from app's state store. 750 // Remove persisted data from app's state store.
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 1041
1029 return true; 1042 return true;
1030 } 1043 }
1031 1044
1032 // static 1045 // static
1033 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { 1046 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() {
1034 return kRegistrationKey; 1047 return kRegistrationKey;
1035 } 1048 }
1036 1049
1037 } // namespace gcm 1050 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/checkin_request.h » ('j') | google_apis/gcm/engine/checkin_request.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698