| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "chrome/browser/profiles/profile_downloader.h" | 5 #include "chrome/browser/profiles/profile_downloader.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // Given an image URL this function builds a new URL set to |size|. | 68 // Given an image URL this function builds a new URL set to |size|. |
| 69 // For example, if |size| was set to 256 and |old_url| was either: | 69 // For example, if |size| was set to 256 and |old_url| was either: |
| 70 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg | 70 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg |
| 71 // or | 71 // or |
| 72 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s64-c/photo.jpg | 72 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s64-c/photo.jpg |
| 73 // then return value in |new_url| would be: | 73 // then return value in |new_url| would be: |
| 74 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s256-c/photo.jpg | 74 // https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s256-c/photo.jpg |
| 75 bool GetImageURLWithSize(const GURL& old_url, int size, GURL* new_url) { | 75 bool GetImageURLWithSize(const GURL& old_url, int size, GURL* new_url) { |
| 76 DCHECK(new_url); | 76 DCHECK(new_url); |
| 77 std::vector<std::string> components; | 77 std::vector<std::string> components = base::SplitString( |
| 78 base::SplitString(old_url.path(), kURLPathSeparator, &components); | 78 old_url.path(), std::string(1, kURLPathSeparator), |
| 79 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 79 if (components.size() == 0) | 80 if (components.size() == 0) |
| 80 return false; | 81 return false; |
| 81 | 82 |
| 82 const std::string& old_spec = old_url.spec(); | 83 const std::string& old_spec = old_url.spec(); |
| 83 std::string default_size_component( | 84 std::string default_size_component( |
| 84 base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize)); | 85 base::StringPrintf(kThumbnailSizeFormat, kDefaultThumbnailSize)); |
| 85 std::string new_size_component( | 86 std::string new_size_component( |
| 86 base::StringPrintf(kThumbnailSizeFormat, size)); | 87 base::StringPrintf(kThumbnailSizeFormat, size)); |
| 87 | 88 |
| 88 size_t pos = old_spec.find(default_size_component); | 89 size_t pos = old_spec.find(default_size_component); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 116 } // namespace | 117 } // namespace |
| 117 | 118 |
| 118 // static | 119 // static |
| 119 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { | 120 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { |
| 120 if (url.empty()) | 121 if (url.empty()) |
| 121 return true; | 122 return true; |
| 122 | 123 |
| 123 GURL image_url_object(url); | 124 GURL image_url_object(url); |
| 124 DCHECK(image_url_object.is_valid()); | 125 DCHECK(image_url_object.is_valid()); |
| 125 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); | 126 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); |
| 126 std::vector<std::string> path_components; | 127 std::vector<std::string> path_components = base::SplitString( |
| 127 base::SplitString(image_url_object.path(), | 128 image_url_object.path(), std::string(1, kURLPathSeparator), |
| 128 kURLPathSeparator, | 129 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 129 &path_components); | |
| 130 | 130 |
| 131 if (path_components.size() < kProfileImageURLPathComponentsCount) | 131 if (path_components.size() < kProfileImageURLPathComponentsCount) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; | 134 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; |
| 135 const std::string& photo_version = | 135 const std::string& photo_version = |
| 136 path_components[kPhotoVersionPathComponentIndex]; | 136 path_components[kPhotoVersionPathComponentIndex]; |
| 137 | 137 |
| 138 // Check that the ID and version match the default Picasa profile photo. | 138 // Check that the ID and version match the default Picasa profile photo. |
| 139 return photo_id == kPicasaPhotoId && | 139 return photo_id == kPicasaPhotoId && |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 account_info_ = info; | 373 account_info_ = info; |
| 374 | 374 |
| 375 // If the StartFetchingImage was called before we had valid info, the | 375 // If the StartFetchingImage was called before we had valid info, the |
| 376 // downloader has been waiting so we need to fetch the image data now. | 376 // downloader has been waiting so we need to fetch the image data now. |
| 377 if (waiting_for_account_info_) { | 377 if (waiting_for_account_info_) { |
| 378 FetchImageData(); | 378 FetchImageData(); |
| 379 waiting_for_account_info_ = false; | 379 waiting_for_account_info_ = false; |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 } | 382 } |
| OLD | NEW |