Browse Source

HttpRequest: Use raw non-owning pointer for cookieStorage_

Tatsuhiro Tsujikawa 12 years ago
parent
commit
a4cf50914d
6 changed files with 24 additions and 20 deletions
  1. 5 0
      src/DownloadEngine.cc
  2. 2 5
      src/DownloadEngine.h
  3. 7 2
      src/HttpRequest.cc
  4. 3 6
      src/HttpRequest.h
  5. 3 3
      test/HttpRequestTest.cc
  6. 4 4
      test/HttpResponseTest.cc

+ 5 - 0
src/DownloadEngine.cc

@@ -554,6 +554,11 @@ AuthConfigFactory* DownloadEngine::getAuthConfigFactory() const
   return authConfigFactory_.get();
 }
 
+CookieStorage* DownloadEngine::getCookieStorage() const
+{
+  return cookieStorage_.get();
+}
+
 void DownloadEngine::setRefreshInterval(int64_t interval)
 {
   refreshInterval_ = std::min(static_cast<int64_t>(999), interval);

+ 2 - 5
src/DownloadEngine.h

@@ -133,7 +133,7 @@ private:
 
   std::deque<std::unique_ptr<Command>> routineCommands_;
 
-  std::shared_ptr<CookieStorage> cookieStorage_;
+  std::unique_ptr<CookieStorage> cookieStorage_;
 
 #ifdef ENABLE_BITTORRENT
   std::shared_ptr<BtRegistry> btRegistry_;
@@ -302,10 +302,7 @@ public:
    uint16_t port,
    const std::string& username);
 
-  const std::shared_ptr<CookieStorage>& getCookieStorage() const
-  {
-    return cookieStorage_;
-  }
+  CookieStorage* getCookieStorage() const;
 
 #ifdef ENABLE_BITTORRENT
   const std::shared_ptr<BtRegistry>& getBtRegistry() const

+ 7 - 2
src/HttpRequest.cc

@@ -61,6 +61,7 @@ HttpRequest::HttpRequest()
   : contentEncodingEnabled_(true),
     userAgent_(USER_AGENT),
     acceptMetalink_(false),
+    cookieStorage_(0),
     authConfigFactory_(0),
     option_(0),
     noCache_(true),
@@ -329,12 +330,16 @@ void HttpRequest::clearHeader()
   headers_.clear();
 }
 
-void HttpRequest::setCookieStorage
-(const std::shared_ptr<CookieStorage>& cookieStorage)
+void HttpRequest::setCookieStorage(CookieStorage* cookieStorage)
 {
   cookieStorage_ = cookieStorage;
 }
 
+CookieStorage* HttpRequest::getCookieStorage() const
+{
+  return cookieStorage_;
+}
+
 void HttpRequest::setAuthConfigFactory(AuthConfigFactory* factory)
 {
   authConfigFactory_ = factory;

+ 3 - 6
src/HttpRequest.h

@@ -74,7 +74,7 @@ private:
   // If true, metalink content types are sent in Accept header field.
   bool acceptMetalink_;
 
-  std::shared_ptr<CookieStorage> cookieStorage_;
+  CookieStorage* cookieStorage_;
 
   AuthConfigFactory* authConfigFactory_;
 
@@ -185,12 +185,9 @@ public:
     acceptMetalink_ = f;
   }
 
-  void setCookieStorage(const std::shared_ptr<CookieStorage>& cookieStorage);
+  void setCookieStorage(CookieStorage* cookieStorage);
 
-  const std::shared_ptr<CookieStorage>& getCookieStorage() const
-  {
-    return cookieStorage_;
-  }
+  CookieStorage* getCookieStorage() const;
 
   void setAuthConfigFactory(AuthConfigFactory* factory);
   void setOption(const Option* option);

+ 3 - 3
test/HttpRequestTest.cc

@@ -385,9 +385,9 @@ void HttpRequestTest::testCreateRequest_with_cookie()
     createCookie("name4", "value4", "aria2.org", false, "/archives/", true),
     createCookie("name5", "value5", "example.org", false, "/", false)
   };
-  auto st = std::make_shared<CookieStorage>();
+  CookieStorage st;
   for(auto c : cookies) {
-    CPPUNIT_ASSERT(st->store(c, 0));
+    CPPUNIT_ASSERT(st.store(c, 0));
   }
 
   HttpRequest httpRequest;
@@ -396,7 +396,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
   httpRequest.setRequest(request);
   httpRequest.setSegment(segment);
   httpRequest.setFileEntry(fileEntry);
-  httpRequest.setCookieStorage(st);
+  httpRequest.setCookieStorage(&st);
   httpRequest.setAuthConfigFactory(authConfigFactory_.get());
   httpRequest.setOption(option_.get());
 

+ 4 - 4
test/HttpResponseTest.cc

@@ -514,8 +514,8 @@ void HttpResponseTest::testRetrieveCookie()
   std::shared_ptr<Request> request(new Request());
   request->setUri("http://www.aria2.org/archives/aria2-1.0.0.tar.bz2");
   httpRequest->setRequest(request);
-  std::shared_ptr<CookieStorage> st(new CookieStorage());
-  httpRequest->setCookieStorage(st);
+  CookieStorage  st;
+  httpRequest->setCookieStorage(&st);
   httpResponse.setHttpRequest(httpRequest);
 
   httpHeader->put(HttpHeader::SET_COOKIE,
@@ -528,10 +528,10 @@ void HttpResponseTest::testRetrieveCookie()
 
   httpResponse.retrieveCookie();
 
-  CPPUNIT_ASSERT_EQUAL((size_t)2, st->size());
+  CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
 
   std::vector<Cookie> cookies;
-  st->dumpCookie(std::back_inserter(cookies));
+  st.dumpCookie(std::back_inserter(cookies));
   CPPUNIT_ASSERT_EQUAL(std::string("k2=v2"), cookies[0].toString());
   CPPUNIT_ASSERT_EQUAL(std::string("k3=v3"), cookies[1].toString());
 }