summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles/profile_downloader.cc
diff options
context:
space:
mode:
authoralemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-24 02:49:39 +0000
committeralemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-24 02:49:39 +0000
commitc2b68c83f9d9031bdcc9d7bf1723e013ab919752 (patch)
treeece63f9ae80a07f5f20012f95e9c6d1ed39541a1 /chrome/browser/profiles/profile_downloader.cc
parentf1c65a518fbff100d431447d0461b5d808fe69b9 (diff)
downloadchromium_src-c2b68c83f9d9031bdcc9d7bf1723e013ab919752.zip
chromium_src-c2b68c83f9d9031bdcc9d7bf1723e013ab919752.tar.gz
chromium_src-c2b68c83f9d9031bdcc9d7bf1723e013ab919752.tar.bz2
When user first time logs into Chromeos, he doesn't have "language" setting filled in his Chromeos profile. So he will inherit owner's locale.
We can improve this experience defaulting to his Google Account locale. So that the actual algorithm of language selection looks like this: 1) Use "language" setting from profile. 2) If failed, use "locale" setting from Google Account. 3) If failed, use owner's default. BUG=chromium:140591 TEST= 1) Remove user from device. 2) Clear user profile in https://www.google.com/settings/chrome/sync 3) Set Account language to some different to owners locale. 4) Login to device should now either use Account language immediately after login, or "Locale changed" message should appear after Account data is synchronized. Review URL: https://chromiumcodereview.appspot.com/23095006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles/profile_downloader.cc')
-rw-r--r--chrome/browser/profiles/profile_downloader.cc38
1 files changed, 27 insertions, 11 deletions
diff --git a/chrome/browser/profiles/profile_downloader.cc b/chrome/browser/profiles/profile_downloader.cc
index 8b4e9a0..b122208 100644
--- a/chrome/browser/profiles/profile_downloader.cc
+++ b/chrome/browser/profiles/profile_downloader.cc
@@ -16,6 +16,7 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_downloader_delegate.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "content/public/browser/browser_thread.h"
@@ -51,6 +52,9 @@ const char kFullNamePath[] = "name";
const char kGivenNamePath[] = "given_name";
+// Path in JSON dictionary to user's preferred locale.
+const char kLocalePath[] = "locale";
+
// Path format for specifying thumbnail's size.
const char kThumbnailSizeFormat[] = "s%d-c";
// Default thumbnail size.
@@ -124,18 +128,24 @@ bool GetImageURLWithSize(const GURL& old_url, int size, GURL* new_url) {
} // namespace
-// static
-bool ProfileDownloader::GetProfileNameAndImageURL(const std::string& data,
- string16* full_name,
- string16* given_name,
- std::string* url,
- int image_size) {
+// Parses the entry response and gets the name and profile image URL.
+// |data| should be the JSON formatted data return by the response.
+// Returns false to indicate a parsing error.
+bool ProfileDownloader::ParseProfileJSON(const std::string& data,
+ string16* full_name,
+ string16* given_name,
+ std::string* url,
+ int image_size,
+ std::string* profile_locale) {
DCHECK(full_name);
DCHECK(given_name);
DCHECK(url);
+ DCHECK(profile_locale);
+
*full_name = string16();
*given_name = string16();
*url = std::string();
+ *profile_locale = std::string();
int error_code = -1;
std::string error_message;
@@ -156,6 +166,7 @@ bool ProfileDownloader::GetProfileNameAndImageURL(const std::string& data,
root_dictionary->GetString(kFullNamePath, full_name);
root_dictionary->GetString(kGivenNamePath, given_name);
+ root_dictionary->GetString(kLocalePath, profile_locale);
std::string url_string;
if (root_dictionary->GetString(kPhotoThumbnailURLPath, &url_string)) {
@@ -233,6 +244,10 @@ string16 ProfileDownloader::GetProfileGivenName() const {
return profile_given_name_;
}
+std::string ProfileDownloader::GetProfileLocale() const {
+ return profile_locale_;
+}
+
SkBitmap ProfileDownloader::GetProfilePicture() const {
return profile_picture_;
}
@@ -293,11 +308,12 @@ void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
if (source == user_entry_fetcher_.get()) {
std::string image_url;
- if (!GetProfileNameAndImageURL(data,
- &profile_full_name_,
- &profile_given_name_,
- &image_url,
- delegate_->GetDesiredImageSideLength())) {
+ if (!ParseProfileJSON(data,
+ &profile_full_name_,
+ &profile_given_name_,
+ &image_url,
+ delegate_->GetDesiredImageSideLength(),
+ &profile_locale_)) {
delegate_->OnProfileDownloadFailure(
this, ProfileDownloaderDelegate::SERVICE_ERROR);
return;