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 <string> |
| 9 #include <vector> |
| 10 |
| 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" |
| 17 |
| 18 class GaiaAuthFetcher; |
| 19 class SigninClient; |
| 20 |
| 21 namespace net { |
| 22 class URLFetcher; |
| 23 } |
| 24 |
| 25 class DeviceActivityFetcher : public GaiaAuthConsumer, |
| 26 public net::URLFetcherDelegate { |
| 27 public: |
| 28 struct DeviceActivity { |
| 29 base::Time last_active; |
| 30 std::string name; |
| 31 }; |
| 32 |
| 33 class Observer { |
| 34 public: |
| 35 virtual void OnFetchDeviceActivitySuccess( |
| 36 const std::vector<DeviceActivityFetcher::DeviceActivity>& devices) = 0; |
| 37 virtual void OnFetchDeviceActivityFailure() {} |
| 38 }; |
| 39 |
| 40 DeviceActivityFetcher(SigninClient* signin_client, |
| 41 DeviceActivityFetcher::Observer* observer); |
| 42 ~DeviceActivityFetcher() override; |
| 43 |
| 44 void Start(); |
| 45 void Stop(); |
| 46 |
| 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; |
| 52 |
| 53 // net::URLFetcherDelegate: |
| 54 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 55 |
| 56 private: |
| 57 void StartFetchingListIdpSessions(); |
| 58 void StartFetchingGetTokenResponse(); |
| 59 void StartFetchingListDevices(); |
| 60 |
| 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_; |
| 65 |
| 66 // If either fetcher fails, retry with exponential backoff. |
| 67 net::BackoffEntry fetcher_backoff_; |
| 68 base::OneShotTimer<DeviceActivityFetcher> fetcher_timer_; |
| 69 int fetcher_retries_; |
| 70 |
| 71 std::string access_token_; |
| 72 std::string login_hint_; |
| 73 |
| 74 SigninClient* signin_client_; // Weak pointer. |
| 75 Observer* observer_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(DeviceActivityFetcher); |
| 78 }; |
| 79 |
| 80 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_DEVICE_ACTVITIY_FETCHER_H_ |
OLD | NEW |