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

Side by Side Diff: chrome/browser/autofill/wallet/wallet_items.cc

Issue 11777007: Adds wallet::RequiredAction for when we start interacting with Online Wallet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: class -> namespace Created 7 years, 11 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/autofill/wallet/wallet_items.h" 5 #include "chrome/browser/autofill/wallet/wallet_items.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/autofill/wallet/required_action.h"
9 10
10 namespace { 11 namespace {
11 12
12 wallet::WalletItems::MaskedInstrument::Type 13 wallet::WalletItems::MaskedInstrument::Type
13 TypeFromString(const std::string& type_string) { 14 TypeFromString(const std::string& type_string) {
14 if (type_string == "VISA") 15 if (type_string == "VISA")
15 return wallet::WalletItems::MaskedInstrument::VISA; 16 return wallet::WalletItems::MaskedInstrument::VISA;
16 if (type_string == "MASTER_CARD") 17 if (type_string == "MASTER_CARD")
17 return wallet::WalletItems::MaskedInstrument::MASTER_CARD; 18 return wallet::WalletItems::MaskedInstrument::MASTER_CARD;
18 if (type_string == "AMEX") 19 if (type_string == "AMEX")
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 bool WalletItems::LegalDocument::operator==(const LegalDocument& other) const { 237 bool WalletItems::LegalDocument::operator==(const LegalDocument& other) const {
237 return document_id_ == other.document_id_ && 238 return document_id_ == other.document_id_ &&
238 display_name_ == other.display_name_ && 239 display_name_ == other.display_name_ &&
239 document_body_ == other.document_body_; 240 document_body_ == other.document_body_;
240 } 241 }
241 242
242 bool WalletItems::LegalDocument::operator!=(const LegalDocument& other) const { 243 bool WalletItems::LegalDocument::operator!=(const LegalDocument& other) const {
243 return !(*this == other); 244 return !(*this == other);
244 } 245 }
245 246
246 WalletItems::WalletItems(const std::vector<std::string>& required_actions, 247 WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions,
247 const std::string& google_transaction_id, 248 const std::string& google_transaction_id,
248 const std::string& default_instrument_id, 249 const std::string& default_instrument_id,
249 const std::string& default_address_id) 250 const std::string& default_address_id)
250 : required_actions_(required_actions), 251 : required_actions_(required_actions),
251 google_transaction_id_(google_transaction_id), 252 google_transaction_id_(google_transaction_id),
252 default_instrument_id_(default_instrument_id), 253 default_instrument_id_(default_instrument_id),
253 default_address_id_(default_address_id) {} 254 default_address_id_(default_address_id) {}
254 255
255 WalletItems::~WalletItems() {} 256 WalletItems::~WalletItems() {}
256 257
257 scoped_ptr<WalletItems> 258 scoped_ptr<WalletItems>
258 WalletItems::CreateWalletItems(const base::DictionaryValue& dictionary) { 259 WalletItems::CreateWalletItems(const base::DictionaryValue& dictionary) {
259 std::string google_transaction_id; 260 std::string google_transaction_id;
260 if (!dictionary.GetString("google_transaction_id", &google_transaction_id)) { 261 if (!dictionary.GetString("google_transaction_id", &google_transaction_id)) {
261 DLOG(ERROR) << "Response from Google wallet missing google transaction id"; 262 DLOG(ERROR) << "Response from Google wallet missing google transaction id";
262 return scoped_ptr<WalletItems>(); 263 return scoped_ptr<WalletItems>();
263 } 264 }
264 265
265 std::vector<std::string> required_action; 266 std::vector<RequiredAction> required_action;
266 const ListValue* required_action_list; 267 const ListValue* required_action_list;
267 if (dictionary.GetList("required_action", &required_action_list)) { 268 if (dictionary.GetList("required_action", &required_action_list)) {
268 for (size_t i = 0; i < required_action_list->GetSize(); ++i) { 269 for (size_t i = 0; i < required_action_list->GetSize(); ++i) {
269 std::string action; 270 std::string action_string;
270 if (required_action_list->GetString(i, &action)) 271 if (required_action_list->GetString(i, &action_string)) {
271 required_action.push_back(action); 272 RequiredAction action = ParseFromString(action_string);
273 if (AppliesToWalletItems(action))
274 required_action.push_back(action);
275 }
272 } 276 }
273 } else { 277 } else {
274 DVLOG(1) << "Response from Google wallet missing required actions"; 278 DVLOG(1) << "Response from Google wallet missing required actions";
275 } 279 }
276 280
277 std::string default_instrument_id; 281 std::string default_instrument_id;
278 if (!dictionary.GetString("default_instrument_id", &default_instrument_id)) 282 if (!dictionary.GetString("default_instrument_id", &default_instrument_id))
279 DVLOG(1) << "Response from Google wallet missing default instrument id"; 283 DVLOG(1) << "Response from Google wallet missing default instrument id";
280 284
281 std::string default_address_id; 285 std::string default_address_id;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 346 }
343 347
344 return wallet_items.Pass(); 348 return wallet_items.Pass();
345 } 349 }
346 350
347 bool WalletItems::operator==(const WalletItems& other) const { 351 bool WalletItems::operator==(const WalletItems& other) const {
348 // TODO(ahutter): Check scoped vector equality. 352 // TODO(ahutter): Check scoped vector equality.
349 return google_transaction_id_ == other.google_transaction_id_ && 353 return google_transaction_id_ == other.google_transaction_id_ &&
350 default_instrument_id_ == other.default_instrument_id_ && 354 default_instrument_id_ == other.default_instrument_id_ &&
351 default_address_id_ == other.default_address_id_ && 355 default_address_id_ == other.default_address_id_ &&
352 required_actions_ == required_actions_; 356 required_actions_ == other.required_actions_;
Dan Beam 2013/01/05 03:53:47 I definitely said "whoopsies" out loud when I saw
Ilya Sherman 2013/01/05 23:30:49 Lol, oh my.
Dan Beam 2013/01/07 06:21:27 I suppose I can add a test for this before landing
Dan Beam 2013/01/07 15:44:53 Done.
353 } 357 }
354 358
355 bool WalletItems::operator!=(const WalletItems& other) const { 359 bool WalletItems::operator!=(const WalletItems& other) const {
356 return !(*this == other); 360 return !(*this == other);
357 } 361 }
358 362
359 } // namespace wallet 363 } // namespace wallet
360 364
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698