OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ |
6 #define GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "google_apis/gcm/base/gcm_export.h" | 14 #include "google_apis/gcm/base/gcm_export.h" |
15 #include "google_apis/gcm/protocol/android_checkin.pb.h" | 15 #include "google_apis/gcm/protocol/checkin.pb.h" |
16 #include "net/base/backoff_entry.h" | 16 #include "net/base/backoff_entry.h" |
17 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
21 } | 21 } |
22 | 22 |
23 namespace gcm { | 23 namespace gcm { |
24 | 24 |
25 // Enables making check-in requests with the GCM infrastructure. When called | 25 // Enables making check-in requests with the GCM infrastructure. When called |
26 // with android_id and security_token both set to 0 it is an initial check-in | 26 // with android_id and security_token both set to 0 it is an initial check-in |
27 // used to obtain credentials. These should be persisted and used for subsequent | 27 // used to obtain credentials. These should be persisted and used for subsequent |
28 // check-ins. | 28 // check-ins. |
29 class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { | 29 class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { |
30 public: | 30 public: |
31 // A callback function for the checkin request, accepting |android_id| and | 31 // A callback function for the checkin request, accepting |checkin_response| |
32 // |security_token|. | 32 // protobuf. |
33 typedef base::Callback<void(uint64 android_id, uint64 security_token)> | 33 typedef base::Callback<void(const checkin_proto::AndroidCheckinResponse& |
34 CheckinRequestCallback; | 34 checkin_response)> CheckinRequestCallback; |
35 | 35 |
36 CheckinRequest(const CheckinRequestCallback& callback, | 36 // Checkin request details. |
| 37 struct GCM_EXPORT RequestInfo { |
| 38 RequestInfo(uint64 android_id, |
| 39 uint64 security_token, |
| 40 const std::string& settings_digest, |
| 41 const std::vector<std::string>& account_ids, |
| 42 const checkin_proto::ChromeBuildProto& chrome_build_proto); |
| 43 ~RequestInfo(); |
| 44 |
| 45 // Android ID of the device. |
| 46 uint64 android_id; |
| 47 // Security token of the device. |
| 48 uint64 security_token; |
| 49 // Digest of GServices settings on the device. |
| 50 std::string settings_digest; |
| 51 // Account IDs of GAIA accounts related to this device. |
| 52 std::vector<std::string> account_ids; |
| 53 // Information of the Chrome build of this device. |
| 54 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 55 }; |
| 56 |
| 57 CheckinRequest(const RequestInfo& request_info, |
37 const net::BackoffEntry::Policy& backoff_policy, | 58 const net::BackoffEntry::Policy& backoff_policy, |
38 const checkin_proto::ChromeBuildProto& chrome_build_proto, | 59 const CheckinRequestCallback& callback, |
39 uint64 android_id, | |
40 uint64 security_token, | |
41 const std::vector<std::string>& account_ids, | |
42 net::URLRequestContextGetter* request_context_getter); | 60 net::URLRequestContextGetter* request_context_getter); |
43 virtual ~CheckinRequest(); | 61 virtual ~CheckinRequest(); |
44 | 62 |
45 void Start(); | 63 void Start(); |
46 | 64 |
47 // URLFetcherDelegate implementation. | 65 // URLFetcherDelegate implementation. |
48 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
49 | 67 |
50 private: | 68 private: |
51 // Schedules a retry attempt, informs the backoff of a previous request's | 69 // Schedules a retry attempt, informs the backoff of a previous request's |
52 // failure when |update_backoff| is true. | 70 // failure when |update_backoff| is true. |
53 void RetryWithBackoff(bool update_backoff); | 71 void RetryWithBackoff(bool update_backoff); |
54 | 72 |
55 net::URLRequestContextGetter* request_context_getter_; | 73 net::URLRequestContextGetter* request_context_getter_; |
56 CheckinRequestCallback callback_; | 74 CheckinRequestCallback callback_; |
57 | 75 |
58 net::BackoffEntry backoff_entry_; | 76 net::BackoffEntry backoff_entry_; |
59 scoped_ptr<net::URLFetcher> url_fetcher_; | 77 scoped_ptr<net::URLFetcher> url_fetcher_; |
60 const checkin_proto::ChromeBuildProto chrome_build_proto_; | 78 const RequestInfo request_info_; |
61 const uint64 android_id_; | |
62 const uint64 security_token_; | |
63 const std::vector<std::string> account_ids_; | |
64 | 79 |
65 base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_; | 80 base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_; |
66 | 81 |
67 DISALLOW_COPY_AND_ASSIGN(CheckinRequest); | 82 DISALLOW_COPY_AND_ASSIGN(CheckinRequest); |
68 }; | 83 }; |
69 | 84 |
70 } // namespace gcm | 85 } // namespace gcm |
71 | 86 |
72 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ | 87 #endif // GOOGLE_APIS_GCM_ENGINE_CHECKIN_REQUEST_H_ |
OLD | NEW |