| 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_REGISTRATION_REQUEST_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| 6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 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/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "google_apis/gcm/base/gcm_export.h" | 16 #include "google_apis/gcm/base/gcm_export.h" |
| 17 #include "net/base/backoff_entry.h" | 17 #include "net/base/backoff_entry.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 class URLRequestContextGetter; | 21 class URLRequestContextGetter; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace gcm { | 24 namespace gcm { |
| 25 | 25 |
| 26 class GCMStatsRecorder; |
| 27 |
| 26 // Registration request is used to obtain registration IDs for applications that | 28 // Registration request is used to obtain registration IDs for applications that |
| 27 // want to use GCM. It requires a set of parameters to be specified to identify | 29 // want to use GCM. It requires a set of parameters to be specified to identify |
| 28 // the Chrome instance, the user, the application and a set of senders that will | 30 // the Chrome instance, the user, the application and a set of senders that will |
| 29 // be authorized to address the application using it's assigned registration ID. | 31 // be authorized to address the application using it's assigned registration ID. |
| 30 class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate { | 32 class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate { |
| 31 public: | 33 public: |
| 32 // This enum is also used in an UMA histogram (GCMRegistrationRequestStatus | 34 // This enum is also used in an UMA histogram (GCMRegistrationRequestStatus |
| 33 // enum defined in tools/metrics/histograms/histogram.xml). Hence the entries | 35 // enum defined in tools/metrics/histograms/histogram.xml). Hence the entries |
| 34 // here shouldn't be deleted or re-ordered and new ones should be added to | 36 // here shouldn't be deleted or re-ordered and new ones should be added to |
| 35 // the end. | 37 // the end. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 std::string cert; | 77 std::string cert; |
| 76 // List of IDs of senders. Allowed up to 100. | 78 // List of IDs of senders. Allowed up to 100. |
| 77 std::vector<std::string> sender_ids; | 79 std::vector<std::string> sender_ids; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 RegistrationRequest( | 82 RegistrationRequest( |
| 81 const RequestInfo& request_info, | 83 const RequestInfo& request_info, |
| 82 const net::BackoffEntry::Policy& backoff_policy, | 84 const net::BackoffEntry::Policy& backoff_policy, |
| 83 const RegistrationCallback& callback, | 85 const RegistrationCallback& callback, |
| 84 int max_retry_count, | 86 int max_retry_count, |
| 85 scoped_refptr<net::URLRequestContextGetter> request_context_getter); | 87 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 88 GCMStatsRecorder* recorder); |
| 86 virtual ~RegistrationRequest(); | 89 virtual ~RegistrationRequest(); |
| 87 | 90 |
| 88 void Start(); | 91 void Start(); |
| 89 | 92 |
| 90 // URLFetcherDelegate implementation. | 93 // URLFetcherDelegate implementation. |
| 91 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 94 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 92 | 95 |
| 93 private: | 96 private: |
| 94 // Schedules a retry attempt, informs the backoff of a previous request's | 97 // Schedules a retry attempt, informs the backoff of a previous request's |
| 95 // failure, when |update_backoff| is true. | 98 // failure, when |update_backoff| is true. |
| 96 void RetryWithBackoff(bool update_backoff); | 99 void RetryWithBackoff(bool update_backoff); |
| 97 | 100 |
| 98 // Parse the response returned by the URL fetcher into token, and returns the | 101 // Parse the response returned by the URL fetcher into token, and returns the |
| 99 // status. | 102 // status. |
| 100 Status ParseResponse(const net::URLFetcher* source, std::string* token); | 103 Status ParseResponse(const net::URLFetcher* source, std::string* token); |
| 101 | 104 |
| 102 RegistrationCallback callback_; | 105 RegistrationCallback callback_; |
| 103 RequestInfo request_info_; | 106 RequestInfo request_info_; |
| 104 | 107 |
| 105 net::BackoffEntry backoff_entry_; | 108 net::BackoffEntry backoff_entry_; |
| 106 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 109 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 107 scoped_ptr<net::URLFetcher> url_fetcher_; | 110 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 108 int retries_left_; | 111 int retries_left_; |
| 109 | 112 |
| 113 // Recorder that records GCM activities for debugging purpose. Not owned. |
| 114 GCMStatsRecorder* recorder_; |
| 115 |
| 110 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; | 116 base::WeakPtrFactory<RegistrationRequest> weak_ptr_factory_; |
| 111 | 117 |
| 112 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); | 118 DISALLOW_COPY_AND_ASSIGN(RegistrationRequest); |
| 113 }; | 119 }; |
| 114 | 120 |
| 115 } // namespace gcm | 121 } // namespace gcm |
| 116 | 122 |
| 117 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ | 123 #endif // GOOGLE_APIS_GCM_ENGINE_REGISTRATION_REQUEST_H_ |
| OLD | NEW |