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

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

Issue 292813007: Remove dependency on content::BrowserThread from GCMDriver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use SequencedTaskRunner 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/fake_gcm_client.h" 5 #include "chrome/browser/services/gcm/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/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "google_apis/gcm/base/encryptor.h" 13 #include "google_apis/gcm/base/encryptor.h"
14 14
15 namespace gcm { 15 namespace gcm {
16 16
17 FakeGCMClient::FakeGCMClient(StartMode start_mode) 17 FakeGCMClient::FakeGCMClient(
18 StartMode start_mode,
19 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
20 const scoped_refptr<base::SequencedTaskRunner>& io_thread)
18 : delegate_(NULL), 21 : delegate_(NULL),
19 status_(UNINITIALIZED), 22 status_(UNINITIALIZED),
20 start_mode_(start_mode), 23 start_mode_(start_mode),
24 ui_thread_(ui_thread),
25 io_thread_(io_thread),
21 weak_ptr_factory_(this) { 26 weak_ptr_factory_(this) {
22 } 27 }
23 28
24 FakeGCMClient::~FakeGCMClient() { 29 FakeGCMClient::~FakeGCMClient() {
25 } 30 }
26 31
27 void FakeGCMClient::Initialize( 32 void FakeGCMClient::Initialize(
28 const checkin_proto::ChromeBuildProto& chrome_build_proto, 33 const checkin_proto::ChromeBuildProto& chrome_build_proto,
29 const base::FilePath& store_path, 34 const base::FilePath& store_path,
30 const std::vector<std::string>& account_ids, 35 const std::vector<std::string>& account_ids,
31 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 36 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
32 const scoped_refptr<net::URLRequestContextGetter>& 37 const scoped_refptr<net::URLRequestContextGetter>&
33 url_request_context_getter, 38 url_request_context_getter,
34 scoped_ptr<Encryptor> encryptor, 39 scoped_ptr<Encryptor> encryptor,
35 Delegate* delegate) { 40 Delegate* delegate) {
36 delegate_ = delegate; 41 delegate_ = delegate;
37 } 42 }
38 43
39 void FakeGCMClient::Start() { 44 void FakeGCMClient::Start() {
40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 45 DCHECK(io_thread_->RunsTasksOnCurrentThread());
41 DCHECK_NE(STARTED, status_); 46 DCHECK_NE(STARTED, status_);
42 47
43 if (start_mode_ == DELAY_START) 48 if (start_mode_ == DELAY_START)
44 return; 49 return;
45 DoLoading(); 50 DoLoading();
46 } 51 }
47 52
48 void FakeGCMClient::DoLoading() { 53 void FakeGCMClient::DoLoading() {
49 status_ = STARTED; 54 status_ = STARTED;
50 base::MessageLoop::current()->PostTask( 55 base::MessageLoop::current()->PostTask(
51 FROM_HERE, 56 FROM_HERE,
52 base::Bind(&FakeGCMClient::CheckinFinished, 57 base::Bind(&FakeGCMClient::CheckinFinished,
53 weak_ptr_factory_.GetWeakPtr())); 58 weak_ptr_factory_.GetWeakPtr()));
54 } 59 }
55 60
56 void FakeGCMClient::Stop() { 61 void FakeGCMClient::Stop() {
57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 62 DCHECK(io_thread_->RunsTasksOnCurrentThread());
58 status_ = STOPPED; 63 status_ = STOPPED;
59 } 64 }
60 65
61 void FakeGCMClient::CheckOut() { 66 void FakeGCMClient::CheckOut() {
62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 67 DCHECK(io_thread_->RunsTasksOnCurrentThread());
63 status_ = CHECKED_OUT; 68 status_ = CHECKED_OUT;
64 } 69 }
65 70
66 void FakeGCMClient::Register(const std::string& app_id, 71 void FakeGCMClient::Register(const std::string& app_id,
67 const std::vector<std::string>& sender_ids) { 72 const std::vector<std::string>& sender_ids) {
68 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 73 DCHECK(io_thread_->RunsTasksOnCurrentThread());
69 74
70 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids); 75 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids);
71 base::MessageLoop::current()->PostTask( 76 base::MessageLoop::current()->PostTask(
72 FROM_HERE, 77 FROM_HERE,
73 base::Bind(&FakeGCMClient::RegisterFinished, 78 base::Bind(&FakeGCMClient::RegisterFinished,
74 weak_ptr_factory_.GetWeakPtr(), 79 weak_ptr_factory_.GetWeakPtr(),
75 app_id, 80 app_id,
76 registration_id)); 81 registration_id));
77 } 82 }
78 83
79 void FakeGCMClient::Unregister(const std::string& app_id) { 84 void FakeGCMClient::Unregister(const std::string& app_id) {
80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 85 DCHECK(io_thread_->RunsTasksOnCurrentThread());
81 86
82 base::MessageLoop::current()->PostTask( 87 base::MessageLoop::current()->PostTask(
83 FROM_HERE, 88 FROM_HERE,
84 base::Bind(&FakeGCMClient::UnregisterFinished, 89 base::Bind(&FakeGCMClient::UnregisterFinished,
85 weak_ptr_factory_.GetWeakPtr(), 90 weak_ptr_factory_.GetWeakPtr(),
86 app_id)); 91 app_id));
87 } 92 }
88 93
89 void FakeGCMClient::Send(const std::string& app_id, 94 void FakeGCMClient::Send(const std::string& app_id,
90 const std::string& receiver_id, 95 const std::string& receiver_id,
91 const OutgoingMessage& message) { 96 const OutgoingMessage& message) {
92 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 97 DCHECK(io_thread_->RunsTasksOnCurrentThread());
93 98
94 base::MessageLoop::current()->PostTask( 99 base::MessageLoop::current()->PostTask(
95 FROM_HERE, 100 FROM_HERE,
96 base::Bind(&FakeGCMClient::SendFinished, 101 base::Bind(&FakeGCMClient::SendFinished,
97 weak_ptr_factory_.GetWeakPtr(), 102 weak_ptr_factory_.GetWeakPtr(),
98 app_id, 103 app_id,
99 message)); 104 message));
100 } 105 }
101 106
102 void FakeGCMClient::SetRecording(bool recording) { 107 void FakeGCMClient::SetRecording(bool recording) {
103 } 108 }
104 109
105 void FakeGCMClient::ClearActivityLogs() { 110 void FakeGCMClient::ClearActivityLogs() {
106 } 111 }
107 112
108 GCMClient::GCMStatistics FakeGCMClient::GetStatistics() const { 113 GCMClient::GCMStatistics FakeGCMClient::GetStatistics() const {
109 return GCMClient::GCMStatistics(); 114 return GCMClient::GCMStatistics();
110 } 115 }
111 116
112 void FakeGCMClient::PerformDelayedLoading() { 117 void FakeGCMClient::PerformDelayedLoading() {
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 118 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
114 119
115 content::BrowserThread::PostTask( 120 io_thread_->PostTask(
116 content::BrowserThread::IO,
117 FROM_HERE, 121 FROM_HERE,
118 base::Bind(&FakeGCMClient::DoLoading, weak_ptr_factory_.GetWeakPtr())); 122 base::Bind(&FakeGCMClient::DoLoading, weak_ptr_factory_.GetWeakPtr()));
119 } 123 }
120 124
121 void FakeGCMClient::ReceiveMessage(const std::string& app_id, 125 void FakeGCMClient::ReceiveMessage(const std::string& app_id,
122 const IncomingMessage& message) { 126 const IncomingMessage& message) {
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 127 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
124 128
125 content::BrowserThread::PostTask( 129 io_thread_->PostTask(
126 content::BrowserThread::IO,
127 FROM_HERE, 130 FROM_HERE,
128 base::Bind(&FakeGCMClient::MessageReceived, 131 base::Bind(&FakeGCMClient::MessageReceived,
129 weak_ptr_factory_.GetWeakPtr(), 132 weak_ptr_factory_.GetWeakPtr(),
130 app_id, 133 app_id,
131 message)); 134 message));
132 } 135 }
133 136
134 void FakeGCMClient::DeleteMessages(const std::string& app_id) { 137 void FakeGCMClient::DeleteMessages(const std::string& app_id) {
135 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 138 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
136 139
137 content::BrowserThread::PostTask( 140 io_thread_->PostTask(
138 content::BrowserThread::IO,
139 FROM_HERE, 141 FROM_HERE,
140 base::Bind(&FakeGCMClient::MessagesDeleted, 142 base::Bind(&FakeGCMClient::MessagesDeleted,
141 weak_ptr_factory_.GetWeakPtr(), 143 weak_ptr_factory_.GetWeakPtr(),
142 app_id)); 144 app_id));
143 } 145 }
144 146
145 // static 147 // static
146 std::string FakeGCMClient::GetRegistrationIdFromSenderIds( 148 std::string FakeGCMClient::GetRegistrationIdFromSenderIds(
147 const std::vector<std::string>& sender_ids) { 149 const std::vector<std::string>& sender_ids) {
148 // GCMService normalizes the sender IDs by making them sorted. 150 // GCMService normalizes the sender IDs by making them sorted.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 212 }
211 213
212 void FakeGCMClient::MessageSendError( 214 void FakeGCMClient::MessageSendError(
213 const std::string& app_id, 215 const std::string& app_id,
214 const GCMClient::SendErrorDetails& send_error_details) { 216 const GCMClient::SendErrorDetails& send_error_details) {
215 if (delegate_) 217 if (delegate_)
216 delegate_->OnMessageSendError(app_id, send_error_details); 218 delegate_->OnMessageSendError(app_id, send_error_details);
217 } 219 }
218 220
219 } // namespace gcm 221 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698