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

Side by Side Diff: chrome/browser/chrome_to_mobile_service.cc

Issue 10970054: Check ChromeToMobileService OriginalURLs before handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check submit URL before handling as such, etc. Created 8 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 void ChromeToMobileService::Shutdown() { 330 void ChromeToMobileService::Shutdown() {
331 // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183 331 // TODO(msw): Unit tests do not provide profiles; see http://crbug.com/122183
332 // Unregister for cloud print device list invalidation notifications. 332 // Unregister for cloud print device list invalidation notifications.
333 ProfileSyncService* profile_sync_service = 333 ProfileSyncService* profile_sync_service =
334 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 334 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL;
335 if (profile_sync_service) 335 if (profile_sync_service)
336 profile_sync_service->UnregisterInvalidationHandler(this); 336 profile_sync_service->UnregisterInvalidationHandler(this);
337 } 337 }
338 338
339 void ChromeToMobileService::OnURLFetchComplete(const net::URLFetcher* source) { 339 void ChromeToMobileService::OnURLFetchComplete(const net::URLFetcher* source) {
340 if (source->GetURL() == GetSearchURL(cloud_print_url_)) 340 if (source->GetOriginalURL() == GetSearchURL(cloud_print_url_))
341 HandleSearchResponse(source); 341 HandleSearchResponse(source);
342 else if (source->GetOriginalURL() == GetSubmitURL(cloud_print_url_))
343 HandleSubmitResponse(source);
342 else 344 else
343 HandleSubmitResponse(source); 345 NOTREACHED();
344 346
345 // Remove the URLFetcher from the ScopedVector; this deletes the URLFetcher. 347 // Remove the URLFetcher from the ScopedVector; this deletes the URLFetcher.
346 for (ScopedVector<net::URLFetcher>::iterator it = url_fetchers_.begin(); 348 for (ScopedVector<net::URLFetcher>::iterator it = url_fetchers_.begin();
347 it != url_fetchers_.end(); ++it) { 349 it != url_fetchers_.end(); ++it) {
348 if (*it == source) { 350 if (*it == source) {
349 url_fetchers_.erase(it); 351 url_fetchers_.erase(it);
350 break; 352 break;
351 } 353 }
352 } 354 }
353 } 355 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 net::URLFetcher* search_request = net::URLFetcher::Create( 585 net::URLFetcher* search_request = net::URLFetcher::Create(
584 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this); 586 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this);
585 url_fetchers_.push_back(search_request); 587 url_fetchers_.push_back(search_request);
586 InitRequest(search_request); 588 InitRequest(search_request);
587 search_request->Start(); 589 search_request->Start();
588 } 590 }
589 591
590 void ChromeToMobileService::HandleSearchResponse( 592 void ChromeToMobileService::HandleSearchResponse(
591 const net::URLFetcher* source) { 593 const net::URLFetcher* source) {
592 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 594 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
593 DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_)); 595 DCHECK_EQ(source->GetOriginalURL(), GetSearchURL(cloud_print_url_));
594 596
595 ListValue mobiles; 597 ListValue mobiles;
596 std::string data; 598 std::string data;
597 ListValue* list = NULL; 599 ListValue* list = NULL;
598 DictionaryValue* dictionary = NULL; 600 DictionaryValue* dictionary = NULL;
599 source->GetResponseAsString(&data); 601 source->GetResponseAsString(&data);
600 scoped_ptr<Value> json(base::JSONReader::Read(data)); 602 scoped_ptr<Value> json(base::JSONReader::Read(data));
601 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary && 603 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary &&
602 dictionary->GetList(cloud_print::kPrinterListValue, &list)) { 604 dictionary->GetList(cloud_print::kPrinterListValue, &list)) {
603 std::string type, name, id; 605 std::string type, name, id;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // Update the cached mobile device list in profile prefs. 638 // Update the cached mobile device list in profile prefs.
637 profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles); 639 profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles);
638 if (HasMobiles()) 640 if (HasMobiles())
639 LogMetric(DEVICES_AVAILABLE); 641 LogMetric(DEVICES_AVAILABLE);
640 UpdateCommandState(); 642 UpdateCommandState();
641 } 643 }
642 644
643 void ChromeToMobileService::HandleSubmitResponse( 645 void ChromeToMobileService::HandleSubmitResponse(
644 const net::URLFetcher* source) { 646 const net::URLFetcher* source) {
645 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 647 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
648 DCHECK_EQ(source->GetOriginalURL(), GetSubmitURL(cloud_print_url_));
649
646 // Get the success value from the cloud print server response data. 650 // Get the success value from the cloud print server response data.
647 std::string data; 651 std::string data;
648 bool success = false; 652 bool success = false;
649 source->GetResponseAsString(&data); 653 source->GetResponseAsString(&data);
650 DictionaryValue* dictionary = NULL; 654 DictionaryValue* dictionary = NULL;
651 scoped_ptr<Value> json(base::JSONReader::Read(data)); 655 scoped_ptr<Value> json(base::JSONReader::Read(data));
652 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary) { 656 if (json.get() && json->GetAsDictionary(&dictionary) && dictionary) {
653 dictionary->GetBoolean("success", &success); 657 dictionary->GetBoolean("success", &success);
654 int error_code = -1; 658 int error_code = -1;
655 if (dictionary->GetInteger("errorCode", &error_code)) 659 if (dictionary->GetInteger("errorCode", &error_code))
(...skipping 27 matching lines...) Expand all
683 687
684 // Report failure below and ignore the second response. 688 // Report failure below and ignore the second response.
685 request_observer_map_.erase(other); 689 request_observer_map_.erase(other);
686 break; 690 break;
687 } 691 }
688 } 692 }
689 693
690 if (observer.get()) 694 if (observer.get())
691 observer->OnSendComplete(success); 695 observer->OnSendComplete(success);
692 } 696 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698