| 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/chrome_to_mobile_service.h" | 5 #include "chrome/browser/chrome_to_mobile_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 399 |
| 400 void ChromeToMobileService::HandleAccountInfoResponse() { | 400 void ChromeToMobileService::HandleAccountInfoResponse() { |
| 401 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 401 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 402 | 402 |
| 403 std::string data; | 403 std::string data; |
| 404 account_info_request_->GetResponseAsString(&data); | 404 account_info_request_->GetResponseAsString(&data); |
| 405 account_info_request_.reset(); | 405 account_info_request_.reset(); |
| 406 | 406 |
| 407 ListValue* services = NULL; | 407 ListValue* services = NULL; |
| 408 DictionaryValue* dictionary = NULL; | 408 DictionaryValue* dictionary = NULL; |
| 409 scoped_ptr<Value> json(base::JSONReader::Read(data, false)); | 409 scoped_ptr<Value> json(base::JSONReader::Read(data)); |
| 410 StringValue cloud_print_service(kCloudPrintSerivceValue); | 410 StringValue cloud_print_service(kCloudPrintSerivceValue); |
| 411 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary && | 411 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary && |
| 412 dictionary->GetList(kAccountServicesKey, &services) && services && | 412 dictionary->GetList(kAccountServicesKey, &services) && services && |
| 413 services->Find(cloud_print_service) != services->end()) { | 413 services->Find(cloud_print_service) != services->end()) { |
| 414 cloud_print_accessible_ = true; | 414 cloud_print_accessible_ = true; |
| 415 RequestMobileListUpdate(); | 415 RequestMobileListUpdate(); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 void ChromeToMobileService::HandleSearchResponse() { | 419 void ChromeToMobileService::HandleSearchResponse() { |
| 420 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 420 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 421 | 421 |
| 422 std::string data; | 422 std::string data; |
| 423 search_request_->GetResponseAsString(&data); | 423 search_request_->GetResponseAsString(&data); |
| 424 search_request_.reset(); | 424 search_request_.reset(); |
| 425 | 425 |
| 426 ListValue* list = NULL; | 426 ListValue* list = NULL; |
| 427 DictionaryValue* dictionary = NULL; | 427 DictionaryValue* dictionary = NULL; |
| 428 scoped_ptr<Value> json(base::JSONReader::Read(data, false)); | 428 scoped_ptr<Value> json(base::JSONReader::Read(data)); |
| 429 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary && | 429 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary && |
| 430 dictionary->GetList(cloud_print::kPrinterListValue, &list)) { | 430 dictionary->GetList(cloud_print::kPrinterListValue, &list)) { |
| 431 ScopedVector<base::DictionaryValue> mobiles; | 431 ScopedVector<base::DictionaryValue> mobiles; |
| 432 for (size_t index = 0; index < list->GetSize(); index++) { | 432 for (size_t index = 0; index < list->GetSize(); index++) { |
| 433 DictionaryValue* mobile_data = NULL; | 433 DictionaryValue* mobile_data = NULL; |
| 434 if (list->GetDictionary(index, &mobile_data)) { | 434 if (list->GetDictionary(index, &mobile_data)) { |
| 435 std::string mobile_type; | 435 std::string mobile_type; |
| 436 mobile_data->GetString("type", &mobile_type); | 436 mobile_data->GetString("type", &mobile_type); |
| 437 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) | 437 if (mobile_type.compare(kTypeAndroidChromeSnapshot) == 0) |
| 438 mobiles.push_back(mobile_data->DeepCopy()); | 438 mobiles.push_back(mobile_data->DeepCopy()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 456 base::WeakPtr<Observer> observer = i->second; | 456 base::WeakPtr<Observer> observer = i->second; |
| 457 request_observer_map_.erase(i); | 457 request_observer_map_.erase(i); |
| 458 if (!observer.get()) | 458 if (!observer.get()) |
| 459 return; | 459 return; |
| 460 | 460 |
| 461 // Get the success value from the CloudPrint server response data. | 461 // Get the success value from the CloudPrint server response data. |
| 462 std::string data; | 462 std::string data; |
| 463 source->GetResponseAsString(&data); | 463 source->GetResponseAsString(&data); |
| 464 bool success = false; | 464 bool success = false; |
| 465 DictionaryValue* dictionary = NULL; | 465 DictionaryValue* dictionary = NULL; |
| 466 scoped_ptr<Value> json(base::JSONReader::Read(data, false)); | 466 scoped_ptr<Value> json(base::JSONReader::Read(data)); |
| 467 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary) | 467 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary) |
| 468 dictionary->GetBoolean("success", &success); | 468 dictionary->GetBoolean("success", &success); |
| 469 | 469 |
| 470 // Check if the observer is waiting on a second response (url and snapshot). | 470 // Check if the observer is waiting on a second response (url and snapshot). |
| 471 RequestObserverMap::iterator other = request_observer_map_.begin(); | 471 RequestObserverMap::iterator other = request_observer_map_.begin(); |
| 472 for (; other != request_observer_map_.end(); ++other) { | 472 for (; other != request_observer_map_.end(); ++other) { |
| 473 if (other->second == observer) { | 473 if (other->second == observer) { |
| 474 // Do not call OnSendComplete for observers waiting on a second response. | 474 // Do not call OnSendComplete for observers waiting on a second response. |
| 475 if (success) | 475 if (success) |
| 476 return; | 476 return; |
| 477 | 477 |
| 478 // Ensure a second response is not sent after reporting failure below. | 478 // Ensure a second response is not sent after reporting failure below. |
| 479 request_observer_map_.erase(other); | 479 request_observer_map_.erase(other); |
| 480 break; | 480 break; |
| 481 } | 481 } |
| 482 } | 482 } |
| 483 | 483 |
| 484 observer->OnSendComplete(success); | 484 observer->OnSendComplete(success); |
| 485 } | 485 } |
| OLD | NEW |