Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / signin / core / browser / device_activity_fetcher.h
blobcd7bb81c3451412342f7e10b81afa443ad5eb83d
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_
8 #include <string>
9 #include <vector>
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;
19 class SigninClient;
21 namespace net {
22 class URLFetcher;
25 class DeviceActivityFetcher : public GaiaAuthConsumer,
26 public net::URLFetcherDelegate {
27 public:
28 struct DeviceActivity {
29 base::Time last_active;
30 std::string name;
33 class Observer {
34 public:
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;
44 void Start();
45 void Stop();
47 // GaiaAuthConsumer:
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;
56 private:
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_;
69 int fetcher_retries_;
71 std::string access_token_;
72 std::string login_hint_;
74 SigninClient* signin_client_; // Weak pointer.
75 Observer* observer_;
77 DISALLOW_COPY_AND_ASSIGN(DeviceActivityFetcher);
80 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_