Add a link to crbug.com/512301 to TODO in media_permission.cc regarding pepper media...
[chromium-blink-merge.git] / google_apis / gcm / engine / checkin_request.h
blob619a8f94458fcb3be83fd79365a1ddaa96a1974d
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>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "google_apis/gcm/base/gcm_export.h"
15 #include "google_apis/gcm/protocol/android_checkin.pb.h"
16 #include "google_apis/gcm/protocol/checkin.pb.h"
17 #include "net/base/backoff_entry.h"
18 #include "net/url_request/url_fetcher_delegate.h"
19 #include "url/gurl.h"
21 namespace net {
22 class URLRequestContextGetter;
25 namespace gcm {
27 class GCMStatsRecorder;
29 // Enables making check-in requests with the GCM infrastructure. When called
30 // with android_id and security_token both set to 0 it is an initial check-in
31 // used to obtain credentials. These should be persisted and used for subsequent
32 // check-ins.
33 class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate {
34 public:
35 // A callback function for the checkin request, accepting |checkin_response|
36 // protobuf.
37 typedef base::Callback<void(const checkin_proto::AndroidCheckinResponse&
38 checkin_response)> CheckinRequestCallback;
40 // Checkin request details.
41 struct GCM_EXPORT RequestInfo {
42 RequestInfo(uint64 android_id,
43 uint64 security_token,
44 const std::map<std::string, std::string>& account_tokens,
45 const std::string& settings_digest,
46 const checkin_proto::ChromeBuildProto& chrome_build_proto);
47 ~RequestInfo();
49 // Android ID of the device.
50 uint64 android_id;
51 // Security token of the device.
52 uint64 security_token;
53 // Map of account OAuth2 tokens keyed by emails.
54 std::map<std::string, std::string> account_tokens;
55 // Digest of GServices settings on the device.
56 std::string settings_digest;
57 // Information of the Chrome build of this device.
58 checkin_proto::ChromeBuildProto chrome_build_proto;
61 CheckinRequest(const GURL& checkin_url,
62 const RequestInfo& request_info,
63 const net::BackoffEntry::Policy& backoff_policy,
64 const CheckinRequestCallback& callback,
65 net::URLRequestContextGetter* request_context_getter,
66 GCMStatsRecorder* recorder);
67 ~CheckinRequest() override;
69 void Start();
71 // URLFetcherDelegate implementation.
72 void OnURLFetchComplete(const net::URLFetcher* source) override;
74 private:
75 // Schedules a retry attempt with a backoff.
76 void RetryWithBackoff();
78 net::URLRequestContextGetter* request_context_getter_;
79 CheckinRequestCallback callback_;
81 net::BackoffEntry backoff_entry_;
82 GURL checkin_url_;
83 scoped_ptr<net::URLFetcher> url_fetcher_;
84 const RequestInfo request_info_;
85 base::TimeTicks request_start_time_;
87 // Recorder that records GCM activities for debugging purpose. Not owned.
88 GCMStatsRecorder* recorder_;
90 base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_;
92 DISALLOW_COPY_AND_ASSIGN(CheckinRequest);
95 } // namespace gcm
97 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_