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

Side by Side Diff: components/gcm_driver/fake_gcm_client.cc

Issue 848503002: [GCM] Remove GCMDriver::Purge and GCMClient::CheckOut (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « components/gcm_driver/fake_gcm_client.h ('k') | components/gcm_driver/fake_gcm_driver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/gcm_driver/fake_gcm_client.h" 5 #include "components/gcm_driver/fake_gcm_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/sys_byteorder.h" 12 #include "base/sys_byteorder.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "google_apis/gcm/base/encryptor.h" 15 #include "google_apis/gcm/base/encryptor.h"
16 #include "google_apis/gcm/engine/account_mapping.h" 16 #include "google_apis/gcm/engine/account_mapping.h"
17 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 18
19 namespace gcm { 19 namespace gcm {
20 20
21 FakeGCMClient::FakeGCMClient( 21 FakeGCMClient::FakeGCMClient(
22 StartMode start_mode, 22 StartMode start_mode,
23 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 23 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
24 const scoped_refptr<base::SequencedTaskRunner>& io_thread) 24 const scoped_refptr<base::SequencedTaskRunner>& io_thread)
25 : delegate_(NULL), 25 : delegate_(NULL),
26 sequence_id_(0), 26 sequence_id_(0),
27 status_(UNINITIALIZED), 27 started_(false),
28 start_mode_(start_mode), 28 start_mode_(start_mode),
29 ui_thread_(ui_thread), 29 ui_thread_(ui_thread),
30 io_thread_(io_thread), 30 io_thread_(io_thread),
31 weak_ptr_factory_(this) { 31 weak_ptr_factory_(this) {
32 } 32 }
33 33
34 FakeGCMClient::~FakeGCMClient() { 34 FakeGCMClient::~FakeGCMClient() {
35 } 35 }
36 36
37 void FakeGCMClient::Initialize( 37 void FakeGCMClient::Initialize(
38 const ChromeBuildInfo& chrome_build_info, 38 const ChromeBuildInfo& chrome_build_info,
39 const base::FilePath& store_path, 39 const base::FilePath& store_path,
40 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 40 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
41 const scoped_refptr<net::URLRequestContextGetter>& 41 const scoped_refptr<net::URLRequestContextGetter>&
42 url_request_context_getter, 42 url_request_context_getter,
43 scoped_ptr<Encryptor> encryptor, 43 scoped_ptr<Encryptor> encryptor,
44 Delegate* delegate) { 44 Delegate* delegate) {
45 delegate_ = delegate; 45 delegate_ = delegate;
46 } 46 }
47 47
48 void FakeGCMClient::Start() { 48 void FakeGCMClient::Start() {
49 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 49 DCHECK(io_thread_->RunsTasksOnCurrentThread());
50 DCHECK_NE(STARTED, status_); 50 DCHECK(!started_);
51 51
52 if (start_mode_ == DELAY_START) 52 if (start_mode_ == DELAY_START)
53 return; 53 return;
54 DoLoading(); 54 DoLoading();
55 } 55 }
56 56
57 void FakeGCMClient::DoLoading() { 57 void FakeGCMClient::DoLoading() {
58 status_ = STARTED; 58 started_ = true;
59 base::MessageLoop::current()->PostTask( 59 base::MessageLoop::current()->PostTask(
60 FROM_HERE, 60 FROM_HERE,
61 base::Bind(&FakeGCMClient::CheckinFinished, 61 base::Bind(&FakeGCMClient::CheckinFinished,
62 weak_ptr_factory_.GetWeakPtr())); 62 weak_ptr_factory_.GetWeakPtr()));
63 } 63 }
64 64
65 void FakeGCMClient::Stop() { 65 void FakeGCMClient::Stop() {
66 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 66 DCHECK(io_thread_->RunsTasksOnCurrentThread());
67 status_ = STOPPED; 67 started_ = false;
68 delegate_->OnDisconnected(); 68 delegate_->OnDisconnected();
69 } 69 }
70 70
71 void FakeGCMClient::CheckOut() {
72 DCHECK(io_thread_->RunsTasksOnCurrentThread());
73 status_ = CHECKED_OUT;
74 sequence_id_++;
75 }
76
77 void FakeGCMClient::Register(const std::string& app_id, 71 void FakeGCMClient::Register(const std::string& app_id,
78 const std::vector<std::string>& sender_ids) { 72 const std::vector<std::string>& sender_ids) {
79 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 73 DCHECK(io_thread_->RunsTasksOnCurrentThread());
80 74
81 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids); 75 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids);
82 base::MessageLoop::current()->PostTask( 76 base::MessageLoop::current()->PostTask(
83 FROM_HERE, 77 FROM_HERE,
84 base::Bind(&FakeGCMClient::RegisterFinished, 78 base::Bind(&FakeGCMClient::RegisterFinished,
85 weak_ptr_factory_.GetWeakPtr(), 79 weak_ptr_factory_.GetWeakPtr(),
86 app_id, 80 app_id,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 delegate_->OnMessageSendError(app_id, send_error_details); 245 delegate_->OnMessageSendError(app_id, send_error_details);
252 } 246 }
253 247
254 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, 248 void FakeGCMClient::SendAcknowledgement(const std::string& app_id,
255 const std::string& message_id) { 249 const std::string& message_id) {
256 if (delegate_) 250 if (delegate_)
257 delegate_->OnSendAcknowledged(app_id, message_id); 251 delegate_->OnSendAcknowledged(app_id, message_id);
258 } 252 }
259 253
260 } // namespace gcm 254 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/fake_gcm_client.h ('k') | components/gcm_driver/fake_gcm_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698