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

Side by Side Diff: webkit/glue/resource_fetcher.cc

Issue 149295: Don't forget to free the callbacks! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 | « webkit/glue/resource_fetcher.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "webkit/glue/resource_fetcher.h" 5 #include "webkit/glue/resource_fetcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "webkit/api/public/WebKit.h" 8 #include "webkit/api/public/WebKit.h"
9 #include "webkit/api/public/WebKitClient.h" 9 #include "webkit/api/public/WebKitClient.h"
10 #include "webkit/api/public/WebURLError.h" 10 #include "webkit/api/public/WebURLError.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 DCHECK(!completed_); 77 DCHECK(!completed_);
78 DCHECK(data_length > 0); 78 DCHECK(data_length > 0);
79 79
80 data_.append(data, data_length); 80 data_.append(data, data_length);
81 } 81 }
82 82
83 void ResourceFetcher::didFinishLoading(WebURLLoader* loader) { 83 void ResourceFetcher::didFinishLoading(WebURLLoader* loader) {
84 DCHECK(!completed_); 84 DCHECK(!completed_);
85 completed_ = true; 85 completed_ = true;
86 86
87 if (callback_) 87 if (callback_.get()) {
88 callback_->Run(response_, data_); 88 callback_->Run(response_, data_);
89 callback_.reset();
90 }
89 } 91 }
90 92
91 void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) { 93 void ResourceFetcher::didFail(WebURLLoader* loader, const WebURLError& error) {
92 DCHECK(!completed_); 94 DCHECK(!completed_);
93 completed_ = true; 95 completed_ = true;
94 96
95 // Go ahead and tell our delegate that we're done. 97 // Go ahead and tell our delegate that we're done.
96 if (callback_) 98 if (callback_.get()) {
97 callback_->Run(WebURLResponse(), std::string()); 99 callback_->Run(WebURLResponse(), std::string());
100 callback_.reset();
101 }
98 } 102 }
99 103
100 ///////////////////////////////////////////////////////////////////////////// 104 /////////////////////////////////////////////////////////////////////////////
101 // A resource fetcher with a timeout 105 // A resource fetcher with a timeout
102 106
103 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout( 107 ResourceFetcherWithTimeout::ResourceFetcherWithTimeout(
104 const GURL& url, WebFrame* frame, int timeout_secs, Callback* c) 108 const GURL& url, WebFrame* frame, int timeout_secs, Callback* c)
105 : ResourceFetcher(url, frame, c) { 109 : ResourceFetcher(url, frame, c) {
106 timeout_timer_.Start(TimeDelta::FromSeconds(timeout_secs), this, 110 timeout_timer_.Start(TimeDelta::FromSeconds(timeout_secs), this,
107 &ResourceFetcherWithTimeout::TimeoutFired); 111 &ResourceFetcherWithTimeout::TimeoutFired);
108 } 112 }
109 113
110 void ResourceFetcherWithTimeout::TimeoutFired() { 114 void ResourceFetcherWithTimeout::TimeoutFired() {
111 if (!completed_) { 115 if (!completed_) {
112 loader_->cancel(); 116 loader_->cancel();
113 didFail(NULL, WebURLError()); 117 didFail(NULL, WebURLError());
114 } 118 }
115 } 119 }
116 120
117 } // namespace webkit_glue 121 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/resource_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698