OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "google_apis/gcm/gcm_client_impl.h" | 5 #include "google_apis/gcm/gcm_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/time/default_clock.h" | 14 #include "base/time/clock.h" |
15 #include "google_apis/gcm/base/mcs_message.h" | 15 #include "google_apis/gcm/base/mcs_message.h" |
16 #include "google_apis/gcm/base/mcs_util.h" | 16 #include "google_apis/gcm/base/mcs_util.h" |
17 #include "google_apis/gcm/engine/checkin_request.h" | 17 #include "google_apis/gcm/engine/checkin_request.h" |
18 #include "google_apis/gcm/engine/connection_factory_impl.h" | 18 #include "google_apis/gcm/engine/connection_factory.h" |
19 #include "google_apis/gcm/engine/gcm_store_impl.h" | |
20 #include "google_apis/gcm/engine/mcs_client.h" | 19 #include "google_apis/gcm/engine/mcs_client.h" |
21 #include "google_apis/gcm/protocol/mcs.pb.h" | 20 #include "google_apis/gcm/protocol/mcs.pb.h" |
22 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
23 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 namespace gcm { | 25 namespace gcm { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return DELETED_MESSAGES; | 110 return DELETED_MESSAGES; |
112 if (kMessageTypeSendErrorKey == value) | 111 if (kMessageTypeSendErrorKey == value) |
113 return SEND_ERROR; | 112 return SEND_ERROR; |
114 if (kMessageTypeDataMessage == value) | 113 if (kMessageTypeDataMessage == value) |
115 return DATA_MESSAGE; | 114 return DATA_MESSAGE; |
116 return UNKNOWN; | 115 return UNKNOWN; |
117 } | 116 } |
118 | 117 |
119 } // namespace | 118 } // namespace |
120 | 119 |
121 GCMInternalsBuilder::GCMInternalsBuilder() {} | |
122 GCMInternalsBuilder::~GCMInternalsBuilder() {} | |
123 | |
124 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { | |
125 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); | |
126 } | |
127 | |
128 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( | |
129 const std::string& version, | |
130 base::Clock* clock, | |
131 ConnectionFactory* connection_factory, | |
132 GCMStore* gcm_store) { | |
133 return make_scoped_ptr<MCSClient>( | |
134 new MCSClient(version, | |
135 clock, | |
136 connection_factory, | |
137 gcm_store)); | |
138 } | |
139 | |
140 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( | |
141 const std::vector<GURL>& endpoints, | |
142 const net::BackoffEntry::Policy& backoff_policy, | |
143 scoped_refptr<net::HttpNetworkSession> network_session, | |
144 net::NetLog* net_log) { | |
145 return make_scoped_ptr<ConnectionFactory>( | |
146 new ConnectionFactoryImpl(endpoints, | |
147 backoff_policy, | |
148 network_session, | |
149 net_log)); | |
150 } | |
151 | |
152 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) | 120 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) |
153 : internals_builder_(internals_builder.Pass()), | 121 : internals_builder_(internals_builder.Pass()), |
154 state_(UNINITIALIZED), | 122 state_(UNINITIALIZED), |
155 clock_(internals_builder_->BuildClock()), | 123 clock_(internals_builder_->BuildClock()), |
156 url_request_context_getter_(NULL), | 124 url_request_context_getter_(NULL), |
157 pending_registration_requests_deleter_(&pending_registration_requests_), | 125 pending_registration_requests_deleter_(&pending_registration_requests_), |
158 pending_unregistration_requests_deleter_( | 126 pending_unregistration_requests_deleter_( |
159 &pending_unregistration_requests_), | 127 &pending_unregistration_requests_), |
160 weak_ptr_factory_(this) { | 128 weak_ptr_factory_(this) { |
161 } | 129 } |
(...skipping 16 matching lines...) Expand all Loading... |
178 url_request_context_getter_ = url_request_context_getter; | 146 url_request_context_getter_ = url_request_context_getter; |
179 const net::HttpNetworkSession::Params* network_session_params = | 147 const net::HttpNetworkSession::Params* network_session_params = |
180 url_request_context_getter_->GetURLRequestContext()-> | 148 url_request_context_getter_->GetURLRequestContext()-> |
181 GetNetworkSessionParams(); | 149 GetNetworkSessionParams(); |
182 DCHECK(network_session_params); | 150 DCHECK(network_session_params); |
183 network_session_ = new net::HttpNetworkSession(*network_session_params); | 151 network_session_ = new net::HttpNetworkSession(*network_session_params); |
184 | 152 |
185 chrome_build_proto_.CopyFrom(chrome_build_proto); | 153 chrome_build_proto_.CopyFrom(chrome_build_proto); |
186 account_ids_ = account_ids; | 154 account_ids_ = account_ids; |
187 | 155 |
188 gcm_store_.reset(new GCMStoreImpl(false, path, blocking_task_runner)); | 156 gcm_store_ = |
| 157 internals_builder_->BuildGCMStore(path, blocking_task_runner).Pass(); |
189 | 158 |
190 delegate_ = delegate; | 159 delegate_ = delegate; |
191 | 160 |
192 state_ = INITIALIZED; | 161 state_ = INITIALIZED; |
193 } | 162 } |
194 | 163 |
195 void GCMClientImpl::Load() { | 164 void GCMClientImpl::Load() { |
196 DCHECK_EQ(INITIALIZED, state_); | 165 DCHECK_EQ(INITIALIZED, state_); |
197 | 166 |
198 // Once the loading is completed, the check-in will be initiated. | 167 // Once the loading is completed, the check-in will be initiated. |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 if (iter != send_error_details.additional_data.end()) { | 657 if (iter != send_error_details.additional_data.end()) { |
689 send_error_details.message_id = iter->second; | 658 send_error_details.message_id = iter->second; |
690 send_error_details.additional_data.erase(iter); | 659 send_error_details.additional_data.erase(iter); |
691 } | 660 } |
692 | 661 |
693 delegate_->OnMessageSendError(data_message_stanza.category(), | 662 delegate_->OnMessageSendError(data_message_stanza.category(), |
694 send_error_details); | 663 send_error_details); |
695 } | 664 } |
696 | 665 |
697 } // namespace gcm | 666 } // namespace gcm |
OLD | NEW |