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

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

Issue 7661009: base: Add Is* functions to Value class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tony review Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 29 matching lines...) Expand all
40 #endif 40 #endif
41 const char* kCreateNewAccountUrl = 41 const char* kCreateNewAccountUrl =
42 "https://www.google.com/accounts/NewAccount?service=chromiumsync"; 42 "https://www.google.com/accounts/NewAccount?service=chromiumsync";
43 43
44 bool GetAuthData(const std::string& json, 44 bool GetAuthData(const std::string& json,
45 std::string* username, 45 std::string* username,
46 std::string* password, 46 std::string* password,
47 std::string* captcha, 47 std::string* captcha,
48 std::string* access_code) { 48 std::string* access_code) {
49 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 49 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
50 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 50 if (!parsed_value.get() || !parsed_value->IsDictionary())
51 return false; 51 return false;
52 52
53 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 53 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
54 if (!result->GetString("user", username) || 54 if (!result->GetString("user", username) ||
55 !result->GetString("pass", password) || 55 !result->GetString("pass", password) ||
56 !result->GetString("captcha", captcha) || 56 !result->GetString("captcha", captcha) ||
57 !result->GetString("access_code", access_code)) { 57 !result->GetString("access_code", access_code)) {
58 return false; 58 return false;
59 } 59 }
60 return true; 60 return true;
61 } 61 }
62 62
63 bool GetConfiguration(const std::string& json, SyncConfiguration* config) { 63 bool GetConfiguration(const std::string& json, SyncConfiguration* config) {
64 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 64 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
65 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 65 if (!parsed_value.get() || !parsed_value->IsDictionary())
66 return false; 66 return false;
67 67
68 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 68 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
69 if (!result->GetBoolean("keepEverythingSynced", &config->sync_everything)) 69 if (!result->GetBoolean("keepEverythingSynced", &config->sync_everything))
70 return false; 70 return false;
71 71
72 // These values need to be kept in sync with where they are written in 72 // These values need to be kept in sync with where they are written in
73 // choose_datatypes.html. 73 // choose_datatypes.html.
74 bool sync_bookmarks; 74 bool sync_bookmarks;
75 if (!result->GetBoolean("syncBookmarks", &sync_bookmarks)) 75 if (!result->GetBoolean("syncBookmarks", &sync_bookmarks))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return false; 134 return false;
135 if (config->use_secondary_passphrase && 135 if (config->use_secondary_passphrase &&
136 !result->GetString("passphrase", &config->secondary_passphrase)) 136 !result->GetString("passphrase", &config->secondary_passphrase))
137 return false; 137 return false;
138 138
139 return true; 139 return true;
140 } 140 }
141 141
142 bool GetPassphrase(const std::string& json, std::string* passphrase) { 142 bool GetPassphrase(const std::string& json, std::string* passphrase) {
143 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 143 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
144 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 144 if (!parsed_value.get() || !parsed_value->IsDictionary())
145 return false; 145 return false;
146 146
147 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 147 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
148 return result->GetString("passphrase", passphrase); 148 return result->GetString("passphrase", passphrase);
149 } 149 }
150 150
151 } // namespace 151 } // namespace
152 152
153 SyncSetupHandler::SyncSetupHandler() : flow_(NULL) { 153 SyncSetupHandler::SyncSetupHandler() : flow_(NULL) {
154 } 154 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 ShowSetupUI(); 478 ShowSetupUI();
479 479
480 // The SyncSetupFlow will set itself as the |flow_|. 480 // The SyncSetupFlow will set itself as the |flow_|.
481 if (!service->get_wizard().AttachSyncSetupHandler(this)) { 481 if (!service->get_wizard().AttachSyncSetupHandler(this)) {
482 // If attach fails, a wizard is already activated and attached to a flow 482 // If attach fails, a wizard is already activated and attached to a flow
483 // handler. 483 // handler.
484 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); 484 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay");
485 service->get_wizard().Focus(); 485 service->get_wizard().Focus();
486 } 486 }
487 } 487 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_handler.cc ('k') | chrome/browser/web_resource/promo_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698