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

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

Issue 278493002: Split GCMDriver into platform-specific implementations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybots Created 6 years, 6 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 | Annotate | Revision Log
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 "base/files/file_path.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12
13 #if defined(OS_ANDROID)
14 #include "components/gcm_driver/gcm_driver_android.h"
15 #else
16 #include "base/files/file_path.h"
11 #include "chrome/browser/services/gcm/gcm_utils.h" 17 #include "chrome/browser/services/gcm/gcm_utils.h"
12 #include "chrome/browser/signin/profile_identity_provider.h" 18 #include "chrome/browser/signin/profile_identity_provider.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
15 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/gcm_driver/gcm_client_factory.h" 23 #include "components/gcm_driver/gcm_client_factory.h"
18 #include "components/gcm_driver/gcm_driver.h" 24 #include "components/gcm_driver/gcm_driver_desktop.h"
19 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "components/signin/core/browser/signin_manager.h" 25 #include "components/signin/core/browser/signin_manager.h"
21 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
22 #include "google_apis/gaia/identity_provider.h" 27 #include "google_apis/gaia/identity_provider.h"
23 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
24
25 #if !defined(OS_ANDROID)
26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
27 #endif 29 #endif
28 30
29 namespace gcm { 31 namespace gcm {
30 32
31 // static 33 // static
32 bool GCMProfileService::IsGCMEnabled(Profile* profile) { 34 bool GCMProfileService::IsGCMEnabled(Profile* profile) {
33 return profile->GetPrefs()->GetBoolean(prefs::kGCMChannelEnabled); 35 return profile->GetPrefs()->GetBoolean(prefs::kGCMChannelEnabled);
34 } 36 }
35 37
36 // static 38 // static
37 void GCMProfileService::RegisterProfilePrefs( 39 void GCMProfileService::RegisterProfilePrefs(
38 user_prefs::PrefRegistrySyncable* registry) { 40 user_prefs::PrefRegistrySyncable* registry) {
39 registry->RegisterBooleanPref( 41 registry->RegisterBooleanPref(
40 prefs::kGCMChannelEnabled, 42 prefs::kGCMChannelEnabled,
41 true, 43 true,
42 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 44 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
43 } 45 }
44 46
45 GCMProfileService::GCMProfileService( 47 GCMProfileService::GCMProfileService(
46 Profile* profile, 48 Profile* profile,
47 scoped_ptr<GCMClientFactory> gcm_client_factory) 49 scoped_ptr<GCMClientFactory> gcm_client_factory)
48 : profile_(profile) { 50 : profile_(profile) {
49 DCHECK(!profile->IsOffTheRecord()); 51 DCHECK(!profile->IsOffTheRecord());
50 52
53 #if defined(OS_ANDROID)
54 driver_.reset(new GCMDriverAndroid());
55 #else
56 LoginUIService* login_ui_service =
57 LoginUIServiceFactory::GetForProfile(profile_);
51 scoped_refptr<base::SequencedWorkerPool> worker_pool( 58 scoped_refptr<base::SequencedWorkerPool> worker_pool(
52 content::BrowserThread::GetBlockingPool()); 59 content::BrowserThread::GetBlockingPool());
53 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 60 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
54 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 61 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
55 worker_pool->GetSequenceToken(), 62 worker_pool->GetSequenceToken(),
56 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 63 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
57 64 driver_.reset(new GCMDriverDesktop(
58 #if defined(OS_ANDROID)
59 LoginUIService* login_ui_service = NULL;
60 #else
61 LoginUIService* login_ui_service =
62 LoginUIServiceFactory::GetForProfile(profile_);
63 #endif
64 driver_.reset(new GCMDriver(
65 gcm_client_factory.Pass(), 65 gcm_client_factory.Pass(),
66 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( 66 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider(
67 SigninManagerFactory::GetForProfile(profile_), 67 SigninManagerFactory::GetForProfile(profile_),
68 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), 68 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
69 login_ui_service)), 69 login_ui_service)),
70 GetChromeBuildInfo(), 70 GetChromeBuildInfo(),
71 profile_->GetPath().Append(chrome::kGCMStoreDirname), 71 profile_->GetPath().Append(chrome::kGCMStoreDirname),
72 profile_->GetRequestContext(), 72 profile_->GetRequestContext(),
73 content::BrowserThread::GetMessageLoopProxyForThread( 73 content::BrowserThread::GetMessageLoopProxyForThread(
74 content::BrowserThread::UI), 74 content::BrowserThread::UI),
75 content::BrowserThread::GetMessageLoopProxyForThread( 75 content::BrowserThread::GetMessageLoopProxyForThread(
76 content::BrowserThread::IO), 76 content::BrowserThread::IO),
77 blocking_task_runner)); 77 blocking_task_runner));
78 #endif
78 } 79 }
79 80
80 GCMProfileService::GCMProfileService() : profile_(NULL) { 81 GCMProfileService::GCMProfileService() : profile_(NULL) {
81 } 82 }
82 83
83 GCMProfileService::~GCMProfileService() { 84 GCMProfileService::~GCMProfileService() {
84 } 85 }
85 86
86 void GCMProfileService::AddAppHandler(const std::string& app_id, 87 void GCMProfileService::AddAppHandler(const std::string& app_id,
87 GCMAppHandler* handler) { 88 GCMAppHandler* handler) {
(...skipping 18 matching lines...) Expand all
106 driver_->Shutdown(); 107 driver_->Shutdown();
107 driver_.reset(); 108 driver_.reset();
108 } 109 }
109 } 110 }
110 111
111 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { 112 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) {
112 driver_.reset(driver); 113 driver_.reset(driver);
113 } 114 }
114 115
115 } // namespace gcm 116 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698