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

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

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

Powered by Google App Engine
This is Rietveld 408576698