[email protected] | 994bbd6 | 2012-06-28 14:24:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 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 CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_ | ||||
6 | #define CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_ | ||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | |||||
[email protected] | 76fb05c | 2013-06-11 04:38:05 | [diff] [blame] | 10 | #include "base/strings/string16.h" |
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 11 | |
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 12 | class ProfileDownloader; |
13 | |||||
Miyoung Shin | 23737f6 | 2019-07-23 15:43:31 | [diff] [blame] | 14 | namespace signin { |
Sylvain Defresne | e220e53 | 2019-07-17 15:49:19 | [diff] [blame] | 15 | class IdentityManager; |
Miyoung Shin | 23737f6 | 2019-07-23 15:43:31 | [diff] [blame] | 16 | } // namespace signin |
Sylvain Defresne | e220e53 | 2019-07-17 15:49:19 | [diff] [blame] | 17 | |
18 | namespace network { | ||||
19 | namespace mojom { | ||||
20 | class URLLoaderFactory; | ||||
21 | } // namespace mojom | ||||
22 | } // namespace network | ||||
23 | |||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 24 | // Reports on success or failure of Profile download. It is OK to delete the |
25 | // |ProfileImageDownloader| instance in any of these handlers. | ||||
26 | class ProfileDownloaderDelegate { | ||||
27 | public: | ||||
[email protected] | 57eaa328 | 2012-12-17 20:16:42 | [diff] [blame] | 28 | // Error codes passed to OnProfileDownloadFailure. |
29 | enum FailureReason { | ||||
Mihai Sardarescu | e78ada7 | 2018-06-22 14:57:53 | [diff] [blame] | 30 | TOKEN_ERROR, // Cannot fetch OAuth2 token. |
31 | NETWORK_ERROR, // Network failure while downloading profile. | ||||
32 | SERVICE_ERROR, // Service returned an error or malformed reply. | ||||
33 | IMAGE_DECODE_FAILED, // Cannot decode fetched image. | ||||
34 | INVALID_PROFILE_PICTURE_URL // The profile picture URL is invalid. | ||||
[email protected] | 57eaa328 | 2012-12-17 20:16:42 | [diff] [blame] | 35 | }; |
36 | |||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 37 | virtual ~ProfileDownloaderDelegate() {} |
38 | |||||
[email protected] | 994bbd6 | 2012-06-28 14:24:38 | [diff] [blame] | 39 | // Whether the delegate need profile picture to be downloaded. |
40 | virtual bool NeedsProfilePicture() const = 0; | ||||
41 | |||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 42 | // Returns the desired side length of the profile image. If 0, returns image |
43 | // of the originally uploaded size. | ||||
[email protected] | 5c9a1ad | 2011-11-30 23:32:40 | [diff] [blame] | 44 | virtual int GetDesiredImageSideLength() const = 0; |
45 | |||||
46 | // Returns the cached URL. If the cache URL matches the new image URL | ||||
Finnur Thorarinsson | febcdb5 | 2018-08-23 14:07:13 | [diff] [blame] | 47 | // the image will not be downloaded. Return an empty string when there is no |
[email protected] | 5c9a1ad | 2011-11-30 23:32:40 | [diff] [blame] | 48 | // cached URL. |
Finnur Thorarinsson | febcdb5 | 2018-08-23 14:07:13 | [diff] [blame] | 49 | virtual std::string GetCachedPictureURL() const = 0; |
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 50 | |
Sylvain Defresne | e220e53 | 2019-07-17 15:49:19 | [diff] [blame] | 51 | // Returns the IdentityManager associated with this download request. |
Miyoung Shin | 23737f6 | 2019-07-23 15:43:31 | [diff] [blame] | 52 | virtual signin::IdentityManager* GetIdentityManager() = 0; |
Sylvain Defresne | e220e53 | 2019-07-17 15:49:19 | [diff] [blame] | 53 | |
54 | // Returns the URLLoaderFactory to use for this download request. | ||||
55 | virtual network::mojom::URLLoaderFactory* GetURLLoaderFactory() = 0; | ||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 56 | |
anthonyvd | d98e85c | 2015-08-04 19:54:20 | [diff] [blame] | 57 | // Returns true if the profile download is taking place before the user has |
58 | // signed in. This can happen for example on Android and will trigger some | ||||
59 | // additional fetches since some information is not yet available. | ||||
60 | virtual bool IsPreSignin() const = 0; | ||||
61 | |||||
[email protected] | 994bbd6 | 2012-06-28 14:24:38 | [diff] [blame] | 62 | // Called when the profile download has completed successfully. Delegate can |
63 | // query the downloader for the picture and full name. | ||||
64 | virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) = 0; | ||||
65 | |||||
66 | // Called when the profile download has failed. | ||||
[email protected] | 57eaa328 | 2012-12-17 20:16:42 | [diff] [blame] | 67 | virtual void OnProfileDownloadFailure( |
68 | ProfileDownloader* downloader, | ||||
69 | ProfileDownloaderDelegate::FailureReason reason) = 0; | ||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 70 | }; |
71 | |||||
72 | #endif // CHROME_BROWSER_PROFILES_PROFILE_DOWNLOADER_DELEGATE_H_ |