Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 9960077: Modify the base::JSONReader interface to take a set of options rather than a boolean flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 static const size_t kNumDataTypes = arraysize(kDataTypes); 89 static const size_t kNumDataTypes = arraysize(kDataTypes);
90 COMPILE_ASSERT(arraysize(kDataTypeNames) == arraysize(kDataTypes), 90 COMPILE_ASSERT(arraysize(kDataTypeNames) == arraysize(kDataTypes),
91 kDataTypes_does_not_match_kDataTypeNames); 91 kDataTypes_does_not_match_kDataTypeNames);
92 92
93 bool GetAuthData(const std::string& json, 93 bool GetAuthData(const std::string& json,
94 std::string* username, 94 std::string* username,
95 std::string* password, 95 std::string* password,
96 std::string* captcha, 96 std::string* captcha,
97 std::string* access_code) { 97 std::string* access_code) {
98 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 98 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json));
99 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 99 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY))
100 return false; 100 return false;
101 101
102 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 102 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
103 if (!result->GetString("user", username) || 103 if (!result->GetString("user", username) ||
104 !result->GetString("pass", password) || 104 !result->GetString("pass", password) ||
105 !result->GetString("captcha", captcha) || 105 !result->GetString("captcha", captcha) ||
106 !result->GetString("access_code", access_code)) { 106 !result->GetString("access_code", access_code)) {
107 return false; 107 return false;
108 } 108 }
109 return true; 109 return true;
110 } 110 }
111 111
112 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { 112 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) {
113 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 113 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json));
114 DictionaryValue* result; 114 DictionaryValue* result;
115 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) { 115 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) {
116 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; 116 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary";
117 return false; 117 return false;
118 } 118 }
119 119
120 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { 120 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) {
121 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; 121 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value";
122 return false; 122 return false;
123 } 123 }
(...skipping 30 matching lines...) Expand all
154 } 154 }
155 if (!result->GetString("passphrase", &config->passphrase)) { 155 if (!result->GetString("passphrase", &config->passphrase)) {
156 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value"; 156 DLOG(ERROR) << "GetConfiguration() not passed a passphrase value";
157 return false; 157 return false;
158 } 158 }
159 } 159 }
160 return true; 160 return true;
161 } 161 }
162 162
163 bool GetPassphrase(const std::string& json, std::string* passphrase) { 163 bool GetPassphrase(const std::string& json, std::string* passphrase) {
164 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 164 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json));
165 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 165 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY))
166 return false; 166 return false;
167 167
168 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 168 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
169 return result->GetString("passphrase", passphrase); 169 return result->GetString("passphrase", passphrase);
170 } 170 }
171 171
172 string16 NormalizeUserName(const string16& user) { 172 string16 NormalizeUserName(const string16& user) {
173 if (user.find_first_of(ASCIIToUTF16("@")) != string16::npos) 173 if (user.find_first_of(ASCIIToUTF16("@")) != string16::npos)
174 return user; 174 return user;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) 713 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty())
714 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); 714 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE);
715 if (!configuration.sync_everything) 715 if (!configuration.sync_everything)
716 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); 716 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE);
717 } 717 }
718 718
719 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { 719 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) {
720 bool force_login = false; 720 bool force_login = false;
721 std::string json; 721 std::string json;
722 if (args->GetString(0, &json) && !json.empty()) { 722 if (args->GetString(0, &json) && !json.empty()) {
723 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 723 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json));
724 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 724 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
725 result->GetBoolean("forceLogin", &force_login); 725 result->GetBoolean("forceLogin", &force_login);
726 } 726 }
727 727
728 OpenSyncSetup(force_login); 728 OpenSyncSetup(force_login);
729 } 729 }
730 730
731 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { 731 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) {
732 DCHECK(!configuring_sync_); 732 DCHECK(!configuring_sync_);
733 733
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (i != current_profile_index && AreUserNamesEqual( 901 if (i != current_profile_index && AreUserNamesEqual(
902 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 902 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
903 *error_message = l10n_util::GetStringUTF16( 903 *error_message = l10n_util::GetStringUTF16(
904 IDS_SYNC_USER_NAME_IN_USE_ERROR); 904 IDS_SYNC_USER_NAME_IN_USE_ERROR);
905 return false; 905 return false;
906 } 906 }
907 } 907 }
908 908
909 return true; 909 return true;
910 } 910 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698