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

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

Issue 10914136: Fix URLFetcher leaks in ChromeToMobileService (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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 data.mobile_os = (mobile_os.compare(kTypeAndroid) == 0) ? ANDROID : IOS; 245 data.mobile_os = (mobile_os.compare(kTypeAndroid) == 0) ? ANDROID : IOS;
246 if (!mobile->GetString("id", &data.mobile_id)) 246 if (!mobile->GetString("id", &data.mobile_id))
247 NOTREACHED(); 247 NOTREACHED();
248 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); 248 content::WebContents* web_contents = chrome::GetActiveWebContents(browser);
249 data.url = web_contents->GetURL(); 249 data.url = web_contents->GetURL();
250 data.title = web_contents->GetTitle(); 250 data.title = web_contents->GetTitle();
251 data.snapshot = snapshot; 251 data.snapshot = snapshot;
252 data.snapshot_id = base::GenerateGUID(); 252 data.snapshot_id = base::GenerateGUID();
253 data.type = !snapshot.empty() ? DELAYED_SNAPSHOT : URL; 253 data.type = !snapshot.empty() ? DELAYED_SNAPSHOT : URL;
254 254
255 net::URLFetcher* submit_url = CreateRequest(); 255 submit_url_.reset(CreateRequest());
msw 2012/09/07 02:01:30 This won't work, as there may be multiple simultan
256 request_observer_map_[submit_url] = observer; 256 request_observer_map_[submit_url_.get()] = observer;
257 SendRequest(submit_url, data); 257 SendRequest(submit_url_.get(), data);
258 258
259 if (data.type == DELAYED_SNAPSHOT) { 259 if (data.type == DELAYED_SNAPSHOT) {
260 LogMetric(SENDING_SNAPSHOT); 260 LogMetric(SENDING_SNAPSHOT);
261 261
262 data.type = SNAPSHOT; 262 data.type = SNAPSHOT;
263 net::URLFetcher* submit_snapshot = CreateRequest(); 263 submit_snapshot_.reset(CreateRequest());
264 request_observer_map_[submit_snapshot] = observer; 264 request_observer_map_[submit_snapshot_.get()] = observer;
265 if (!content::BrowserThread::PostBlockingPoolSequencedTask( 265 if (!content::BrowserThread::PostBlockingPoolSequencedTask(
266 data.snapshot.AsUTF8Unsafe(), FROM_HERE, 266 data.snapshot.AsUTF8Unsafe(), FROM_HERE,
267 base::Bind(&ChromeToMobileService::SendRequest, 267 base::Bind(&ChromeToMobileService::SendRequest,
268 weak_ptr_factory_.GetWeakPtr(), 268 weak_ptr_factory_.GetWeakPtr(),
269 submit_snapshot, data))) { 269 submit_snapshot_.get(), data))) {
270 NOTREACHED(); 270 NOTREACHED();
271 } 271 }
272 } 272 }
273 } 273 }
274 274
275 void ChromeToMobileService::DeleteSnapshot(const FilePath& snapshot) { 275 void ChromeToMobileService::DeleteSnapshot(const FilePath& snapshot) {
276 DCHECK(snapshot.empty() || snapshots_.find(snapshot) != snapshots_.end()); 276 DCHECK(snapshot.empty() || snapshots_.find(snapshot) != snapshots_.end());
277 if (snapshots_.find(snapshot) != snapshots_.end()) { 277 if (snapshots_.find(snapshot) != snapshots_.end()) {
278 if (!snapshot.empty()) { 278 if (!snapshot.empty()) {
279 if (!content::BrowserThread::PostBlockingPoolSequencedTask( 279 if (!content::BrowserThread::PostBlockingPoolSequencedTask(
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 if (access_token_.empty()) { 504 if (access_token_.empty()) {
505 // Enqueue this task to perform after obtaining an access token. 505 // Enqueue this task to perform after obtaining an access token.
506 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch, 506 task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch,
507 weak_ptr_factory_.GetWeakPtr())); 507 weak_ptr_factory_.GetWeakPtr()));
508 RequestAccessToken(); 508 RequestAccessToken();
509 return; 509 return;
510 } 510 }
511 511
512 LogMetric(DEVICES_REQUESTED); 512 LogMetric(DEVICES_REQUESTED);
513 513
514 net::URLFetcher* search_request = net::URLFetcher::Create( 514 search_request_.reset(net::URLFetcher::Create(
msw 2012/09/07 02:01:30 Similarly, this won't work for multiple simultaneo
515 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this); 515 GetSearchURL(cloud_print_url_), net::URLFetcher::GET, this));
516 InitRequest(search_request); 516 InitRequest(search_request_.get());
517 search_request->Start(); 517 search_request_->Start();
518 } 518 }
519 519
520 void ChromeToMobileService::HandleSearchResponse( 520 void ChromeToMobileService::HandleSearchResponse(
521 const net::URLFetcher* source) { 521 const net::URLFetcher* source) {
522 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 522 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
523 DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_)); 523 DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_));
524 524
525 std::string data; 525 std::string data;
526 ListValue* list = NULL; 526 ListValue* list = NULL;
527 DictionaryValue* dictionary = NULL; 527 DictionaryValue* dictionary = NULL;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 592
593 // Report failure below and ignore the second response. 593 // Report failure below and ignore the second response.
594 request_observer_map_.erase(other); 594 request_observer_map_.erase(other);
595 break; 595 break;
596 } 596 }
597 } 597 }
598 598
599 if (observer.get()) 599 if (observer.get())
600 observer->OnSendComplete(success); 600 observer->OnSendComplete(success);
601 } 601 }
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