[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / google_apis / gcm / engine / checkin_request.h
blob9253aacf4fbf69e7c519eefca95bd1c1c98d494e
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 <string>
9 #include <vector>
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"
20 #include "url/gurl.h"
22 namespace net {
23 class URLRequestContextGetter;
26 namespace gcm {
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
33 // check-ins.
34 class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate {
35 public:
36 // A callback function for the checkin request, accepting |checkin_response|
37 // protobuf.
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);
48 ~RequestInfo();
50 // Android ID of the device.
51 uint64 android_id;
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();
70 void Start();
72 // URLFetcherDelegate implementation.
73 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
75 private:
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_;
84 GURL checkin_url_;
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);
97 } // namespace gcm
99 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_