OLD | NEW |
---|---|
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 Loading... | |
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)) { |
272 RequiredAction action = ParseRequiredActionFromString(action_string); | |
273 if (!ActionAppliesToWalletItems(action)) { | |
274 DLOG(ERROR) << "Response from Google wallet with bad required action"; | |
ahutter
2013/01/07 18:36:13
ditto.
Dan Beam
2013/01/07 18:52:02
Done.
| |
275 return scoped_ptr<WalletItems>(); | |
276 } | |
271 required_action.push_back(action); | 277 required_action.push_back(action); |
278 } | |
272 } | 279 } |
273 } else { | 280 } else { |
274 DVLOG(1) << "Response from Google wallet missing required actions"; | 281 DVLOG(1) << "Response from Google wallet missing required actions"; |
275 } | 282 } |
276 | 283 |
277 std::string default_instrument_id; | 284 std::string default_instrument_id; |
278 if (!dictionary.GetString("default_instrument_id", &default_instrument_id)) | 285 if (!dictionary.GetString("default_instrument_id", &default_instrument_id)) |
279 DVLOG(1) << "Response from Google wallet missing default instrument id"; | 286 DVLOG(1) << "Response from Google wallet missing default instrument id"; |
280 | 287 |
281 std::string default_address_id; | 288 std::string default_address_id; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 } | 349 } |
343 | 350 |
344 return wallet_items.Pass(); | 351 return wallet_items.Pass(); |
345 } | 352 } |
346 | 353 |
347 bool WalletItems::operator==(const WalletItems& other) const { | 354 bool WalletItems::operator==(const WalletItems& other) const { |
348 // TODO(ahutter): Check scoped vector equality. | 355 // TODO(ahutter): Check scoped vector equality. |
349 return google_transaction_id_ == other.google_transaction_id_ && | 356 return google_transaction_id_ == other.google_transaction_id_ && |
350 default_instrument_id_ == other.default_instrument_id_ && | 357 default_instrument_id_ == other.default_instrument_id_ && |
351 default_address_id_ == other.default_address_id_ && | 358 default_address_id_ == other.default_address_id_ && |
352 required_actions_ == required_actions_; | 359 required_actions_ == other.required_actions_; |
353 } | 360 } |
354 | 361 |
355 bool WalletItems::operator!=(const WalletItems& other) const { | 362 bool WalletItems::operator!=(const WalletItems& other) const { |
356 return !(*this == other); | 363 return !(*this == other); |
357 } | 364 } |
358 | 365 |
359 } // namespace wallet | 366 } // namespace wallet |
360 | 367 |
OLD | NEW |