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

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

Issue 10914147: Manage ChromeToMobile URLFetcher lifetimes with a ScopedVector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « chrome/browser/chrome_to_mobile_service.h ('k') | 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 305 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL;
306 if (profile_sync_service) 306 if (profile_sync_service)
307 profile_sync_service->UnregisterInvalidationHandler(this); 307 profile_sync_service->UnregisterInvalidationHandler(this);
308 } 308 }
309 309
310 void ChromeToMobileService::OnURLFetchComplete(const net::URLFetcher* source) { 310 void ChromeToMobileService::OnURLFetchComplete(const net::URLFetcher* source) {
311 if (source->GetURL() == GetSearchURL(cloud_print_url_)) 311 if (source->GetURL() == GetSearchURL(cloud_print_url_))
312 HandleSearchResponse(source); 312 HandleSearchResponse(source);
313 else 313 else
314 HandleSubmitResponse(source); 314 HandleSubmitResponse(source);
315
316 // Remove the URLFetcher from the ScopedVector; this deletes the URLFetcher.
317 for (ScopedVector<net::URLFetcher>::iterator it = url_fetchers_.begin();
318 it != url_fetchers_.end(); ++it) {
319 if (*it == source) {
320 url_fetchers_.erase(it);
321 break;
322 }
323 }
315 } 324 }
316 325
317 void ChromeToMobileService::Observe( 326 void ChromeToMobileService::Observe(
318 int type, 327 int type,
319 const content::NotificationSource& source, 328 const content::NotificationSource& source,
320 const content::NotificationDetails& details) { 329 const content::NotificationDetails& details) {
321 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_AVAILABLE); 330 DCHECK_EQ(type, chrome::NOTIFICATION_TOKEN_AVAILABLE);
322 TokenService::TokenAvailableDetails* token_details = 331 TokenService::TokenAvailableDetails* token_details =
323 content::Details<TokenService::TokenAvailableDetails>(details).ptr(); 332 content::Details<TokenService::TokenAvailableDetails>(details).ptr();
324 // Invalidate the cloud print access token on Gaia login token updates. 333 // Invalidate the cloud print access token on Gaia login token updates.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } else if (observer.get()) { 424 } else if (observer.get()) {
416 // Signal snapshot generation failure. 425 // Signal snapshot generation failure.
417 observer->SnapshotGenerated(FilePath(), 0); 426 observer->SnapshotGenerated(FilePath(), 0);
418 } 427 }
419 } 428 }
420 429
421 net::URLFetcher* ChromeToMobileService::CreateRequest() { 430 net::URLFetcher* ChromeToMobileService::CreateRequest() {
422 net::URLFetcher* request = net::URLFetcher::Create( 431 net::URLFetcher* request = net::URLFetcher::Create(
423 cloud_print::GetUrlForSubmit(cloud_print_url_), 432 cloud_print::GetUrlForSubmit(cloud_print_url_),
424 net::URLFetcher::POST, this); 433 net::URLFetcher::POST, this);
434 url_fetchers_.push_back(request);
425 InitRequest(request); 435 InitRequest(request);
426 return request; 436 return request;
427 } 437 }
428 438
429 void ChromeToMobileService::InitRequest(net::URLFetcher* request) { 439 void ChromeToMobileService::InitRequest(net::URLFetcher* request) {
430 request->SetRequestContext(profile_->GetRequestContext()); 440 request->SetRequestContext(profile_->GetRequestContext());
431 request->SetMaxRetries(kMaxRetries); 441 request->SetMaxRetries(kMaxRetries);
432 DCHECK(!access_token_.empty()); 442 DCHECK(!access_token_.empty());
433 request->SetExtraRequestHeaders("Authorization: OAuth " + 443 request->SetExtraRequestHeaders("Authorization: OAuth " +
434 access_token_ + "\r\n" + cloud_print::kChromeCloudPrintProxyHeader); 444 access_token_ + "\r\n" + cloud_print::kChromeCloudPrintProxyHeader);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch, 516 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch,
507 weak_ptr_factory_.GetWeakPtr())); 517 weak_ptr_factory_.GetWeakPtr()));
508 RequestAccessToken(); 518 RequestAccessToken();
509 return; 519 return;
510 } 520 }
511 521
512 LogMetric(DEVICES_REQUESTED); 522 LogMetric(DEVICES_REQUESTED);
513 523
514 net::URLFetcher* search_request = net::URLFetcher::Create( 524 net::URLFetcher* search_request = net::URLFetcher::Create(
515 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this); 525 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this);
526 url_fetchers_.push_back(search_request);
516 InitRequest(search_request); 527 InitRequest(search_request);
517 search_request->Start(); 528 search_request->Start();
518 } 529 }
519 530
520 void ChromeToMobileService::HandleSearchResponse( 531 void ChromeToMobileService::HandleSearchResponse(
521 const net::URLFetcher* source) { 532 const net::URLFetcher* source) {
522 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 533 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
523 DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_)); 534 DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_));
524 535
525 std::string data; 536 std::string data;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 603
593 // Report failure below and ignore the second response. 604 // Report failure below and ignore the second response.
594 request_observer_map_.erase(other); 605 request_observer_map_.erase(other);
595 break; 606 break;
596 } 607 }
597 } 608 }
598 609
599 if (observer.get()) 610 if (observer.get())
600 observer->OnSendComplete(success); 611 observer->OnSendComplete(success);
601 } 612 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_to_mobile_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698