Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_ | |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/time/time.h" | |
| 11 #include "base/timer/timer.h" | |
| 12 #include "google_apis/gaia/gaia_auth_consumer.h" | |
| 13 #include "net/base/backoff_entry.h" | |
| 14 #include "net/url_request/url_fetcher_delegate.h" | |
| 15 | |
| 16 class GaiaAuthFetcher; | |
| 17 class SigninClient; | |
| 18 | |
| 19 namespace net { | |
| 20 class URLFetcher; | |
| 21 } | |
| 22 | |
| 23 class DeviceActivityFetcher : public GaiaAuthConsumer, | |
| 24 public net::URLFetcherDelegate { | |
| 25 public: | |
| 26 struct DeviceActivity { | |
| 27 base::Time last_active; | |
|
Alexei Svitkine (slow)
2015/05/19 15:23:49
Nit: Wrong indent.
Mike Lerman
2015/05/19 16:53:17
Done.
| |
| 28 std::string name; | |
| 29 }; | |
| 30 | |
| 31 class Observer { | |
| 32 public: | |
| 33 virtual void OnFetchDeviceActivitySuccess( | |
| 34 const std::vector<DeviceActivityFetcher::DeviceActivity>& devices) = 0; | |
| 35 virtual void OnFetchDeviceActivityFailure() {} | |
| 36 }; | |
| 37 | |
| 38 DeviceActivityFetcher(SigninClient* signin_client, | |
| 39 DeviceActivityFetcher::Observer* observer); | |
| 40 ~DeviceActivityFetcher() override; | |
| 41 | |
| 42 void Start(); | |
| 43 void Stop(); | |
| 44 | |
| 45 // Overridden from GaiaAuthConsumer | |
| 46 void OnListIdpSessionsSuccess(const std::string& login_hint) override; | |
| 47 void OnListIdpSessionsError(const GoogleServiceAuthError& error) override; | |
| 48 void OnGetTokenResponseSuccess(const ClientOAuthResult& result) override; | |
| 49 void OnGetTokenResponseError(const GoogleServiceAuthError& error) override; | |
| 50 | |
| 51 // Overridden from URLFetcherDelegate | |
| 52 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 53 | |
| 54 private: | |
| 55 void StartFetchingListIdpSessions(); | |
| 56 void StartFetchingGetTokenResponse(); | |
| 57 void StartFetchingListDevices(); | |
| 58 | |
| 59 // Gaia fetcher used for acquiring an access token. | |
| 60 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
| 61 // URL Fetcher used for calling List Devices. | |
| 62 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 63 | |
| 64 // If either fetcher fails, retry with exponential backoff. | |
| 65 net::BackoffEntry fetcher_backoff_; | |
| 66 base::OneShotTimer<DeviceActivityFetcher> fetcher_timer_; | |
| 67 int fetcher_retries_; | |
| 68 | |
| 69 std::string access_token_; | |
| 70 std::string login_hint_; | |
| 71 | |
| 72 SigninClient* signin_client_; // Weak pointer. | |
| 73 Observer* observer_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(DeviceActivityFetcher); | |
| 76 }; | |
| 77 | |
| 78 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_ | |
| OLD | NEW |