| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 13 #include "chrome/browser/utility_process_host.h" | 14 #include "chrome/browser/chromeos/login/image_decoder.h" |
| 14 #include "chrome/common/net/url_fetcher.h" | 15 #include "chrome/common/net/url_fetcher.h" |
| 15 | 16 |
| 16 class ListValue; | 17 class ListValue; |
| 17 class ResourceDispatcherHost; | |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 // Gets user image URL from user's Google Profile, downloads the image, | 21 // Gets user image URL from user's Google Profile, downloads the image, |
| 22 // converts it to PNG format and stores the converted image in a file with | 22 // executes image decode and calls UserManager to store image in a file with |
| 23 // path to it stored in local state dictionary. | 23 // path to it stored in local state dictionary. |
| 24 class UserImageDownloader : public URLFetcher::Delegate, | 24 class UserImageDownloader : public URLFetcher::Delegate, |
| 25 public UtilityProcessHost::Client { | 25 public ImageDecoder::Delegate { |
| 26 public: | 26 public: |
| 27 // |auth_token| is a authentication token received in ClientLogin | 27 // |auth_token| is a authentication token received in ClientLogin |
| 28 // response, used for requests sent to Contacts API. | 28 // response, used for requests sent to Contacts API. |
| 29 // Starts downloading the picture. Object is deleted as reference counted | 29 // Starts downloading the picture. Object is deleted as reference counted |
| 30 // object. | 30 // object. |
| 31 UserImageDownloader(const std::string& username, | 31 UserImageDownloader(const std::string& username, |
| 32 const std::string& auth_token); | 32 const std::string& auth_token); |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 // It's a reference counted object, so destructor is private. | 35 // It's a reference counted object, so destructor is private. |
| 36 ~UserImageDownloader(); | 36 ~UserImageDownloader(); |
| 37 | 37 |
| 38 // Overriden from URLFetcher::Delegate: | 38 // Overriden from URLFetcher::Delegate: |
| 39 virtual void OnURLFetchComplete(const URLFetcher* source, | 39 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 40 const GURL& url, | 40 const GURL& url, |
| 41 const URLRequestStatus& status, | 41 const URLRequestStatus& status, |
| 42 int response_code, | 42 int response_code, |
| 43 const ResponseCookies& cookies, | 43 const ResponseCookies& cookies, |
| 44 const std::string& data); | 44 const std::string& data); |
| 45 | 45 |
| 46 // Overriden from UtilityProcessHost::Client: | 46 // Overriden from ImageDecoder::Delegate: |
| 47 virtual void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | 47 virtual void OnImageDecoded(const SkBitmap& decoded_image); |
| 48 | |
| 49 // Launches sandboxed process that will decode the image. | |
| 50 void DecodeImageInSandbox(ResourceDispatcherHost* rdh, | |
| 51 const std::vector<unsigned char>& image_data); | |
| 52 | 48 |
| 53 // Parses received JSON data looking for user image url. | 49 // Parses received JSON data looking for user image url. |
| 54 // If succeeded, returns true and stores the url in |image_url| parameter. | 50 // If succeeded, returns true and stores the url in |image_url| parameter. |
| 55 // Otherwise, returns false. | 51 // Otherwise, returns false. |
| 56 bool GetImageURL(const std::string& json_data, GURL* image_url) const; | 52 bool GetImageURL(const std::string& json_data, GURL* image_url) const; |
| 57 | 53 |
| 58 // Searches for image url in a list of contacts matching contact address | 54 // Searches for image url in a list of contacts matching contact address |
| 59 // with user email. Returns true and image url if succeeds, false | 55 // with user email. Returns true and image url if succeeds, false |
| 60 // otherwise. | 56 // otherwise. |
| 61 bool GetImageURLFromEntries(ListValue* entry_list, GURL* image_url) const; | 57 bool GetImageURLFromEntries(ListValue* entry_list, GURL* image_url) const; |
| 62 | 58 |
| 63 // Checks if email list contains user email. Returns true if match is | 59 // Checks if email list contains user email. Returns true if match is |
| 64 // found. | 60 // found. |
| 65 bool IsUserEntry(ListValue* email_list) const; | 61 bool IsUserEntry(ListValue* email_list) const; |
| 66 | 62 |
| 67 // Searches for image url in list of links for the found contact. | 63 // Searches for image url in list of links for the found contact. |
| 68 // Returns true and image url if succeeds, false otherwise. | 64 // Returns true and image url if succeeds, false otherwise. |
| 69 bool GetImageURLFromLinks(ListValue* link_list, GURL* image_url) const; | 65 bool GetImageURLFromLinks(ListValue* link_list, GURL* image_url) const; |
| 70 | 66 |
| 71 // Encodes user image in PNG format and saves the result to the file | 67 // Encodes user image in PNG format and saves the result to the file |
| 72 // specified. Should work on IO thread. | 68 // specified. Should work on IO thread. |
| 73 void SaveImageAsPNG(const std::string& filename, const SkBitmap& image); | 69 void SaveImageAsPNG(const std::string& filename, const SkBitmap& image); |
| 74 | 70 |
| 75 // Fetcher for user's profile page. | 71 // Fetcher for user's profile page. |
| 76 scoped_ptr<URLFetcher> profile_fetcher_; | 72 scoped_ptr<URLFetcher> profile_fetcher_; |
| 77 | 73 |
| 78 // Fetcher for user's profile picture. | |
| 79 scoped_ptr<URLFetcher> picture_fetcher_; | |
| 80 | |
| 81 // Username saved to use as a key for user picture in preferences. | 74 // Username saved to use as a key for user picture in preferences. |
| 82 std::string username_; | 75 std::string username_; |
| 83 | 76 |
| 84 // Authentication token to use for image download. | 77 // Authentication token to use for image download. |
| 85 std::string auth_token_; | 78 std::string auth_token_; |
| 86 | 79 |
| 87 DISALLOW_COPY_AND_ASSIGN(UserImageDownloader); | 80 DISALLOW_COPY_AND_ASSIGN(UserImageDownloader); |
| 88 }; | 81 }; |
| 89 | 82 |
| 90 } // namespace chromeos | 83 } // namespace chromeos |
| 91 | 84 |
| 92 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_DOWNLOADER_H_ |
| 93 | 86 |
| OLD | NEW |