1 // Copyright 2015 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_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "google_apis/gaia/gaia_auth_consumer.h"
15 #include "net/base/backoff_entry.h"
16 #include "net/url_request/url_fetcher_delegate.h"
18 class GaiaAuthFetcher
;
25 class DeviceActivityFetcher
: public GaiaAuthConsumer
,
26 public net::URLFetcherDelegate
{
28 struct DeviceActivity
{
29 base::Time last_active
;
35 virtual void OnFetchDeviceActivitySuccess(
36 const std::vector
<DeviceActivityFetcher::DeviceActivity
>& devices
) = 0;
37 virtual void OnFetchDeviceActivityFailure() {}
40 DeviceActivityFetcher(SigninClient
* signin_client
,
41 DeviceActivityFetcher::Observer
* observer
);
42 ~DeviceActivityFetcher() override
;
48 void OnListIdpSessionsSuccess(const std::string
& login_hint
) override
;
49 void OnListIdpSessionsError(const GoogleServiceAuthError
& error
) override
;
50 void OnGetTokenResponseSuccess(const ClientOAuthResult
& result
) override
;
51 void OnGetTokenResponseError(const GoogleServiceAuthError
& error
) override
;
53 // net::URLFetcherDelegate:
54 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
57 void StartFetchingListIdpSessions();
58 void StartFetchingGetTokenResponse();
59 void StartFetchingListDevices();
61 // Gaia fetcher used for acquiring an access token.
62 scoped_ptr
<GaiaAuthFetcher
> gaia_auth_fetcher_
;
63 // URL Fetcher used for calling List Devices.
64 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
66 // If either fetcher fails, retry with exponential backoff.
67 net::BackoffEntry fetcher_backoff_
;
68 base::OneShotTimer
<DeviceActivityFetcher
> fetcher_timer_
;
71 std::string access_token_
;
72 std::string login_hint_
;
74 SigninClient
* signin_client_
; // Weak pointer.
77 DISALLOW_COPY_AND_ASSIGN(DeviceActivityFetcher
);
80 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_