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
3 // found in the LICENSE file.
5 #ifndef GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_
6 #define GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "google_apis/gcm/base/gcm_export.h"
16 #include "google_apis/gcm/protocol/android_checkin.pb.h"
17 #include "google_apis/gcm/protocol/checkin.pb.h"
18 #include "net/base/backoff_entry.h"
19 #include "net/url_request/url_fetcher_delegate.h"
23 class URLRequestContextGetter
;
28 class GCMStatsRecorder
;
30 // Enables making check-in requests with the GCM infrastructure. When called
31 // with android_id and security_token both set to 0 it is an initial check-in
32 // used to obtain credentials. These should be persisted and used for subsequent
34 class GCM_EXPORT CheckinRequest
: public net::URLFetcherDelegate
{
36 // A callback function for the checkin request, accepting |checkin_response|
38 typedef base::Callback
<void(const checkin_proto::AndroidCheckinResponse
&
39 checkin_response
)> CheckinRequestCallback
;
41 // Checkin request details.
42 struct GCM_EXPORT RequestInfo
{
43 RequestInfo(uint64 android_id
,
44 uint64 security_token
,
45 const std::string
& settings_digest
,
46 const std::vector
<std::string
>& account_ids
,
47 const checkin_proto::ChromeBuildProto
& chrome_build_proto
);
50 // Android ID of the device.
52 // Security token of the device.
53 uint64 security_token
;
54 // Digest of GServices settings on the device.
55 std::string settings_digest
;
56 // Account IDs of GAIA accounts related to this device.
57 std::vector
<std::string
> account_ids
;
58 // Information of the Chrome build of this device.
59 checkin_proto::ChromeBuildProto chrome_build_proto
;
62 CheckinRequest(const GURL
& checkin_url
,
63 const RequestInfo
& request_info
,
64 const net::BackoffEntry::Policy
& backoff_policy
,
65 const CheckinRequestCallback
& callback
,
66 net::URLRequestContextGetter
* request_context_getter
,
67 GCMStatsRecorder
* recorder
);
68 virtual ~CheckinRequest();
72 // URLFetcherDelegate implementation.
73 virtual void OnURLFetchComplete(const net::URLFetcher
* source
) OVERRIDE
;
76 // Schedules a retry attempt, informs the backoff of a previous request's
77 // failure when |update_backoff| is true.
78 void RetryWithBackoff(bool update_backoff
);
80 net::URLRequestContextGetter
* request_context_getter_
;
81 CheckinRequestCallback callback_
;
83 net::BackoffEntry backoff_entry_
;
85 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
86 const RequestInfo request_info_
;
87 base::TimeTicks request_start_time_
;
89 // Recorder that records GCM activities for debugging purpose. Not owned.
90 GCMStatsRecorder
* recorder_
;
92 base::WeakPtrFactory
<CheckinRequest
> weak_ptr_factory_
;
94 DISALLOW_COPY_AND_ASSIGN(CheckinRequest
);
99 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_