summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornoamsml@google.com <noamsml@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 05:30:18 +0000
committernoamsml@google.com <noamsml@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-21 05:30:18 +0000
commitdd7eb7777ead61d494f9ceeb6a1a95a04d74eff8 (patch)
treecf72e8b79fdcb36bb6ae50f1aba94e5c3ee4ecb9
parent9c0f72cf015d527e6ff9044bad2465abd1712a7b (diff)
downloadchromium_src-dd7eb7777ead61d494f9ceeb6a1a95a04d74eff8.zip
chromium_src-dd7eb7777ead61d494f9ceeb6a1a95a04d74eff8.tar.gz
chromium_src-dd7eb7777ead61d494f9ceeb6a1a95a04d74eff8.tar.bz2
Fixed leak of TestRequestContextGetter in CloudPrintURLFetcherNoServiceProcess (part of the test).
Fixed leak of DictionaryValue in CloudPrintURLFetcher. BUG=177206 Review URL: https://chromiumcodereview.appspot.com/12316012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183745 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/cloud_print/cloud_print_helpers.cc24
-rw-r--r--chrome/common/cloud_print/cloud_print_helpers.h10
-rw-r--r--chrome/service/cloud_print/cloud_print_url_fetcher.cc12
-rw-r--r--chrome/service/cloud_print/printer_job_handler_unittest.cc9
-rw-r--r--tools/heapcheck/suppressions.txt13
-rw-r--r--tools/valgrind/memcheck/suppressions.txt14
6 files changed, 31 insertions, 51 deletions
diff --git a/chrome/common/cloud_print/cloud_print_helpers.cc b/chrome/common/cloud_print/cloud_print_helpers.cc
index 7a25c08..84e4320 100644
--- a/chrome/common/cloud_print/cloud_print_helpers.cc
+++ b/chrome/common/cloud_print/cloud_print_helpers.cc
@@ -170,24 +170,22 @@ GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
return cloud_print_server_url.ReplaceComponents(replacements);
}
-bool ParseResponseJSON(const std::string& response_data,
- bool* succeeded,
- DictionaryValue** response_dict) {
- scoped_ptr<Value> message_value(base::JSONReader::Read(response_data));
+scoped_ptr<base::DictionaryValue> ParseResponseJSON(
+ const std::string& response_data,
+ bool* succeeded) {
+ scoped_ptr<base::Value> message_value(base::JSONReader::Read(response_data));
if (!message_value.get())
- return false;
+ return scoped_ptr<base::DictionaryValue>();
- if (!message_value->IsType(Value::TYPE_DICTIONARY))
- return false;
+ if (!message_value->IsType(base::Value::TYPE_DICTIONARY))
+ return scoped_ptr<base::DictionaryValue>();
- scoped_ptr<DictionaryValue> response_dict_local(
- static_cast<DictionaryValue*>(message_value.release()));
+ scoped_ptr<base::DictionaryValue> response_dict(
+ static_cast<base::DictionaryValue*>(message_value.release()));
if (succeeded &&
- !response_dict_local->GetBoolean(kSuccessValue, succeeded))
+ !response_dict->GetBoolean(kSuccessValue, succeeded))
*succeeded = false;
- if (response_dict)
- *response_dict = response_dict_local.release();
- return true;
+ return response_dict.Pass();
}
void AddMultipartValueForUpload(const std::string& value_name,
diff --git a/chrome/common/cloud_print/cloud_print_helpers.h b/chrome/common/cloud_print/cloud_print_helpers.h
index abbf092..71bd9b6 100644
--- a/chrome/common/cloud_print/cloud_print_helpers.h
+++ b/chrome/common/cloud_print/cloud_print_helpers.h
@@ -9,6 +9,8 @@
#include <string>
#include <vector>
+#include "base/memory/scoped_ptr.h"
+
class GURL;
namespace base {
@@ -54,12 +56,12 @@ GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
const std::string& proxy_id);
// Parses the response data for any cloud print server request. The method
-// returns false if there was an error in parsing the JSON. The succeeded
+// returns null if there was an error in parsing the JSON. The succeeded
// value returns the value of the "success" value in the response JSON.
// Returns the response as a dictionary value.
-bool ParseResponseJSON(const std::string& response_data,
- bool* succeeded,
- base::DictionaryValue** response_dict);
+scoped_ptr<base::DictionaryValue> ParseResponseJSON(
+ const std::string& response_data,
+ bool* succeeded);
// Prepares one value as part of a multi-part upload request.
void AddMultipartValueForUpload(const std::string& value_name,
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.cc b/chrome/service/cloud_print/cloud_print_url_fetcher.cc
index d4fba3a..4b5208e 100644
--- a/chrome/service/cloud_print/cloud_print_url_fetcher.cc
+++ b/chrome/service/cloud_print/cloud_print_url_fetcher.cc
@@ -144,15 +144,17 @@ void CloudPrintURLFetcher::OnURLFetchComplete(
// response, we will retry (to handle the case where we got redirected
// to a non-cloudprint-server URL eg. for authentication).
bool succeeded = false;
- DictionaryValue* response_dict = NULL;
- ParseResponseJSON(data, &succeeded, &response_dict);
- if (response_dict)
+ scoped_ptr<DictionaryValue> response_dict =
+ ParseResponseJSON(data, &succeeded);
+
+ if (response_dict) {
action = delegate_->HandleJSONData(source,
source->GetURL(),
- response_dict,
+ response_dict.get(),
succeeded);
- else
+ } else {
action = RETRY_REQUEST;
+ }
}
}
// Retry the request if needed.
diff --git a/chrome/service/cloud_print/printer_job_handler_unittest.cc b/chrome/service/cloud_print/printer_job_handler_unittest.cc
index b18f5fd..05595ab 100644
--- a/chrome/service/cloud_print/printer_job_handler_unittest.cc
+++ b/chrome/service/cloud_print/printer_job_handler_unittest.cc
@@ -192,13 +192,18 @@ const char kExamplePrinterDescription[] = "Example Description";
class CloudPrintURLFetcherNoServiceProcess
: public CloudPrintURLFetcher {
+ public:
+ CloudPrintURLFetcherNoServiceProcess() :
+ context_getter_(new net::TestURLRequestContextGetter(
+ base::MessageLoopProxy::current())) {}
protected:
virtual net::URLRequestContextGetter* GetRequestContextGetter() {
- return new net::TestURLRequestContextGetter(
- base::MessageLoopProxy::current());
+ return context_getter_.get();
}
virtual ~CloudPrintURLFetcherNoServiceProcess() {}
+ private:
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
};
diff --git a/tools/heapcheck/suppressions.txt b/tools/heapcheck/suppressions.txt
index 1b24727..f1246be 100644
--- a/tools/heapcheck/suppressions.txt
+++ b/tools/heapcheck/suppressions.txt
@@ -1816,19 +1816,6 @@
fun:GcryptInitializer
}
{
- bug_177206_a
- Heapcheck:Leak
- ...
- fun:cloud_print::CloudPrintURLFetcher::OnURLFetchComplete
-}
-{
- bug_177206_b
- Heapcheck:Leak
- fun:cloud_print::CloudPrintURLFetcherNoServiceProcess::GetRequestContextGetter
- fun:cloud_print::CloudPrintURLFetcher::StartRequestHelper
- fun:cloud_print::CloudPrintURLFetcher::StartGetRequest
-}
-{
bug_177285_a
Heapcheck:Leak
fun:MessageLoop::MessageLoop
diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt
index 8f60d7b..54c87bb 100644
--- a/tools/valgrind/memcheck/suppressions.txt
+++ b/tools/valgrind/memcheck/suppressions.txt
@@ -6660,20 +6660,6 @@
fun:_ZN3net15NSSCertDatabase16DeleteCertAndKeyEPKNS_15X509CertificateE
}
{
- bug_177206_a
- Memcheck:Leak
- ...
- fun:_ZN11cloud_print20CloudPrintURLFetcher18OnURLFetchCompleteEPKN3net10URLFetcherE
-}
-{
- bug_177206_b
- Memcheck:Leak
- fun:_Znw*
- fun:_ZN11cloud_print36CloudPrintURLFetcherNoServiceProcess23GetRequestContextGetterEv
- fun:_ZN11cloud_print20CloudPrintURLFetcher18StartRequestHelperERK4GURLN3net10URLFetcher11RequestTypeEPNS0_8DelegateEiRKSsSA_SA_
- fun:_ZN11cloud_print20CloudPrintURLFetcher15StartGetRequestERK4GURLPNS0_8DelegateEiRKSs
-}
-{
bug_177213
Memcheck:Leak
...