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

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

Issue 293053014: Retrieve chrome build info in GCMProfileService, instead of GCMDriver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_driver.h" 5 #include "chrome/browser/services/gcm/gcm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
17 #include "components/gcm_driver/gcm_app_handler.h" 17 #include "components/gcm_driver/gcm_app_handler.h"
18 #include "components/gcm_driver/gcm_client_factory.h" 18 #include "components/gcm_driver/gcm_client_factory.h"
19 #include "components/gcm_driver/system_encryptor.h" 19 #include "components/gcm_driver/system_encryptor.h"
20 #include "google_apis/gaia/oauth2_token_service.h" 20 #include "google_apis/gaia/oauth2_token_service.h"
21 #include "google_apis/gcm/protocol/android_checkin.pb.h"
22 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
23 22
24 namespace gcm { 23 namespace gcm {
25 24
26 namespace {
27
28 checkin_proto::ChromeBuildProto_Platform GetPlatform() {
29 #if defined(OS_WIN)
30 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN;
31 #elif defined(OS_MACOSX)
32 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC;
33 #elif defined(OS_IOS)
34 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS;
35 #elif defined(OS_CHROMEOS)
36 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS;
37 #elif defined(OS_LINUX)
38 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
39 #else
40 // For all other platforms, return as LINUX.
41 return checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
42 #endif
43 }
44
45 std::string GetVersion() {
46 chrome::VersionInfo version_info;
47 return version_info.Version();
48 }
49
50 checkin_proto::ChromeBuildProto_Channel GetChannel() {
51 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
52 switch (channel) {
53 case chrome::VersionInfo::CHANNEL_UNKNOWN:
54 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
55 case chrome::VersionInfo::CHANNEL_CANARY:
56 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY;
57 case chrome::VersionInfo::CHANNEL_DEV:
58 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV;
59 case chrome::VersionInfo::CHANNEL_BETA:
60 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA;
61 case chrome::VersionInfo::CHANNEL_STABLE:
62 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE;
63 default:
64 NOTREACHED();
65 return checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
66 }
67 }
68
69 } // namespace
70
71 // Helper class to save tasks to run until we're ready to execute them. 25 // Helper class to save tasks to run until we're ready to execute them.
72 class GCMDriver::DelayedTaskController { 26 class GCMDriver::DelayedTaskController {
73 public: 27 public:
74 DelayedTaskController(); 28 DelayedTaskController();
75 ~DelayedTaskController(); 29 ~DelayedTaskController();
76 30
77 // Adds a task that will be invoked once we're ready. 31 // Adds a task that will be invoked once we're ready.
78 void AddTask(const base::Closure& task); 32 void AddTask(const base::Closure& task);
79 33
80 // Sets ready status. It is ready only when check-in is completed and 34 // Sets ready status. It is ready only when check-in is completed and
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; 99 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
146 virtual void OnMessageSendError( 100 virtual void OnMessageSendError(
147 const std::string& app_id, 101 const std::string& app_id,
148 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; 102 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
149 virtual void OnGCMReady() OVERRIDE; 103 virtual void OnGCMReady() OVERRIDE;
150 virtual void OnActivityRecorded() OVERRIDE; 104 virtual void OnActivityRecorded() OVERRIDE;
151 105
152 // Called on IO thread. 106 // Called on IO thread.
153 void Initialize( 107 void Initialize(
154 scoped_ptr<GCMClientFactory> gcm_client_factory, 108 scoped_ptr<GCMClientFactory> gcm_client_factory,
109 const GCMClient::ChromeBuildInfo& chrome_build_info,
155 const base::FilePath& store_path, 110 const base::FilePath& store_path,
156 const std::vector<std::string>& account_ids, 111 const std::vector<std::string>& account_ids,
157 const scoped_refptr<net::URLRequestContextGetter>& request_context, 112 const scoped_refptr<net::URLRequestContextGetter>& request_context,
158 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); 113 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
159 void Start(const base::WeakPtr<GCMDriver>& service); 114 void Start(const base::WeakPtr<GCMDriver>& service);
160 void Stop(); 115 void Stop();
161 void CheckOut(); 116 void CheckOut();
162 void Register(const std::string& app_id, 117 void Register(const std::string& app_id,
163 const std::vector<std::string>& sender_ids); 118 const std::vector<std::string>& sender_ids);
164 void Unregister(const std::string& app_id); 119 void Unregister(const std::string& app_id);
(...skipping 24 matching lines...) Expand all
189 io_thread_(io_thread) { 144 io_thread_(io_thread) {
190 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 145 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
191 } 146 }
192 147
193 GCMDriver::IOWorker::~IOWorker() { 148 GCMDriver::IOWorker::~IOWorker() {
194 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 149 DCHECK(io_thread_->RunsTasksOnCurrentThread());
195 } 150 }
196 151
197 void GCMDriver::IOWorker::Initialize( 152 void GCMDriver::IOWorker::Initialize(
198 scoped_ptr<GCMClientFactory> gcm_client_factory, 153 scoped_ptr<GCMClientFactory> gcm_client_factory,
154 const GCMClient::ChromeBuildInfo& chrome_build_info,
199 const base::FilePath& store_path, 155 const base::FilePath& store_path,
200 const std::vector<std::string>& account_ids, 156 const std::vector<std::string>& account_ids,
201 const scoped_refptr<net::URLRequestContextGetter>& request_context, 157 const scoped_refptr<net::URLRequestContextGetter>& request_context,
202 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) { 158 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
203 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 159 DCHECK(io_thread_->RunsTasksOnCurrentThread());
204 160
205 gcm_client_ = gcm_client_factory->BuildInstance(); 161 gcm_client_ = gcm_client_factory->BuildInstance();
206 162
207 checkin_proto::ChromeBuildProto chrome_build_proto; 163 gcm_client_->Initialize(chrome_build_info,
208 chrome_build_proto.set_platform(GetPlatform());
209 chrome_build_proto.set_chrome_version(GetVersion());
210 chrome_build_proto.set_channel(GetChannel());
211
212 gcm_client_->Initialize(chrome_build_proto,
213 store_path, 164 store_path,
214 account_ids, 165 account_ids,
215 blocking_task_runner, 166 blocking_task_runner,
216 request_context, 167 request_context,
217 make_scoped_ptr<Encryptor>(new SystemEncryptor), 168 make_scoped_ptr<Encryptor>(new SystemEncryptor),
218 this); 169 this);
219 } 170 }
220 171
221 void GCMDriver::IOWorker::OnRegisterFinished( 172 void GCMDriver::IOWorker::OnRegisterFinished(
222 const std::string& app_id, 173 const std::string& app_id,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 313 }
363 314
364 ui_thread_->PostTask( 315 ui_thread_->PostTask(
365 FROM_HERE, 316 FROM_HERE,
366 base::Bind(&GCMDriver::GetGCMStatisticsFinished, service_, stats)); 317 base::Bind(&GCMDriver::GetGCMStatisticsFinished, service_, stats));
367 } 318 }
368 319
369 GCMDriver::GCMDriver( 320 GCMDriver::GCMDriver(
370 scoped_ptr<GCMClientFactory> gcm_client_factory, 321 scoped_ptr<GCMClientFactory> gcm_client_factory,
371 scoped_ptr<IdentityProvider> identity_provider, 322 scoped_ptr<IdentityProvider> identity_provider,
323 const GCMClient::ChromeBuildInfo& chrome_build_info,
372 const base::FilePath& store_path, 324 const base::FilePath& store_path,
373 const scoped_refptr<net::URLRequestContextGetter>& request_context, 325 const scoped_refptr<net::URLRequestContextGetter>& request_context,
374 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 326 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
375 const scoped_refptr<base::SequencedTaskRunner>& io_thread, 327 const scoped_refptr<base::SequencedTaskRunner>& io_thread,
376 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) 328 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
377 : gcm_enabled_(true), 329 : gcm_enabled_(true),
378 gcm_client_ready_(false), 330 gcm_client_ready_(false),
379 identity_provider_(identity_provider.Pass()), 331 identity_provider_(identity_provider.Pass()),
380 ui_thread_(ui_thread), 332 ui_thread_(ui_thread),
381 io_thread_(io_thread), 333 io_thread_(io_thread),
382 weak_ptr_factory_(this) { 334 weak_ptr_factory_(this) {
383 // Get the list of available accounts. 335 // Get the list of available accounts.
384 std::vector<std::string> account_ids; 336 std::vector<std::string> account_ids;
385 #if !defined(OS_ANDROID) 337 #if !defined(OS_ANDROID)
386 account_ids = identity_provider_->GetTokenService()->GetAccounts(); 338 account_ids = identity_provider_->GetTokenService()->GetAccounts();
387 #endif 339 #endif
388 340
389 // Create and initialize the GCMClient. Note that this does not initiate the 341 // Create and initialize the GCMClient. Note that this does not initiate the
390 // GCM check-in. 342 // GCM check-in.
391 io_worker_.reset(new IOWorker(ui_thread, io_thread)); 343 io_worker_.reset(new IOWorker(ui_thread, io_thread));
392 io_thread_->PostTask( 344 io_thread_->PostTask(
393 FROM_HERE, 345 FROM_HERE,
394 base::Bind(&GCMDriver::IOWorker::Initialize, 346 base::Bind(&GCMDriver::IOWorker::Initialize,
395 base::Unretained(io_worker_.get()), 347 base::Unretained(io_worker_.get()),
396 base::Passed(&gcm_client_factory), 348 base::Passed(&gcm_client_factory),
349 chrome_build_info,
397 store_path, 350 store_path,
398 account_ids, 351 account_ids,
399 request_context, 352 request_context,
400 blocking_task_runner)); 353 blocking_task_runner));
401 354
402 identity_provider_->AddObserver(this); 355 identity_provider_->AddObserver(this);
403 } 356 }
404 357
405 GCMDriver::GCMDriver() 358 GCMDriver::GCMDriver()
406 : gcm_enabled_(true), 359 : gcm_enabled_(true),
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 804 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
852 } 805 }
853 806
854 std::string GCMDriver::SignedInUserName() const { 807 std::string GCMDriver::SignedInUserName() const {
855 if (IsStarted()) 808 if (IsStarted())
856 return identity_provider_->GetActiveUsername(); 809 return identity_provider_->GetActiveUsername();
857 return std::string(); 810 return std::string();
858 } 811 }
859 812
860 } // namespace gcm 813 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_driver.h ('k') | chrome/browser/services/gcm/gcm_driver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698