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

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: Fix to android test issue 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 "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 virtual void OnMessageReceived( 251 virtual void OnMessageReceived(
247 const std::string& app_id, 252 const std::string& app_id,
248 const GCMClient::IncomingMessage& message) OVERRIDE; 253 const GCMClient::IncomingMessage& message) OVERRIDE;
249 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; 254 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
250 virtual void OnMessageSendError(const std::string& app_id, 255 virtual void OnMessageSendError(const std::string& app_id,
251 const std::string& message_id, 256 const std::string& message_id,
252 GCMClient::Result result) OVERRIDE; 257 GCMClient::Result result) OVERRIDE;
253 virtual void OnGCMReady() OVERRIDE; 258 virtual void OnGCMReady() OVERRIDE;
254 259
255 // Called on IO thread. 260 // Called on IO thread.
256 void Initialize( 261 void Initialize(GCMClientFactory* gcm_client_factory,
257 GCMClientFactory* gcm_client_factory, 262 const base::FilePath& store_path,
258 const base::FilePath& store_path, 263 const std::vector<std::string>& account_ids,
259 const scoped_refptr<net::URLRequestContextGetter>& 264 const scoped_refptr<net::URLRequestContextGetter>&
260 url_request_context_getter); 265 url_request_context_getter);
261 void Reset(); 266 void Reset();
262 void CheckOut(); 267 void CheckOut();
263 void Register(const std::string& app_id, 268 void Register(const std::string& app_id,
264 const std::vector<std::string>& sender_ids, 269 const std::vector<std::string>& sender_ids,
265 const std::string& cert); 270 const std::string& cert);
266 void Unregister(const std::string& app_id); 271 void Unregister(const std::string& app_id);
267 void Send(const std::string& app_id, 272 void Send(const std::string& app_id,
268 const std::string& receiver_id, 273 const std::string& receiver_id,
269 const GCMClient::OutgoingMessage& message); 274 const GCMClient::OutgoingMessage& message);
270 275
(...skipping 11 matching lines...) Expand all
282 : service_(service) { 287 : service_(service) {
283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 288 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
284 } 289 }
285 290
286 GCMProfileService::IOWorker::~IOWorker() { 291 GCMProfileService::IOWorker::~IOWorker() {
287 } 292 }
288 293
289 void GCMProfileService::IOWorker::Initialize( 294 void GCMProfileService::IOWorker::Initialize(
290 GCMClientFactory* gcm_client_factory, 295 GCMClientFactory* gcm_client_factory,
291 const base::FilePath& store_path, 296 const base::FilePath& store_path,
297 const std::vector<std::string>& account_ids,
292 const scoped_refptr<net::URLRequestContextGetter>& 298 const scoped_refptr<net::URLRequestContextGetter>&
293 url_request_context_getter) { 299 url_request_context_getter) {
294 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
295 301
296 gcm_client_ = gcm_client_factory->BuildInstance().Pass(); 302 gcm_client_ = gcm_client_factory->BuildInstance().Pass();
297 303
298 checkin_proto::ChromeBuildProto chrome_build_proto; 304 checkin_proto::ChromeBuildProto chrome_build_proto;
299 chrome_build_proto.set_platform(GetPlatform()); 305 chrome_build_proto.set_platform(GetPlatform());
300 chrome_build_proto.set_chrome_version(GetVersion()); 306 chrome_build_proto.set_chrome_version(GetVersion());
301 chrome_build_proto.set_channel(GetChannel()); 307 chrome_build_proto.set_channel(GetChannel());
302 308
303 scoped_refptr<base::SequencedWorkerPool> worker_pool( 309 scoped_refptr<base::SequencedWorkerPool> worker_pool(
304 content::BrowserThread::GetBlockingPool()); 310 content::BrowserThread::GetBlockingPool());
305 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 311 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
306 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 312 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
307 worker_pool->GetSequenceToken(), 313 worker_pool->GetSequenceToken(),
308 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 314 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
309 315
310 gcm_client_->Initialize(chrome_build_proto, 316 gcm_client_->Initialize(chrome_build_proto,
311 store_path, 317 store_path,
318 account_ids,
312 blocking_task_runner, 319 blocking_task_runner,
313 url_request_context_getter, 320 url_request_context_getter,
314 this); 321 this);
315 322
316 content::BrowserThread::PostTask( 323 content::BrowserThread::PostTask(
317 content::BrowserThread::UI, 324 content::BrowserThread::UI,
318 FROM_HERE, 325 FROM_HERE,
319 base::Bind(&GCMProfileService::FinishInitializationOnUI, 326 base::Bind(&GCMProfileService::FinishInitializationOnUI,
320 service_, 327 service_,
321 gcm_client_->IsReady())); 328 gcm_client_->IsReady()));
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 void GCMProfileService::CheckIn(const std::string& username) { 714 void GCMProfileService::CheckIn(const std::string& username) {
708 DCHECK(!username.empty() && username_.empty()); 715 DCHECK(!username.empty() && username_.empty());
709 username_ = username; 716 username_ = username;
710 717
711 DCHECK(!delayed_task_controller_); 718 DCHECK(!delayed_task_controller_);
712 delayed_task_controller_.reset(new DelayedTaskController); 719 delayed_task_controller_.reset(new DelayedTaskController);
713 720
714 // Load all register apps. 721 // Load all register apps.
715 ReadRegisteredAppIDs(); 722 ReadRegisteredAppIDs();
716 723
724 // Get the list of available accounts.
725 std::vector<std::string> account_ids;
726 #if !defined(OS_ANDROID)
727 account_ids =
728 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts();
729 #endif
730
717 // Let the IO thread create and initialize GCMClient. 731 // Let the IO thread create and initialize GCMClient.
718 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 732 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
719 profile_->GetRequestContext(); 733 profile_->GetRequestContext();
720 content::BrowserThread::PostTask( 734 content::BrowserThread::PostTask(
721 content::BrowserThread::IO, 735 content::BrowserThread::IO,
722 FROM_HERE, 736 FROM_HERE,
723 base::Bind(&GCMProfileService::IOWorker::Initialize, 737 base::Bind(&GCMProfileService::IOWorker::Initialize,
724 io_worker_, 738 io_worker_,
725 gcm_client_factory_.get(), 739 gcm_client_factory_.get(),
726 profile_->GetPath().Append(chrome::kGCMStoreDirname), 740 profile_->GetPath().Append(chrome::kGCMStoreDirname),
741 account_ids,
727 url_request_context_getter)); 742 url_request_context_getter));
728 } 743 }
729 744
730 void GCMProfileService::CheckOut() { 745 void GCMProfileService::CheckOut() {
731 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 746 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
732 747
733 DCHECK(!username_.empty()); 748 DCHECK(!username_.empty());
734 username_.clear(); 749 username_.clear();
735 750
736 // Remove persisted data from app's state store. 751 // Remove persisted data from app's state store.
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1042
1028 return true; 1043 return true;
1029 } 1044 }
1030 1045
1031 // static 1046 // static
1032 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { 1047 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() {
1033 return kRegistrationKey; 1048 return kRegistrationKey;
1034 } 1049 }
1035 1050
1036 } // namespace gcm 1051 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_client_mock.cc ('k') | google_apis/gcm/engine/checkin_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698