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 COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_REQUEST_H_
6 #define COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_REQUEST_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "net/base/backoff_entry.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_request_context_getter.h"
20 class URLRequestContextGetter
;
25 // Defines the request to talk with the server to determine if the GCM support
27 class GCMChannelStatusRequest
: public net::URLFetcherDelegate
{
29 // Callback completing the channel status request.
30 // |update_received|: use the existing values if it is false which means no
31 // update is received.
32 // |enabled|: indicates if GCM is enabled (allowed to run) or not.
33 // |poll_interval_seconds|: the interval in seconds to start next poll
35 typedef base::Callback
<void(bool update_received
,
37 int poll_interval_seconds
)>
38 GCMChannelStatusRequestCallback
;
40 GCMChannelStatusRequest(
41 const scoped_refptr
<net::URLRequestContextGetter
>& request_context_getter
,
42 const std::string
& channel_status_request_url
,
43 const std::string
& user_agent
,
44 const GCMChannelStatusRequestCallback
& callback
);
45 ~GCMChannelStatusRequest() override
;
49 static int default_poll_interval_seconds();
50 static int min_poll_interval_seconds();
53 FRIEND_TEST_ALL_PREFIXES(GCMChannelStatusRequestTest
, RequestData
);
55 // Overridden from URLFetcherDelegate:
56 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
58 bool ParseResponse(const net::URLFetcher
* source
);
59 void RetryWithBackoff(bool update_backoff
);
61 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter_
;
62 const std::string channel_status_request_url_
;
63 const std::string user_agent_
;
64 GCMChannelStatusRequestCallback callback_
;
65 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
66 net::BackoffEntry backoff_entry_
;
67 base::WeakPtrFactory
<GCMChannelStatusRequest
> weak_ptr_factory_
;
69 DISALLOW_COPY_AND_ASSIGN(GCMChannelStatusRequest
);
74 #endif // COMPONENTS_GCM_DRIVER_GCM_CHANNEL_STATUS_REQUEST_H_