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_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "google_apis/gcm/base/gcm_export.h"
12 #include "google_apis/gcm/protocol/android_checkin.pb.h"
13 #include "net/base/backoff_entry.h"
14 #include "net/url_request/url_fetcher_delegate.h"
17 class URLRequestContextGetter;
22 // Enables making check-in requests with the GCM infrastructure. When called
23 // with android_id and security_token both set to 0 it is an initial check-in
24 // used to obtain credentials. These should be persisted and used for subsequent
26 class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate {
28 // A callback function for the checkin request, accepting |android_id| and
30 typedef base::Callback<void(uint64 android_id, uint64 security_token)>
31 CheckinRequestCallback;
33 CheckinRequest(const CheckinRequestCallback& callback,
34 const net::BackoffEntry::Policy& backoff_policy,
35 const checkin_proto::ChromeBuildProto& chrome_build_proto,
37 uint64 security_token,
38 net::URLRequestContextGetter* request_context_getter);
39 virtual ~CheckinRequest();
43 // URLFetcherDelegate implementation.
44 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
47 // Schedules a retry attempt, informs the backoff of a previous request's
48 // failure when |update_backoff| is true.
49 void RetryWithBackoff(bool update_backoff);
51 net::URLRequestContextGetter* request_context_getter_;
52 CheckinRequestCallback callback_;
54 net::BackoffEntry backoff_entry_;
55 scoped_ptr<net::URLFetcher> url_fetcher_;
56 checkin_proto::ChromeBuildProto chrome_build_proto_;
58 uint64 security_token_;
60 base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_;
62 DISALLOW_COPY_AND_ASSIGN(CheckinRequest);
67 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_